Skip to content

Instantly share code, notes, and snippets.

View felix-larsen's full-sized avatar
🤔
thinking

Felix Larsen felix-larsen

🤔
thinking
View GitHub Profile
@felix-larsen
felix-larsen / CustomPhotoPickerView.swift
Last active May 16, 2024 06:58
PHPhotoPicker metadata example
import SwiftUI
import PhotosUI
struct CustomPhotoPickerView: UIViewControllerRepresentable {
@Binding var selectedImage: UIImage?
@Binding var date: Date?
@Binding var location: CLLocationCoordinate2D?
@Environment(\.presentationMode) var presentationMode
@felix-larsen
felix-larsen / december01_1.swift
Last active December 1, 2020 20:37
1st December - Advent of Code 2020
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])")
}
}
}
@felix-larsen
felix-larsen / december02_1.swift
Created December 2, 2020 07:27
2nd December solution - Advent of Code 2020
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)
@felix-larsen
felix-larsen / december03_1.swift
Created December 3, 2020 07:40
3rd December solution - Advent of Code 2020 - swift
let treeCount = countTrees(in: lines, dX: 3, dY: 1)
print(treeCount)
@felix-larsen
felix-larsen / december04_1.swift
Created December 4, 2020 06:12
4th December - Advent of Code 2020 - swift
var validPassportsCount = 0
let keys: [String] = [
"ecl",
"pid",
"eyr",
"hcl",
"byr",
"iyr",
"hgt"
]
@felix-larsen
felix-larsen / december05_1.swift
Created December 5, 2020 06:57
5th December solution - Advent of Code - swift
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
@felix-larsen
felix-larsen / december06_1.swift
Created December 6, 2020 09:01
6th December solution - Advent of Code - swift
let solution = solve(lines, isFirstPuzzle: true)
print(solution)
@felix-larsen
felix-larsen / december07_1.swift
Created December 7, 2020 20:20
7th December solution - Advent of Code - swift
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]
@felix-larsen
felix-larsen / december08_1.swift
Created December 8, 2020 05:54
8th December solution - Advent of Code - swift
print(runInstructions(lines: lines))
@felix-larsen
felix-larsen / december09_1.swift
Created December 9, 2020 05:56
9th December solution - Advent of Code - swift
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
}
}