June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
33
Task/Odd-word-problem/Julia/odd-word-problem.julia
Normal file
33
Task/Odd-word-problem/Julia/odd-word-problem.julia
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# io = readstring(STDIN)
|
||||
io = "what,is,the;meaning,of:life."
|
||||
i = 0
|
||||
|
||||
readbyte!() = io[global i += 1]
|
||||
writebyte(c) = print(Char(c))
|
||||
|
||||
function odd(prev::Function = () -> false)
|
||||
a = readbyte!()
|
||||
if !isalpha(a)
|
||||
prev()
|
||||
writebyte(a)
|
||||
return a != '.'
|
||||
end
|
||||
|
||||
# delay action until later, in the shape of a closure
|
||||
clos() = (writebyte(a); prev())
|
||||
|
||||
return odd(clos)
|
||||
end
|
||||
|
||||
function even()
|
||||
while true
|
||||
c = readbyte!()
|
||||
writebyte(c)
|
||||
if !isalpha(c) return c != '.' end
|
||||
end
|
||||
end
|
||||
|
||||
evn = false
|
||||
while evn ? odd() : even()
|
||||
evn = !evn
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue