Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Advent of Code 2019
#1
Hi everybody! In case you did not know about Advent of Code yet:

Quote:Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. People use them as a speed contest, interview prep, company training, university coursework, practice problems, or to challenge each other.

You don't need a computer science background to participate - just a little programming knowledge and some problem solving skills will get you pretty far. Nor do you need a fancy computer; every problem has a solution that completes in at most 15 seconds on ten-year-old hardware.

The first puzzles will unlock on December 1st at midnight Eastern Time, which is very soon.

Looking forward to exchange thoughts and small hints ( NO FULL SOLUTIONS ).
If YOU think you MUST show us your code, otherwise you would die, PLEASE use the [spoiler ][/spoiler ] tags!
Reply
#2
What's the point of solving the puzzles if you don't share your solutions?
Reply
#3
I would say that first day tasks were very basic.

It's good to remember that no need for .strip() if converting single integer on row:

>>> int('5\n')
5
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
(Dec-01-2019, 04:08 AM)Gribouillis Wrote: What's the point of solving the puzzles if you don't share your solutions?
Sharing is fine but i don´t want to be immediately spoilered opening this thread.
So everybody is invited to share their code but please use spoiler tags. :-)
Reply
#5
My solutions for day # 1

I tried to scrape data directly from input page (https://adventofcode.com/2019/day/1/input) however I was getting 400 so I just copied data into text file.

Puzzle # 1:
'sum calculation result for every row in file'


Puzzle # 2 (used Python 3.8 and walrus operator)
'sum calculation results which are greater than zero for every row in file'

I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#6
I did puzzle one same way as perfringo.

For puzzle 2 i used a recursive approach as i´m still on python 3.7

My solutions for day 1:

Reply
#7
(Dec-02-2019, 12:51 PM)perfringo Wrote: I tried to scrape data directly from input page (https://adventofcode.com/2019/day/1/input) however I was getting 400 so I just copied data into text file.
There is a way,could be a puzzle this to Wink
When logged in the session cookie will be same for all days input.
Find session cookie in browser(inspect header).
Example:
Reply
#8
(Dec-02-2019, 01:17 PM)snippsat Wrote: There is a way,could be a puzzle this to Wink

Thank you!

Day #2 puzzles I did in the copy-paste style but next days will access data directly.

Puzzle #1:
'for every slice of four check for opcode and break or apply calculation'


Puzzle #2:
'find permutation pair producing target output and return calculated value'

I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#9
Day #3

I was in real hurry with this one. So I decided to approach this 'systematically' in top-down style. I wanted to do some generator chaining but in order to get ready before my time was up I didn't follow this initial thought. Also - I did vectors decades ago, so I let shapely and numpy to do heavy lifting. This is brute-force and probably there is some math which allows to reach same result with less work.

Puzzel # 1:
'find intersection point with smallest Manhattan distance from start (0,0)'
For that:
  • read data from webpage
  • calculate relative moves
  • calculate path using relative moves
  • convert into shapely LineString
  • find all intersections
  • find smallest Manhattan distance from intersections
  • output smallest Manhattan distance


Puzzle # 2:
Intersection points were already found. So:
'Find smallest distance to intersection point' (function 'shortest_distance' in code above)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#10
I've been doing the problems in Clojure, but broadly my solution for day 3 is in the same vein as described above. The solution for day 4 was pretty short, too. Clojure is a functional language, so my solutions have lots of recursion and higher order functions (map and reduce have featured, for example).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Advent of code 2023 snippsat 2 744 Dec-08-2023, 06:52 PM
Last Post: snippsat
  PyCon 2019 snippsat 0 1,890 May-03-2019, 06:52 PM
Last Post: snippsat
  The most important skills for Python devs in 2019 adosii 6 3,588 Apr-27-2019, 12:17 AM
Last Post: Skaperen
  Stackoverflow Developer Survey Results - 2019 buran 1 2,316 Apr-09-2019, 05:23 PM
Last Post: Gribouillis
  PyConWeb 2019 bugy 0 1,908 Feb-06-2019, 08:31 AM
Last Post: bugy
  Advent of Code 2018 snippsat 0 2,565 Dec-01-2018, 11:05 PM
Last Post: snippsat
  Advent of Code 2017 stranac 5 4,737 Dec-05-2017, 08:50 AM
Last Post: buran
  Advent of Code 2016 snippsat 4 6,482 Dec-06-2016, 10:35 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020