day 8 ivy part 1

这个提交包含在:
magical 2022-12-07 23:11:37 -08:00
父节点 9c7847b91c
当前提交 383ff93502
共有 3 个文件被更改,包括 52 次插入0 次删除

1
day08/input.ivy 普通文件

文件差异因一行或多行过长而隐藏

17
day08/sol.ivy 普通文件
查看文件

@ -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

34
day08/toivy.py 可执行文件
查看文件

@ -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="")