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
import SwiftUI | |
import PhotosUI | |
struct CustomPhotoPickerView: UIViewControllerRepresentable { | |
@Binding var selectedImage: UIImage? | |
@Binding var date: Date? | |
@Binding var location: CLLocationCoordinate2D? | |
@Environment(\.presentationMode) var presentationMode |
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
for i in 0...data.count-1 { | |
for a in i...data.count-1 { | |
if(data[i] + data[a] == 2020) { | |
print("Result \(data[i] * data[a])") | |
} | |
} | |
} |
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 validPasswordsCount = passwords | |
.map { password -> DataEntry in | |
let substrings = password.split(separator: " ") | |
let minMaxSub = substrings[0].split(separator: "-") | |
return DataEntry(min: Int(minMaxSub[0])!, max: Int(minMaxSub[1])!, char: substrings[1].first!, password: String(substrings[2])) | |
} | |
.filter(isValid_1) | |
.count | |
print(validPasswordsCount) |
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 treeCount = countTrees(in: lines, dX: 3, dY: 1) | |
print(treeCount) |
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 validPassportsCount = 0 | |
let keys: [String] = [ | |
"ecl", | |
"pid", | |
"eyr", | |
"hcl", | |
"byr", | |
"iyr", | |
"hgt" | |
] |
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 filename = "/Users/felix/xCodeProjects/AdventOfCode2020.playground/Resources/december05.txt" | |
let contents = try! String(contentsOfFile: filename) | |
let lines = contents.components(separatedBy: CharacterSet.newlines) | |
let seats = lines.compactMap { seatString -> Seat? in | |
if seatString.isEmpty { | |
return nil | |
} | |
let rowEndIndex = seatString.index(seatString.startIndex, offsetBy: 7) | |
let binaryRowString = String(seatString[..<rowEndIndex].map { (char) -> Character in |
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 solution = solve(lines, isFirstPuzzle: true) | |
print(solution) |
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 list = listBagsContaining(with: bagMap, withBagName: "shinygold", allBagNames: [String]()) | |
func listBagsContaining(with bags: [String : [Bag]], withBagName bagName: String, allBagNames: [String]) -> [String] { | |
let containingBagNames = bags.filter { | |
key, value in | |
value.map({ $0.name}).contains(bagName) | |
} | |
.compactMap { $0.key } | |
if containingBagNames.count == 0 { | |
return allBagNames + [bagName] |
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(runInstructions(lines: lines)) |
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 preamble = 25 | |
var solution1 = -1 | |
for i in 0..<numbers.count { | |
if !checkThatAnyNumbers(in: Array(numbers[i..<preamble + i]), sumTo: numbers[preamble + i]) { | |
solution1 = numbers[preamble + i] | |
break | |
} | |
} |
OlderNewer