day 23 ivy wip
parent
91da124cf7
commit
540bbb9a9e
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,64 @@
|
|||
)get "input.ivy"
|
||||
sample = 7 7 rho '....#..' '..###.#' '#...#.#' '.#...##' '#.###..' '##.#.##' '.#..#..'
|
||||
|
||||
board = sample == '#'
|
||||
#board
|
||||
|
||||
op north a = 1 flip a
|
||||
op south a = -1 flip a
|
||||
op west a = 1 rot a
|
||||
op east a = -1 rot a
|
||||
|
||||
#north 3 3 rho iota 9
|
||||
|
||||
op a coalesce b =
|
||||
a: a
|
||||
b
|
||||
|
||||
op any a = or/,a
|
||||
op pad a = 0,(transp (0,(transp a),0)),0
|
||||
op needsPad a = (any 0 != a[1,(rho a)[1]]) or (any 0 != a[;(1,(rho a)[2])])
|
||||
op maybePad a =
|
||||
needsPad a: pad a
|
||||
a
|
||||
|
||||
|
||||
op smearWE a = a or (west a) or (east a)
|
||||
op smearNS a = a or (north a) or (south a)
|
||||
op lift a = (1,rho a) rho a
|
||||
|
||||
op show a = (text ".#23456789"[1+a]),"\n-"
|
||||
|
||||
M = 0
|
||||
|
||||
a = maybePad board
|
||||
n = south smearWE a
|
||||
s = north smearWE a
|
||||
e = west smearNS a
|
||||
w = east smearNS a
|
||||
#n
|
||||
|
||||
p = 4 3 2 1
|
||||
|
||||
C = (lift n) , (lift s) , (lift w) , (lift e)
|
||||
rho C
|
||||
canMove = a and or/ 3 1 2 transp C # can move if there is an elf nearby
|
||||
C2 = (not C) and (rho C) rho canMove # can move in a direction if not alone and there is no elf in that direction
|
||||
show C2
|
||||
P1 = max/ p * 3 1 2 transp C2 # select direction
|
||||
P2 = p o.== P1 # decompose into 4x?x? matrix
|
||||
P1; "\n-"
|
||||
C3 = (north P2[1]) + (south P2[2]) + (west P2[3]) + (east P2[4])
|
||||
C3; "\n-"
|
||||
notBlock = C3 == 1
|
||||
C4 = (lift south notBlock), (lift north notBlock), (lift east notBlock), (lift west notBlock)
|
||||
rho C4
|
||||
P3 = P2 and C4
|
||||
show P3
|
||||
moved = or/ 3 1 2 transp P3
|
||||
moved
|
||||
#a and not moved
|
||||
#show P3
|
||||
B = (a and not moved) + (north P3[1]) + (south P3[2]) + (west P3[3]) + (east P3[4])
|
||||
show a
|
||||
show B
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Converts a text file containing a list of integers
|
||||
into a format that can be loaded by ivy.
|
||||
"""
|
||||
|
||||
import sys
|
||||
if sys.argv[1:]:
|
||||
filename = sys.argv[1]
|
||||
else:
|
||||
filename = "input"
|
||||
|
||||
varname = filename.split(".",1)[0]
|
||||
|
||||
with open(filename) as f:
|
||||
lines = f.read().splitlines()
|
||||
|
||||
data = []
|
||||
for line in lines:
|
||||
line = line.replace("-", ",")
|
||||
data.append(line.split(","))
|
||||
|
||||
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("{} = {} {} rho".format(varname, 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