Advent of Code 2019(adventofcode.com) |
Advent of Code 2019(adventofcode.com) |
the word advent is religious.
If you are religious, look upon this as a similar thing which reminds you of the season, building in anticipation of the final day.
If you are not religious, it's just a word with no special meaning other than the time of year. Same goes if you are not of a Christian religion.
Otherwise, it's just a normal word which means "the arrival of a notable person, thing, or event".
What an utterly strange proclamation. On every level: the notion that speech should not be free, the notion that users cannot be trusted to figure out what the project is about if it's not "clearly marked" in this way, the notion that there is some harm that can be done by such a "religious project" or a "religious word," whatever that even means.
I hadn't thought about that! I'll take this as an opportunity to learn Rust!
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!
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.
This year, I’m learning Python by using a Raspberry Pi 4 directly connected to my iPad via USB. Should be another fun month!
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 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.
I have used http://www.https://cryptopals.com/ for a similar purpose, with the added benefit of learning about cryptography as a parallel outcome.
Some problems feel like they were designed to be solved in awk, like the assembly style ones. Others, not so much... But it was great fun overall and I learned a lot about awk.
> | awk '{print $<word>}'
The solution to the first exercise looks surprisingly clean. It will be interesting to see how they continue as the challenges get harder. Bookmarked!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 comes closest, but one could scrape those puzzles and create a competing site, which I'd guess Eric wants to avoid.
Personally, I suspect that he wants something that consumes so much of his free time to wholly be his, and I respect that.
After seeing the problem [0], I didn't immediately think to use oeis because the manhatten distance of a spiral is pretty easy to code or do by hand. The second stage has a harder sequence though. It prompted me to check oeis and I easily got the answer [2] within a minute of checking.
Looking back at the first stage, I found a sequence for it [1] and PARI/GP code i could run to answer the question. If I had used oeis immediately I would have a solution to both phases in 2 minutes which would be the fastest on the old leaderboard for the problem [3].
I strongly recommend using AoC as a tool to help learn a new language. Many people, myself included, use it to learn Rust.
The best part about AoC is the community. Everyone is super helpful and kind. The daily Reddit thread has solutions in every language under the sun.
My better half is a designer and is going to participate this year to help learn JavaScript.
Looking forward to the fun, the stress and the eventual euphoria.
For example, here is the Nim communities effort: https://forum.nim-lang.org/t/5588
"I have thought about the particular challenges of this year's Advent of Code (which I greatly enjoyed once again, with some intermittent mixed feelings), and my conclusion is that some problems might very well be of similar difficulty levels, but with nevertheless very dissimilar frustration-inducing levels. And I think the frustration level is strongly correlated with the feedback signal one can use to debug. Case in point: Day 15, which was almost impossible to debug, once you had a working solution, versus Day 17, which was actually fun to debug, since the visual signal you could use was so strong."
Ultimately though I realised that if I followed the description word by word, and made no assumptions, then I got the right solution. Still, a nightmare: you could pass all the examples, or even some alternate real sample data, and still get it wrong if you got the ordering slightly incorrect.
I was aware of Norvig's 2016 AoC solutions, but I thought he never did any of the newer editions. I know what I'll be reading today :)
It looks similar to what I though I had to write, but I will have to reread it and the documentation to understand it well.
And day 2 seems a bit too complex with my meager J knowledge. OTOH with the J interpreter for android and its terseness it seems the most suited language for programming on a phone, so I will probably stick to it.
[0] https://www.reddit.com/r/adventofcode/comments/e4axxe/2019_d...
It's honestly the only real reason to go on /g/ (or really 4chan in general) for me.
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 can't tell from the description what the actual puzzle is...
Is it that I need to generate a program that generates the output 19690720 when run through the function that was written in part 1?
My reading comprehension obviously needs some work :P
Feel like a bit of an idiot.
sum(map(lambda x: x // 3 - 2, numbers))numbers.sumBy { it / 3 - 2 }
input.map(&(-> (f) {->(g) {g.(g)}.(->(g) { f.(->(*args) {g.(g).(*args)})})}.(->(f) { ->(n) { n < 9 ? 0 : (n/3-2)+f.(n/3-2) } }))).reduce(&:+)Lot of fun though.
I'm sure theres a better way to approach some of these.
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 require advanced skills such as more sophisticated algorithms (graph theory, dynamic programming, etc.), reverse engineering, and careful debugging.
For what it's worth, I would expect anyone who knows what a loop is to be able to get the first half of today's problem without much difficulty. The second half is a bit less trivial but also pretty easy to understand.
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.
I haven't done it since 2017, and I was pretty quick (made that year's overall leaderboard), but on average they took me about 23 minutes (for both parts).
Every day's puzzle has two parts. The first part is usually easy. The second part is then a twist that requires a change to the solution of the first part.
Apart from that, you can always skip a day if you just can't solve it. The exception is that sometimes a puzzle can reference the solution of an older day, so if you'd solved the older day you would already have an understanding of how to proceed, and might be able to reuse some code.
The earlier ones, perhaps, but professional programmers struggle with the later ones. I’d never suggest that some one new to programming tries to do all of AoC.
First couple of tasks are really easy, but difficulty increases over time and so does time needed to solve them.
Someone who is currently learning about loops might not be able to solve these on their own, but with someone else's help they might learn lots of useful concepts (e.g. linked lists, bfs, basic asm, how to code efficiently...) and try to apply them.
AoC are solving usually those who are quite familiar with programming and want to learn a new language or to compete with colleagues.
In the end I think it's not a good fit, given that basic concepts are still being understood, and the mere task of reading a file and iterating over the lines, even the concept itself of what "iterating" is, is already a big challenge...
Trying is free and won't hurt, though, so why not :)
I'd suggest new programmers do any they can reasonably understand and just skip ones that seem like they'll be frustrating or require a "fast" algorithm they don't know. (OTOH, many days' first star can be gotten with a brute force algorithm. It's usually the 2nd star that takes something more clever.)
let path = Bundle.main.url(forResource: "input01", withExtension: "txt")
var text = try String(contentsOf: path!, encoding: .utf8)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?
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)")Thus for Python 3 the new // operator was added for explicit floor division (which is often quite useful in its own right), leaving the / operator to always return an exact (to machine precision) floating point result, even with integer arguments.
cf. https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...
I'd like to see a plot of average (median or mode) to finish each part but only the site has all that information.