|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://anggtwu.net/LUA/JumpingFrogs1.lua.html
-- http://anggtwu.net/LUA/JumpingFrogs1.lua
-- (find-angg "LUA/JumpingFrogs1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/JumpingFrogs1.lua"))
-- https://rvlabs.ca/jumping-frogs
-- https://news.ycombinator.com/item?id=43461022 A difficult game to test your logic (rvlabs.ca)
now = ">>>_<<<"
moves = {{">_", "_>"}, {"_<", "<_"},
{"><_", "_<>"}, {"_><", "<>_"}}
opts = function (now)
local T = VTable {}
for _,ab in ipairs(moves) do
local new,n = now:gsub(ab[1], ab[2])
if n == 1 then table.insert(T, new) end
-- print(new, n)
end
return T
end
fulltree = function (now)
local T = VTable(map(fulltree, opts(now)))
return VTable {now, T}
end
dfs = function (history, T)
if T[1] == "<<<_>>>" then print(history) end
for _,newT in ipairs(T[2]) do
local newhistory = copy(history)
table.insert(newhistory, newT[1])
dfs(newhistory, newT)
end
end
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "JumpingFrogs1.lua"
= opts(">>>_<<<")
FT = fulltree(">>>_<<<")
dfs(VTable{">>>_<<<"}, FT)
--]]
-- Local Variables:
-- coding: utf-8-unix
-- End: