5 ms·
Many of the comments are about the event as a whole, but I'd like to commend the author for the day 1 puzzle, which I think is very cleverly written. Many peopl
by aquova 7y ago
Many of the comments are about the event as a whole, but I'd like to commend the author for the day 1 puzzle, which I think is very cleverly written. Many people (including myself) use these as an opportunity to try out learning a new language, and the first puzzle does a good job of making sure you know enough basic operations for some of the puzzles coming up. The puzzle itself wasn't very difficult, you could do it by hand if you really wanted to, but it required you to know how to read and parse lines in a file, handle compound data structures, iterate through, and perform basic operations (floor, casting strings to ints, etc). I thought it was really well done, and creates the basic knowledge for the puzzles ahead.
- klemenk 7y agoYou can watch authors talk about how he prepares challenges and other challenges he had with AoC :D https://www.youtube.com/watch?v=gibVyxpi-qA&feature=emb_title https://www.youtube.com/watch?v=gibVyxpi-qA&feature=emb_titl...
- melling 7y agoLearning new environments can be painful so it’s good it starts off easy. 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.
- melling 7y agoI 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..
- brantonb 7y agoI 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!
- duckarmada 7y agoI've been creating multiline strings and then just using components(separatedBy:)
- dmitriid 7y agoI 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 https://twitter.com/dmitriid/status/1201441652507844608
- melling 7y agoLast night I gave the complete solution in Swift below. Here are the two lines to read the file: let path = Bundle.main.url(forResource: "input01", withExtension: "txt") var text = try String(contentsOf: path!, encoding: .utf8)
- dmitriid 7y agoThere's no chance in hell anyone learning Swift can figure these two lines out. Besides, there are immediate additional questions: - what's a bundle, and why does a Bundle deal with urls? - What's the difference between Bundle.main.url and FileManager.main.urls, and why one and not the other? - where does the resource come from? - how do I read a file from a path? - Why is String responsible for reading (and writing!) contents of a file? In which world is this good design?
- sammorrowdrums 7y agoI use pastebin raw and get stuff from web requests sometimes rather than local files.
- rb808 7y agolol I actually did this typing into source comma down comma down comma... Only after reading this I realized how lazy I was so went back to do it properly. :)
- znpy 7y ago> Many people (including myself) use these as an opportunity to try out learning a new language I hadn't thought about that! I'll take this as an opportunity to learn Rust!
- jzymbaluk 7y agoI'm doing the same thing this year!
- sammorrowdrums 7y agoThanks to these comments, in spite of already having starting advent coding, I have begun learning basic Rust, have the stack and development environment set up and I'm looking forward to doing the first two days again in Rust...
- sammorrowdrums 7y agoChecking back in - have you done it, is it going OK? I can't do it when the puzzles come out (too late in UK) but I've really enjoyed Rust so far and I got my 10 stars so far. Results are really nice, and match and enums etc. really make the language nice. Rust really has taken many of the best parts of Python, functional paradigms, and lower level languages, and the compiler errors - being warned about missing branches in matches! I'm hoping that finishing 2019 with Rust will lead to more in 2020!
- kitd 7y agoGood idea. I have used http://www.https://cryptopals.com/ http://www.https://cryptopals.com/ for a similar purpose, with the added benefit of learning about cryptography as a parallel outcome.
- maremp 7y agoPoorly formatted link, it should be https://cryptopals.com/ https://cryptopals.com/.
- zeveb 7y ago> The puzzle itself wasn't very difficult, you could do it by hand if you really wanted to, but it required you to know how to read and parse lines in a file, handle compound data structures, iterate through, and perform basic operations (floor, casting strings to ints, etc). I don't believe that it required any compound data structures, just looping through the lines in the file. You're right about the rest, though.
- ahaferburg 7y agoIt's faster to just paste the input into your favorite editor, and massage it gently until it is a literal in the language you're using. No parsing necessary.