day 8 ivy part 1
parent
9c7847b91c
commit
383ff93502
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,17 @@
|
|||
) get "input.ivy"
|
||||
|
||||
sample = 5 5 rho 3 0 3 7 3 2 5 5 1 2 6 5 3 3 2 3 3 5 4 9 3 5 3 9 0
|
||||
|
||||
op visible r =
|
||||
r = -1, r
|
||||
r = transp max\ transp r
|
||||
r = r > -1 flip r
|
||||
1 drop r
|
||||
|
||||
op vis2 m = (visible m) or (flip visible flip m)
|
||||
op vis4 m = (vis2 m) or (transp vis2 transp m)
|
||||
|
||||
sample
|
||||
+/, vis4 sample
|
||||
+/, vis4 input
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#!/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="")
|
Loading…
Reference in New Issue