Live data from Hacker News

Advent of Code 2019

adventofcode.com

71–80 of 124 posts

Re: Advent of Code 2019

#71
post #56
post #27

Earlier quoted context omitted.

Learning 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.

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?

i just copy/pasted the data into the source instead of dealing with IO.

Re: Advent of Code 2019

#72

Earlier quoted context omitted.

It doesn’t need recursion, you can do a while(round(x/3)-2 > 0) type thing, but recursion is simpler.

Nothing 'needs' recursion, it's always equivalent to an iterative solution. In some languages a recursive solution is more natural and may perform better.

I know of languages that can automatically convert some kinds of recursive code into the iterative equivalent automatically, but I've never seen one that can make the recursive version faster than an iterative equivalent.

Re: Advent of Code 2019

#73

These are daily programming puzzles? How long do they take on average? Also, I know somebody who is just starting out at coding. Would it be too hard for them? They are brand new, learning about loops

I completed the whole thing last year; the problems start out very easy, but get dramatically more challenging over the course of the month. Check out the statistics for how many people completed each problem in 2018: https://adventofcode.com/2018/stats The first few problems are approachable by pretty much anyone who understands how to do arithmetic, file I/O and basic flow control. Many of the later problems requir…

> Check out the statistics for how many people completed each problem in 2018

I suspect you'd see a dropoff like this regardless of whether the problems get more difficult or not. Going to the gym doesn't get any harder in February but they see the same effect.

Re: Advent of Code 2019

#75
post #71
post #56

Earlier quoted context omitted.

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?

i just copy/pasted the data into the source instead of dealing with IO.

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)")

Re: Advent of Code 2019

#77
post #14

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 i…

lol 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. :)

Re: Advent of Code 2019

#78

Eric, the author, says he won't accept any puzzle submissions because of attribution and legal issues. This seems like the wrong outcome for people who want to make the site better but don't want credit, compensation, or attribution. Has anyone seen a site using an IP assignment agreement which is the equivalent of "take my work, I don't want credit, and it's just for your site"? The Creative Commons CC0 license come…

Maybe he enjoys/benefits from the work, I feel like coming up with puzzle ideas would be somewhat fun/beneficial. I would definitely assume that if this were not the case he would outsource it or maybe even open source it.

Re: Advent of Code 2019

#79
post #27
post #14

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 i…

Learning 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.

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!

Re: Advent of Code 2019

#80
post #75
post #71

Earlier quoted context omitted.

i just copy/pasted the data into the source instead of dealing with IO.

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 = Bund…

You can option+tap a link in Safari to download to Files. Hold down the command key to see available shortcuts.
Post reply on HN