Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/metalim/adventofcode.2019.python
Advent of Code 2019 in Python / Jupyter Notebook
https://github.com/metalim/adventofcode.2019.python
advent-of-code advent-of-code-2019 jupyter-notebook python
Last synced: 6 days ago
JSON representation
Advent of Code 2019 in Python / Jupyter Notebook
- Host: GitHub
- URL: https://github.com/metalim/adventofcode.2019.python
- Owner: metalim
- Created: 2019-12-04T09:48:20.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-26T08:35:22.000Z (over 1 year ago)
- Last Synced: 2024-12-18T18:16:51.966Z (6 days ago)
- Topics: advent-of-code, advent-of-code-2019, jupyter-notebook, python
- Language: Jupyter Notebook
- Homepage: https://adventofcode.com/2019
- Size: 103 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Advent of Code 2019 in Python / Jupyter Notebook
This year I'll be using [Advent of Code](https://adventofcode.com/2019/) to learn [Python](https://www.python.org/).
As my goal is more Deep Learning, than Python programming itself, I'll be doing AoC in [Jupyter Notebook](https://jupyter.org/).Goals:
* Learn Python tricks.
* Learn Jupyter Notebook tricks.
* Make it look pretty on GitHub.## Quirks & tricks
While Python resembles [CoffeeScript](https://coffeescript.org/) - my favorite language so far (*well, vice versa in reality: CoffeeScript resembles Python*), Python has many legacy design decisions you have to adapt to. To name a few:
* Order of blocks in short form of `if`:
```python
if else# it gets weird for nested conditionals
if else if else
```In CoffeeScript it's:
```coffeescript
if
# or
if then else# and for nested
if then else if then else
```While I clearly see why Python does that, it takes time to adapt to.
* No switch statement. Alternative is wordy:
```python
if x == 0:
elif x == 1:
elif x == 2:
else:
```* You can write:
```python
for x in if
```but you can't write:
```python
for x in if :
```* Breaking outer loop has strange syntax, but I kinda like it:
```python
for :
for :
if : break
else:
# inner loop completed without breaking
```* Numbers in Python are not just arbitrary precision floating point bignums, but complex numbers as well. I like how writing both parts is optional. Makes it easier to define directions in 2D:
```python
ds = [1, 1j, -1, -1j] # for Right, Up, Left, Down.
```* Sets in Python are powerful.
```python
A = {1,2,3,4}
B = {3,4,5}
C = A - B # == {1,2}
D = B - A # == {5}
D = B | {1} # == {1,3,4,5}
```* Python doesn't allow inline assignment operations. Following is not possible:
```python
for s in input.split('\n'):
if (match = re.match(r'some number: (-?\d+)', s)) != None:
# do something with match.group(1)
elif (match = re.match(r'something else: (.+)', s)) != None:
# do something with match.group(1)
```Instead you have to write something like:
```python
for s in input.split('\n'):
match = re.match(r'some number: (-?\d+)', s)
if match != None:
# do something with match.group(1)
continue
match = re.match(r'something else: (.+)', s)
if match != None:
# do something with match.group(1)
continue
```That's no longer true in Python 3.8, where you can use special "walrus operator" `:=`, introduced especially for inline assignments:
```python
for s in input.split('\n'):
if (match := re.match(r'some number: (-?\d+)', s)) != None:
# do something with match.group(1)
elif (match := re.match(r'something else: (.+)', s)) != None:
# do something with match.group(1)
```## All years AoC solutions
* 2022:
* [Go](https://github.com/metalim/metalim.adventofcode.2022.go)
* 2021:
* [Go](https://github.com/metalim/metalim.adventofcode.2021.go)
* 2020:
* [Lรคng & Python](https://github.com/metalim/metalim.adventofcode.2020.lang) โ๐
* 2019:
* [Python in Jupyter Notebook](https://github.com/metalim/metalim.adventofcode.2019.python) โ love this one, as it shows pretty results on GitHub ๐ you are here
* 2018
* [Go](https://github.com/metalim/metalim.adventofcode.2018.go)
* 2017:
* **[CoffeeScript](https://github.com/metalim/metalim.adventofcode.2017) ๐ first year I was doing AoC**
* [Go](https://github.com/metalim/metalim.adventofcode.2017.go) โ done in December 2018
* 2016:
* [CoffeeScript](https://github.com/metalim/metalim.adventofcode.2016) โ done in December 2017
* [Go](https://github.com/metalim/metalim.adventofcode.2016.go) โ done in January 2019, incomplete
* 2015:
* [CoffeeScript](https://github.com/metalim/metalim.adventofcode.2015) โ done in December 2017## Useful links
* [Advent of Code](https://adventofcode.com/) - obviously.
* [Scatterplot](http://www.maurits.vdschee.nl/scatterplot/) - timings of first 100 solvers for all AoC tasks.
* [Medals](http://www.maurits.vdschee.nl/scatterplot/medals.html) - top 3 positions for each task.
* [r/adventofcode](https://www.reddit.com/r/adventofcode/) - subreddit with solutions and discussions. [Visualizations](https://www.reddit.com/r/adventofcode/search?q=flair_name%3A%22Visualization%22&restrict_sr=1&sort=new) are nice.* Other challenges/exercises:
* [Exercism](https://exercism.io/) - exercises in many language tracks. Submit code. Can see other solutions. Tasks are mostly trivial. Can request mentor to improve you coding style. I was very satisfied with Go mentor *bitfield*.
* [Codewars](https://www.codewars.com/) - programming tasks in many languages. Submit code. Can see other solutions. 1 kyu (hardest level) katas often question your understanding of language internals.
* [Project Euler](https://projecteuler.net/) - probably the oldest programming challenge resource. Heavily math-based. Submit answers.
* [CodinGame](https://www.codingame.com/) - programming tasks in many languages. Submit code and see resulting animation. Can see ofther solutions. Has bot battles, if you want competition.
* [CodeForces](https://codeforces.com/) - coding contests several times a month. Similar to IT Olympics/Olympiads, but online. Can solve tasks in archive, if you don't want competition. Can participate in Virtual contests, if you want competition, but contest is over.
* [HackerRank](https://www.hackerrank.com/) - very wide range of challenges. Submit code. Many languages to choose from. Acceptance tests (and results of their execution) are hidden, which makes it more challenging. Practice, compete, prepare for coding interview, solve test tasks from employers. Competitions include long-running translation of challenges from Project Euler (currently first 245 tasks).
* Will not include link to Topcoder, as their website now looks like marketing shโt. Never used, probably never will.