Flipping bits game: Difference between revisions
m
→{{header|Julia}}
(→{{header|Scala}}: Output or reason for omission.) |
|||
Line 1,779:
=={{header|Julia}}==
<lang julia>module FlippingBitsGame
using
import Base.size, Base.show, Base.==
struct Configuration
M::BitMatrix
end
Base.size(c::Configuration) = size(c.M)
function Base.show(io::IO, conf::Configuration)
Line 1,810 ⟶ 1,807:
end
Base.:(==)(a::Configuration, b::Configuration) = a.M == b.M
struct Index{D}
i::Int
Line 1,816 ⟶ 1,813:
const ColIndex = Index{:C}
const RowIndex = Index{:R}
function
col = @view conf.M[:, c.i]
@. col = !col
return conf
end
function
row = @view conf.M[r.i, :]
@. row = !row
return conf
end
randomconfig(nrow::Integer, ncol::Integer) = Configuration(bitrand(nrow, ncol))▼
▲randomconfig(nrow::Integer, ncol::Integer) = Configuration(bitrand(nrow, ncol))
function randommoves!(conf::Configuration, nflips::Integer)
nrow, ncol = size(conf)
Line 1,840 ⟶ 1,838:
return conf
end
function play()
nrow::Int, ncol::Int = 0, 0
Line 1,876 ⟶ 1,874:
return
end
end # module FlippingBitsGame
FlippingBitsGame.play()
</lang>{{output}}
<pre>Insert the size of the matrix (nrow [> 1] *space* ncol [> 1]):3 3
|