Simple functional Python library designed for learning and problem solving purposes inspired by APL and Elixir programming languages.
Created mainly for solving Advent of Code challenges - hence the name advent.
While Python is a very versatile and powerful programming language it lacks functional approach found in other languages.
For better demonstration let's look at the puzzle Calorie Counting from day 1 of Advent of Code 2022.
with open('input.txt') as file:
content = file.read()
biggest = 0
for chunk in content.split('\n\n'):
total = 0
for line in chunk.split('\n'):
n = int(line)
total += n
if total > biggest:
biggest = total
print(biggest)with open('input.txt') as file:
content = file.read()
parsed = (map(int, line.split('\n')) for line in content.split('\n\n'))
solution = max(map(sum, parsed))
print(solution)from advent import *
solver = (
gn.read_file('input.txt')
| tt.split_by('\n\n')
| sq.map(
tt.split_by('\n')
| sq.map(int)
| sq.sum()
)
| sq.max()
)
print(solver())File.read!("input.txt")
|> String.split("\n\n")
|> Stream.map(fn line ->
line
|> String.split("\n")
|> Stream.map(&String.to_integer/1)
|> Enum.sum()
end)
|> Enum.max()
|> IO.puts()- combinators (cb)
- functions (fn)
- generators (gn)
- operators (op)
- regex (rx)
- sequences (sq)
- textual (tt)
- Clean interface (arguably)
- Functions piping
- Arguments binding
- Basic combinators