Skip to content

Advent of Code 2020 in Julia πŸ”΅πŸŸ’πŸ”΄πŸŸ£

Notifications You must be signed in to change notification settings

tranhd95/advent-of-code-2020

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

55 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Advent of Code 2020 in Julia πŸ”΅πŸŸ’πŸ”΄πŸŸ£!

Julia Features Notes

Nested loops syntactic sugar

collection = [1, 2, 3]
for i in collection, j in collection
	print(i, j)
end
# 11 12 13 
# 21 22 23 
# 31 32 33

Local variable that can be used as a Walrus operator

if (local foo = 1) > 0
	println(foo)
end
# 1

count(el -> Bool, collection) and probably more useful collection utilities

count(i -> (4 ≀ i ≀ 6), [2,3,4,5,6]) 
# 3

Function composition

$$ f(g(h(x))) = (f\circ g \circ h)(x) $$

# ∘ \circ<tab>
(sqrt ∘ +)(3, 6) # -> 3.0
∘(sqrt, +)(3, 6) # -> 3.0

# Multiple functions
square = x -> x^2
∘(sqrt, square, sqrt, square)(32) # -> 32.00000000000001

Unpacking list of arguments

arguments = [sqrt, square, sqrt, square]
∘(arguments...)(32) # -> 32.00000000000001

Piping

square = x -> x^2
increment = x -> x+1
5 |> increment |> square |> print # -> 36

# Elementwise application
numbers = [1, 2, 3]
numbers .|> increment .|> square # -> [4, 9 ,16]
# Equivalent to
map(x -> x |> increment |> square, numbers)

Measuring the execution time

@time begin
    ...
end

About

Advent of Code 2020 in Julia πŸ”΅πŸŸ’πŸ”΄πŸŸ£

Topics

Resources

Stars

Watchers

Forks

Languages