Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
TheMuellenator / variables.swift
Last active March 5, 2024 17:50
iOS repl.it - Variables Challenge Solution
var a = 5
var b = 8
var c = a
a = b
b = c
print("a: \(a)")
print("b: \(b)")
@TheMuellenator
TheMuellenator / arrays.swift
Last active May 7, 2024 14:33
iOS repl.it - Arrays Challenge Solution
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]
]
@TheMuellenator
TheMuellenator / randomisation.swift
Last active May 7, 2024 14:39
iOS repl.it - Randomisation Challenge Solution
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)
@TheMuellenator
TheMuellenator / functions1.swift
Last active March 27, 2024 17:34
iOS repl.it - Functions 1 Challenge Solution
print("Starting map")
start()
//4 steps right and 5 steps down.
right()
right()
right()
right()
@TheMuellenator
TheMuellenator / functions2.swift
Last active April 11, 2024 02:31
iOS repl.it - Functions 2 Challenge Solution
//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)
@TheMuellenator
TheMuellenator / control_flow.swift
Last active February 6, 2024 15:05
iOS repl.it - IF Else Challenge Solution
//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"
@TheMuellenator
TheMuellenator / switch.swift
Last active March 26, 2024 21:17
iOS repl.it - Switch Challenge Solution
////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:
@TheMuellenator
TheMuellenator / dictionaries.swift
Last active October 16, 2023 17:28
iOS repl.it - Dictionaries Challenge Solution
//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"
@TheMuellenator
TheMuellenator / optionals.swift
Last active March 20, 2024 00:00
iOS repl.it - Optionals Challenge Solution
//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"]!
@TheMuellenator
TheMuellenator / functions3.swift
Last active April 16, 2024 04:49
iOS repl.it - Functions 3 Challenge Solution
func isOdd(n: Int) -> Bool {
if n % 2 != 0 {
return true
} else {
return false
}
// Alternatively:
// return n % 2 != 0
}