This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = 5 | |
var b = 8 | |
var c = a | |
a = b | |
b = c | |
print("a: \(a)") | |
print("b: \(b)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers = [45, 73, 195, 53] | |
//Create a new array called computedNumbers | |
var computedNumbers = [ | |
numbers[0] * numbers[1], | |
numbers[1] * numbers[2], | |
numbers[2] * numbers[3], | |
numbers[3] * numbers[0] | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] | |
//The number of letters in alphabet equals 26 | |
var password = alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] + alphabet[Int.random(in: 0...25)] | |
print(password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Starting map") | |
start() | |
//4 steps right and 5 steps down. | |
right() | |
right() | |
right() | |
right() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Don't change this code: | |
func calculator() { | |
let a = Int(readLine()!)! //First input | |
let b = Int(readLine()!)! //Second input | |
add(n1: a, n2: b) | |
subtract(n1: a, n2: b) | |
multiply(n1: a, n2: b) | |
divide(n1: a, n2: b) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Don't change this | |
var aYear = Int(readLine()!)! | |
func isLeap(year: Int) { | |
var leap = "NO" | |
//IF divisible by 4 with no remainders. | |
if year % 4 == 0 { | |
leap = "YES" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////Don't change this | |
var aNumber = Int(readLine()!)! | |
func dayOfTheWeek(day: Int) { | |
//Write your code inside this function. | |
switch day { | |
case 1: | |
print("Monday") | |
case 2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Don't change this | |
var stockTickers: [String: String] = ["APPL" : "Apple Inc", "HOG": "Harley-Davidson Inc", "BOOM": "Dynamic Materials", "HEINY": "Heineken", "BEN": "Franklin Resources Inc"] | |
//Write your code here. | |
stockTickers["WORK"] = "Slack Technologies Inc" | |
stockTickers["BOOM"] = "DMC Global Inc" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Don't change this | |
var studentsAndScores = ["Amy": Int(readLine()!)!, "James": Int(readLine()!)!, "Helen": Int(readLine()!)!] | |
func highestScore(scores: [String: Int]) { | |
//Write your code here. | |
let a = studentsAndScores["Amy"]! | |
let b = studentsAndScores["James"]! | |
let c = studentsAndScores["Helen"]! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isOdd(n: Int) -> Bool { | |
if n % 2 != 0 { | |
return true | |
} else { | |
return false | |
} | |
// Alternatively: | |
// return n % 2 != 0 | |
} |
OlderNewer