Set, the card game: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: handle plurals corrrectly) |
m (→{{header|Julia}}: remove unused code) |
||
Line 122: | Line 122: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<syntaxhighlight lang="julia">import |
<syntaxhighlight lang="julia">import Random: shuffle |
||
import Random: shuffle |
|||
import Combinatorics: combinations |
import Combinatorics: combinations |
||
Line 132: | Line 131: | ||
struct SetCard |
struct SetCard |
||
t::Tuple{UInt8, UInt8, UInt8, UInt8} |
|||
shading::UInt8 |
|||
color::UInt8 |
|||
symbol::UInt8 |
|||
function SetCard(num, sha, col, sym) |
function SetCard(num, sha, col, sym) |
||
@assert all(i -> 1 <= i <= 3, (num, sha, col, sym)) |
@assert all(i -> 1 <= i <= 3, (num, sha, col, sym)) |
||
return new(num, sha, col, sym) |
return new(tuple(num, sha, col, sym)) |
||
end |
end |
||
end |
end |
||
Base.vec(s::SetCard) = vec(s.t) |
|||
function Base.string(s::SetCard) |
|||
return "(" * |
|||
col(s::SetCard) = COLORS[s.color] |
|||
join([NUMBERS[s.t[1]], SHADINGS[s.t[2]], COLORS[s.t[3]], SYMBOLS[s.t[4]]], " ") * |
|||
sym(s::SetCard) = SYMBOLS[s.symbol] |
|||
⚫ | |||
Base.vec(sc::SetCard) = [sc.number, sc.shading, sc.color, sc.symbol] |
|||
function Base.string(sc::SetCard) |
|||
⚫ | |||
return "(" * join([num(sc), sha(sc), col(sc), sym(sc)], " ") * plu * ")" |
|||
end |
end |
||
Base.print(io:: IO, sc::SetCard) = print(io, string(sc)) |
Base.print(io:: IO, sc::SetCard) = print(io, string(sc)) |
||
Base.print(io:: IO, vsc::Vector{SetCard}) = print(io, "[" * join(string.(vsc), ", ") * "]") |
Base.print(io:: IO, vsc::Vector{SetCard}) = print(io, "[" * join(string.(vsc), ", ") * "]") |
||
""" |
""" Return an iterator for a vector of the sets found in the dealt `cards` """ |
||
function allsameordifferent(sc1::SetCard, sc2, sc3) |
|||
a, b, c = vec(sc1), vec(sc2), vec(sc3) |
|||
⚫ | |||
⚫ | |||
""" Return a vector of the sets in the vector of SetCards """ |
|||
function process_deal(cards::Vector{SetCard}) |
function process_deal(cards::Vector{SetCard}) |
||
return Iterators.filter( |
return Iterators.filter(combinations(cards, 3)) do c |
||
⚫ | |||
⚫ | |||
end |
end |
||