I'm interested in seeing how it's done without redefining print.airstruck wrote:It can be done without messing with print, but the solutions won't be so minimal.
Code Puzzles
Re: Code Puzzles
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: Code Puzzles
bartbes wrote:Or if you're opposed to debug.setmetatable, set a metatable on _G that wraps functions when they are set, left as an exercise for the reader.
Here is one:davisdude wrote:I'm interested in seeing how it's done without redefining print.
Code: Select all
function T(f)
f(function(g) g(T) f(function()end) end)
end
Code: Select all
s{
function(w)
w(6)
print("not")
end,
function(w)
for i = 1,4 do
print("fuzzy")
w(2)
end
end,
function(w)
for i = 1,3 do
print("wuzzy")
w(2)
end
end,
function(w)
w(1)
print("was")
w(2)
for i = 1,2 do
w(2)
print("was")
end
end,
function(w)
w(1)
print("a bear")
w(2)
print("had no hair")
w(4)
print("he")
end
}
fuzzy
wuzzy
was
a bear
fuzzy
wuzzy
had no hair
fuzzy
wuzzy
was
not
fuzzy
was
he
Re: Code Puzzles
Although this doesn't work if it's nested any more than two levels.vrld wrote:Here is one:davisdude wrote:I'm interested in seeing how it's done without redefining print.Code: Select all
function T(f) f(function(g) g(T) f(function()end) end) end
(When I say "work," I mean that it doesn't repeat the printed statement above then below, which is how I expect it to work, at least).
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: Code Puzzles
It solves the puzzle ...davisdude wrote:Although this doesn't work if it's nested any more than two levels.
(When I say "work," I mean that it doesn't repeat the printed statement above then below, which is how I expect it to work, at least).
Here is a solution that allows nesting:
Code: Select all
function T(f)
local function t(g)
T(g)
f(function() end)
end
f(t)
end
Who is online
Users browsing this forum: No registered users and 3 guests