I started last year using Swift Playgrounds. I was lazy and just pasted the input into a multi-line string. I had to switch away from Playgrounds after a couple of days because it would crash due to memory issues. It traces every line of execution and the intermediate values of all variables. I really enjoyed doing the challenges in Swift, but I did have to switch to using my Mac to do it.
This year, I’m learning Python by using a Raspberry Pi 4 directly connected to my iPad via USB. Should be another fun month!
I 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)")
I couldn't figure it out on a Mac. Then I Googled it, and decided I'm better off solving this in languages I know (whatever I feel like today: JS, Python, Java, perhaps even Erlang) or in a language that has a reasonable standard library (Rust) than in this mess: https://twitter.com/dmitriid/status/1201441652507844608
I’m trying to solve them with Swift Playgrounds on the iPad, for example. And I can’t figure out how to create a simple text file for the data.