2022-03-21 17:09:42 -05:00
|
|
|
fun print_single (cell: bool): void = do
|
2022-03-26 19:14:12 -05:00
|
|
|
match cell with
|
2022-04-01 03:15:36 -05:00
|
|
|
| true -> @write("█")
|
|
|
|
| else @write(" ")
|
|
|
|
end
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
|
|
|
|
fun print_vec (state: vec_bool) (length: int) (curr: int): void = do
|
2022-04-01 03:15:36 -05:00
|
|
|
if curr == length then @write("") else
|
2022-03-21 17:09:42 -05:00
|
|
|
do
|
2022-04-01 03:15:36 -05:00
|
|
|
@get(state, curr) |> print_single(_)
|
|
|
|
print_vec(state, length, curr + 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
|
|
|
|
fun cell_merger (a: bool) (b: bool) (c: bool): bool = do
|
|
|
|
if a then
|
|
|
|
if b then
|
|
|
|
if c then
|
2022-04-01 03:15:36 -05:00
|
|
|
return false
|
2022-03-21 17:09:42 -05:00
|
|
|
else
|
2022-04-01 03:15:36 -05:00
|
|
|
return true
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
else
|
|
|
|
if c then
|
2022-04-01 03:15:36 -05:00
|
|
|
return true
|
2022-03-21 17:09:42 -05:00
|
|
|
else
|
2022-04-01 03:15:36 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
else
|
|
|
|
if b then
|
|
|
|
if c then
|
2022-04-01 03:15:36 -05:00
|
|
|
return true
|
2022-03-21 17:09:42 -05:00
|
|
|
else
|
2022-04-01 03:15:36 -05:00
|
|
|
return true
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
else
|
|
|
|
if c then
|
2022-04-01 03:15:36 -05:00
|
|
|
return true
|
2022-03-21 17:09:42 -05:00
|
|
|
else
|
2022-04-01 03:15:36 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
|
|
|
|
fun next (state: vec_bool) (pointer: int): bool = do
|
2022-04-01 03:15:36 -05:00
|
|
|
match pointer with
|
2022-03-21 17:09:42 -05:00
|
|
|
| 0 -> do
|
2022-04-01 03:15:36 -05:00
|
|
|
let a: bool = false
|
|
|
|
let b: bool = @get(state, 1)
|
|
|
|
let c: bool = @get(state, 2)
|
|
|
|
return cell_merger(a, b, c)
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
| 1 -> do
|
2022-04-01 03:15:36 -05:00
|
|
|
let a: bool = @get(state, 0)
|
|
|
|
let b: bool = @get(state, 1)
|
|
|
|
let c: bool = @get(state, 2)
|
|
|
|
return cell_merger(a, b, c)
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
| 2 -> do
|
2022-04-01 03:15:36 -05:00
|
|
|
let a: bool = @get(state, 1)
|
|
|
|
let b: bool = @get(state, 2)
|
|
|
|
let c: bool = @get(state, 3)
|
|
|
|
return cell_merger(a, b, c)
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
| 3 -> do
|
2022-04-01 03:15:36 -05:00
|
|
|
let a: bool = @get(state, 2)
|
|
|
|
let b: bool = @get(state, 3)
|
|
|
|
let c: bool = @get(state, 4)
|
|
|
|
return cell_merger(a, b, c)
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
| 4 -> do
|
2022-04-01 03:15:36 -05:00
|
|
|
let a: bool = @get(state, 3)
|
|
|
|
let b: bool = @get(state, 4)
|
|
|
|
let c: bool = @get(state, 5)
|
|
|
|
return cell_merger(a, b, c)
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
| 5 -> do
|
2022-04-01 03:15:36 -05:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
| else return false
|
|
|
|
end
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
|
|
|
|
fun iter (state: vec_bool) (for: int) (curr: int): void = do
|
|
|
|
if curr == for then
|
2022-04-01 03:15:36 -05:00
|
|
|
@write("")
|
2022-03-21 17:09:42 -05:00
|
|
|
else
|
|
|
|
do
|
|
|
|
let next_state: vec_bool = [
|
|
|
|
next(state, 0),
|
|
|
|
next(state, 1),
|
|
|
|
next(state, 2),
|
|
|
|
next(state, 3),
|
|
|
|
next(state, 4),
|
|
|
|
next(state, 5)
|
2022-04-01 03:15:36 -05:00
|
|
|
]
|
2022-03-21 17:09:42 -05:00
|
|
|
|
2022-04-01 03:15:36 -05:00
|
|
|
print_vec(next_state, 6, 0)
|
|
|
|
@write("\n")
|
|
|
|
iter(next_state, for, curr + 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-03-21 17:09:42 -05:00
|
|
|
|
|
|
|
fun main: void = do
|
2022-04-01 03:15:36 -05:00
|
|
|
let vec: vec_bool = [false, false, false, false, false, true]
|
|
|
|
print_vec(vec, 6, 0)
|
|
|
|
@write("\n")
|
2022-03-21 17:09:42 -05:00
|
|
|
|
2022-04-01 03:15:36 -05:00
|
|
|
iter(vec, 20, 0)
|
|
|
|
end
|