Odd word problem: Difference between revisions
Content added Content deleted
(Run BASIC entry is incorrect) |
(→{{header|Lua}}: added Lua solution) |
||
Line 1,494: | Line 1,494: | ||
what,si,the;gninaem,of:efil. |
what,si,the;gninaem,of:efil. |
||
Should have: |
Should have: |
||
what,si,the;gninaem,of:efil.</pre> |
|||
=={{header|Lua}}== |
|||
<lang lua>function reverse() |
|||
local ch = io.read(1) |
|||
if not ch then return end |
|||
if ch:find("%w") then |
|||
local rc = reverse() |
|||
io.write(ch) |
|||
return rc |
|||
end |
|||
return ch |
|||
end |
|||
function forward() |
|||
ch = io.read(1) |
|||
if not ch then return false end |
|||
io.write(ch) |
|||
if ch == "." then return false end |
|||
if ch:find("%w") then |
|||
return forward() |
|||
else |
|||
ch = reverse() |
|||
if ch then io.write(ch) end |
|||
end |
|||
return true |
|||
end |
|||
while forward() do end</lang> |
|||
{{out}} |
|||
<pre>$ echo we,are;not,in,kansas;any,more.|oddword.lua |
|||
we,era;not,ni,kansas;yna,more. |
|||
$ echo what,is,the;meaning,of:life.|oddword.lua |
|||
what,si,the;gninaem,of:efil.</pre> |
what,si,the;gninaem,of:efil.</pre> |
||