day 1 ivy solution

main
magical 2022-11-30 22:09:01 -08:00
parent 64779081cb
commit 71b38be272
3 changed files with 32 additions and 0 deletions

1
day01/input.ivy 100644

File diff suppressed because one or more lines are too long

8
day01/sol.ivy 100644
View File

@ -0,0 +1,8 @@
) get "input.ivy"
# part 1
max/ +/ input
# part 2
sums = +/ input
+/ sums[3 take down sums]

23
day01/toivy.py 100644
View File

@ -0,0 +1,23 @@
"""reads a ragged array and converts it to ivy code
input: whitespace separated values, with each chunk separated by a blank line
"""
import sys
import re
with open("input") as f:
chunks = f.read().split("\n\n")
data = []
for x in chunks:
data.append(x.replace(",", " ").split())
cols = max(len(row) for row in data)
print("input = {} {} rho".format(len(data), cols), end="")
for x in data:
print("", *x, end="")
if len(x) < cols:
print(" 0" * (cols - len(x)), end="")
print()