We're on to Day 3 now! I'm seeing a bunch of cool languages getting submitted, which is really fun. Let's get to the puzzle!
The Puzzle
In today’s puzzle, we're trying to toboggan down a foresty slope to get to the coast for our trip. But trees aren't conducive to safe sledding, so we're checking our options carefully before starting. 2-D grids are a staple of Advent of Codeses past, and we've seen things dealing with rational slopes too. But it'll be interesting seeing how you decide to sled down these particular rational slopes. 😉
The Leaderboards
As always, this is the spot where I’ll plug any leaderboard codes shared from the community.
Ryan's Leaderboard: 224198-25048a19
If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.
Yesterday’s Languages
Updated 03:06PM 12/12/2020 PST.
| Language | Count |
|---|---|
| Python | 5 |
| Ruby | 3 |
| Rust | 3 |
| JavaScript | 2 |
| Raku | 1 |
| COBOL | 1 |
| PHP | 1 |
| Elixir | 1 |
| C | 1 |
Merry Coding!
Latest comments (39)
Here's my beginner's Haskell solution:
Vanilla JS solution in 12 lines of code:
//create arr with input as template literal
let newArr= arr.split(/\r?\n/);//split by endlines
let xCord = 0;//X coordinates
let counter = 0;//trees hit counter
for(let i = 0 ; i < newArr.length ; i++){
let temp = newArr[i].split('');//split into array of characters
if(temp[xCord]=='#'){//checking for trees
counter++;//if there is a tree increment the counter
}
xCord = xCord +3;//add +3 to the right
if(xCord>=31){//check if there is more coords than elements in array
xCord = xCord-31;//reset coords
}}
console.log(counter);//result
SQL works for me ;)
0 lines of code. No loops, no boolean flag, only SQL.
Get this table naming 'day3':
3.1 Solution
3.2 Solution
Haskell
My JavaScript walkthrough:
Python implementation using numpy.
Spent ages trying to get this figured using array striding but eventually my head exploded and I resorted to using indices.
My solution in C#:
My ugly python version
Hi! Thanks for sharing!
FYI, if you want to get some syntax highlighting in your comments, you can use three backtics followed by the language name to open and three backticks by themselves to close. Here's the Markdown cheat sheet for reference.
Completed my day 3 with a little help from comments here
Short Python solution