Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 139 additions & 1 deletion HWFrom1-24(Recursion).playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,149 @@ Homework link: https://docs.google.com/document/d/1INvOynuggw69yLRNg3y-TPwBiYb3l
*/


//Question 1



import Foundation



/*





Homework link: https://docs.google.com/document/d/1INvOynuggw69yLRNg3y-TPwBiYb3lQZQiFUOxZKBwsY/edit#heading=h.za36ai6n5fth







*/







//Question 1



var count = 0;

var firstNumber = 0

var secondNumber = 1











func fib(n: Int) -> Int {



while count <= n {



let temp = secondNumber

secondNumber = secondNumber + firstNumber

firstNumber = temp



}



var stepNum = 0

func tryStep() -> Int {

let stepCount = Int(arc4random_uniform(3)) - 1

stepNum += stepCount;

switch(stepCount) {

case -1: print("Ouch \(stepNum)")

case 1: print("Yay \(stepNum)")

default: print("Beep \(stepNum)")

}

return stepCount

}







func stepUp() {

if tryStep() == 1 {

// We’re done!

return

}

else if tryStep() == 0 {



stepUp()

}





// Now we’re two steps below where we want to be :-(

stepUp()

stepUp()

}









//Question 2





//Question 3



Expand All @@ -22,4 +160,4 @@ Homework link: https://docs.google.com/document/d/1INvOynuggw69yLRNg3y-TPwBiYb3l



//Question 3
//Question 3