Skip to content

did first two #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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