Hi Brian: I think your recursive technique is offset by one index. When you call with numSteps as '5', it should return [0, 1, 1, 2, 3, 5], instead it returns [0, 1, 1, 2, 3, 5, 8] - which is an index, or numStep, of 6.
Lol, I've been studying swift for two months and when I see you doing things like these so fast, and explaining it I just get like hell yeah, he is so good hopefully ur doing good, lets keep up the good work!
Hey man! Great video - I really like your video setup. What are you using to record yourself / your screen at the same time? Are you using anything in particular for editing? Thanks!
+wdw5000 Yes, I just got back from an 8 day Taiwan vacation and getting back into the groove of things. Currently working on producing how to create UA-cam app series but takes time as you can imagine. These algorithm videos are here to satisfy your hunger for now :)
Cannot use mutating member on immutable value: 'fibForNumbers' returns immutable value anyone know why? when I use return fibForNumbers(numberOfSteps: numberOfSteps-1).append(fibNumber(number: numberOfSteps)) .instead when I use return fibForNumbers(numberOfSteps: numberOfSteps-1) + [fibNumber(number: numberOfSteps)] is fine any now knows the difference between append a element to an army and just + one func fibForNumbers (numberOfSteps: Int) -> [Int]{ // if numberOfSteps Int{ if number == 1{ return 0 } else if number == 2{ return 1 } else{ return fibNumber(number: number-1) + fibNumber(number: number - 2) } } fibNumber(number: 5) fibForNumbers(numberOfSteps: 5)
Hey man, I really like your algorithm videos, but read below that you ran out of ideas. So what you think of making videos based on the "swift algorithm club" (github.com/raywenderlich/swift-algorithm-club)? Just a suggestion :)
I don't like the way you did the recursive function, it's not very intuitive. Here's my version: func recursiveFib(for numSteps: Int) -> [Int] { if numSteps < 0 { return [] } if numSteps < 2 { return [Int](0...numSteps) } let previous = recursiveFib(for: numSteps - 1) return previous + [previous[numSteps - 2] + previous[numSteps - 1]] }
I like this because it's all self-contained within the function. The function runs beautifully without the first if-statement so I'm not sure why that was added. Edit: Oh, I see the if-statement is used to handle negatives. :)
Hi Brian,
Great tutorials you showing us. For fibonacci, i've included one boolean parameter indicating for the first step to include [0,1]
func fibRecursiveFor(numSteps: Int, first: Int, second: Int, firstStep: Bool) -> [Int]{
if numSteps == 0 {
return []
}
if firstStep {
return [0,1] + [first + second] + fibRecursiveFor(numSteps: numSteps - 1, first: second, second: first + second, firstStep: false)
}
return [first + second] + fibRecursiveFor(numSteps: numSteps - 1, first: second, second: first + second, firstStep: false)
}
fibRecursiveFor(numSteps: 9, first: 0, second: 1, firstStep: true)
Hi Brian: I think your recursive technique is offset by one index. When you call with numSteps as '5', it should return [0, 1, 1, 2, 3, 5], instead it returns [0, 1, 1, 2, 3, 5, 8] - which is an index, or numStep, of 6.
+Richard Martin good catch, as long as you understand the algorithm you’re good
Good video, it explains alot. Do you think I can use this for the running sum leetcode problem?
I love it how you're secretly smiling while writing the recursive function :D
could you please add more videos relating algorithm..as these are also quite helpful thanks
Hi Simran, I think I ran out of ideas for algorithms so I stopped...
Lets Build That App more algorithms please!
@@LetsBuildThatApp dynamic programming
hey, is the a way to do this with only var and print?
Lol, I've been studying swift for two months and when I see you doing things like these so fast, and explaining it I just get like
hell yeah, he is so good
hopefully ur doing good, lets keep up the good work!
Its prepared lesson bro , no one can think in this fast, dont think like this way and compare yourself with him u will frustrate
Hey man! Great video - I really like your video setup. What are you using to record yourself / your screen at the same time? Are you using anything in particular for editing? Thanks!
Noticed your videos are mostly algorithm based now. Will you be recreating any apps in the near future?
+wdw5000 Yes, I just got back from an 8 day Taiwan vacation and getting back into the groove of things. Currently working on producing how to create UA-cam app series but takes time as you can imagine. These algorithm videos are here to satisfy your hunger for now :)
How was your Taiwan vacation?
Taiwan is really awesome, I enjoyed staying in Taipei, yilan, and hualien. Being able to travel to all these places without a car was real nice.
Please make a video on String algorithms in Swift.. It'll be really great....
Theres wrong with shorter way its give one more noumber , you should make numsteps-2
Cannot use mutating member on immutable value: 'fibForNumbers' returns immutable value
anyone know why?
when I use return fibForNumbers(numberOfSteps: numberOfSteps-1).append(fibNumber(number: numberOfSteps))
.instead when I use return fibForNumbers(numberOfSteps: numberOfSteps-1) + [fibNumber(number: numberOfSteps)] is fine
any now knows the difference between append a element to an army and just + one
func fibForNumbers (numberOfSteps: Int) -> [Int]{
// if numberOfSteps Int{
if number == 1{
return 0
}
else if number == 2{
return 1
}
else{
return fibNumber(number: number-1) + fibNumber(number: number - 2)
}
}
fibNumber(number: 5)
fibForNumbers(numberOfSteps: 5)
thank yo, but there is a simpler solution: func fib(_ n: Int) -> Int {
guard n > 1 else {return n}
return fib(n - 1) + fib(n - 2)
}
simpler, но с n = 100, он будет выполнять эту функцию 50 000 лет
Good stuff!
Very good and helpful 👌
Hey man, I really like your algorithm videos, but read below that you ran out of ideas. So what you think of making videos based on the "swift algorithm club" (github.com/raywenderlich/swift-algorithm-club)? Just a suggestion :)
+Saturnino collaço I'm actually an android author on rays website, I'm not going to encroach on their content :)
Thanks you, very helpful
I don't like the way you did the recursive function, it's not very intuitive. Here's my version:
func recursiveFib(for numSteps: Int) -> [Int] {
if numSteps < 0 {
return []
}
if numSteps < 2 {
return [Int](0...numSteps)
}
let previous = recursiveFib(for: numSteps - 1)
return previous + [previous[numSteps - 2] + previous[numSteps - 1]]
}
Good job. I think there are many different solutions to this problem, good that you found one that suits your coding preference.
I like this because it's all self-contained within the function. The function runs beautifully without the first if-statement so I'm not sure why that was added. Edit: Oh, I see the if-statement is used to handle negatives. :)