adventofcode2022/day08/toivy.py

35 lines
682 B
Python
Raw Normal View History

2022-12-08 07:11:37 +00:00
#!/usr/bin/env python3
"""
Converts a text file containing a list of integers
into a format that can be loaded by ivy.
"""
with open("input") as f:
lines = f.read().splitlines()
data = []
for line in lines:
line = list(line.strip())
data.append(line)
def count(row):
n = 0
for x in row:
if x.isdigit():
n += 1
else:
n += len(x)
return n
cols = max(map(count, data))
print("input = {} {} rho".format(len(data), cols), end="")
for row in data:
print("", " ".join(
x if x.isdigit() else repr(x)
for x in row), end="")
n = count(row)
if n < cols:
print(" 0" * (cols - n), end="")