Last active
March 17, 2016 11:42
-
-
Save antimon2/220eeac0a5ef50a5e989 to your computer and use it in GitHub Desktop.
ズンドコキヨシ.jl with Iteration (追記あり) ref: http://qiita.com/antimon2/items/b198076666b40c72cece
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zundoko_iter.jl | |
immutable ZunDoko end | |
Base.start(::ZunDoko) = 0 | |
Base.done(::ZunDoko, i::Int) = i == 6 | |
function Base.next(::ZunDoko, i::Int) | |
if i == 5 | |
("キ・ヨ・シ!", 6) | |
elseif i == 4 | |
rand([("ズン", 4), ("ドコ", 5)]) | |
else | |
rand([("ズン", i + 1), ("ドコ", 0)]) | |
end | |
end | |
function runzundoko() | |
for cw in ZunDoko() | |
print(cw) | |
end | |
println() | |
end | |
runzundoko() | |
# => ズンズンズンドコズンズンズンドコドコドコドコズンズンズンズンズンドコキ・ヨ・シ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zundoko_iter_strict.jl | |
immutable ZunDoko end | |
Base.start(::ZunDoko) = 0 | |
Base.done(::ZunDoko, i::Int) = i == 6 | |
function Base.next(::ZunDoko, i::Int) | |
if i == 5 | |
("キ・ヨ・シ!", 6) | |
elseif i == 4 | |
rand([("ズン", -1), ("ドコ", 5)]) | |
elseif i == -1 | |
rand([("ズン", -1), ("ドコ", 0)]) | |
else | |
rand([("ズン", i + 1), ("ドコ", 0)]) | |
end | |
end | |
function runzundoko() | |
for cw in ZunDoko() | |
print(cw) | |
end | |
println() | |
end | |
runzundoko() | |
# => ドコズンズンズンズンズンズンドコズンズンズンズンドコキ・ヨ・シ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# zundoko_iter_val.jl | |
immutable ZunDoko end | |
Base.start(::ZunDoko) = Val{0} | |
Base.done(::ZunDoko, ::Type{Val{6}}) = true | |
Base.done{N}(::ZunDoko, ::Type{Val{N}}) = false | |
Base.next(::ZunDoko, ::Type{Val{5}}) = ("キ・ヨ・シ!", Val{6}) | |
Base.next(::ZunDoko, ::Type{Val{4}}) = rand([("ズン", Val{4}), ("ドコ", Val{5})]) | |
Base.next{N}(::ZunDoko, ::Type{Val{N}}) = rand([("ズン", Val{N+1}), ("ドコ", Val{0})]) | |
function runzundoko() | |
for cw in ZunDoko() | |
print(cw) | |
end | |
println() | |
end | |
runzundoko() | |
# => ドコドコズンズンズンドコズンズンドコズンドコドコズンドコズンズンズンズンドコキ・ヨ・シ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment