3 ms·
I solved the first part using the examples. Swift is nice. func calcFuel(_ mass:Int) -> Int {mass / 3 - 2} let z0 = massList.map(calcFuel).reduce(0, +)
by melling 7y ago
I solved the first part using the examples. Swift is nice.
func calcFuel(_ mass:Int) -> Int {mass / 3 - 2}
let z0 = massList.map(calcFuel).reduce(0, +)
or simply ...
let z1 = massList.map({$0 / 3 - 2}).reduce(0, +)
Any idea how to read the data on the iPad?
- chii 7y agoi just copy/pasted the data into the source instead of dealing with IO.
- melling 7y agoI had to create the plain text input file in iCloud with my Mac then insert it (Big +, third option) in the iPad’s Swift Playground. Need a text app that will save to Files for a complete iPad solution. Also, a Swift Playground bug reverted my final solution to the code from my first few minutes, losing my code. That was frustrating... Anyway, a complete Swift Playground on iPad solution: import UIKit let path = Bundle.main.url(forResource: "input01", withExtension: "txt") var text = try String(contentsOf: path!, encoding: .utf8) let massList:[Int] = text.components(separatedBy: .whitespacesAndNewlines).compactMap({Int($0)}) let z1 = massList.map({$0 / 3 - 2}).reduce(0, +) print("\(z1)")
- brantonb 7y agoYou can option+tap a link in Safari to download to Files. Hold down the command key to see available shortcuts.
- ulucs 7y agoI copy my session cookie and send a web request for the inputs. I should write some sort of caching code though..