adventofcode2022/day01/toivy.py

24 lines
507 B
Python
Raw Normal View History

2022-12-01 06:09:01 +00:00
"""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()