Anonymous user
Flipping bits game: Difference between revisions
Now code ensures their is a solution
(→{{header|Go}}: Incorrect.) |
(Now code ensures their is a solution) |
||
Line 891:
=={{header|Go}}==
The code just works for N=3, but could easily be changed to accomodate higher Ns.
Line 913:
var s,t string
var moves int
target = randMatrix()
current =
current = flipCol(current, rand.Intn(2)+1)
current = flipRow(current, rand.Intn(2)+1)
}
fmt.Println("Target:")
Line 944 ⟶ 948:
}
moves++
u, _ := strconv.ParseInt(t,0,
v := int(u)
if u>3 {
fmt.Println("Wrong command!")
Line 950 ⟶ 955:
}
switch s {
case "c": {
fmt.Printf("Column %s will be flipped\n", t)
current = flipCol(current, v)
▲ for i:=0;i<3;i++ {
if current[i][u-1]==0 {▼
current[i][u-1]=1▼
} else {▼
current[i][u-1]=0▼
}▼
}▼
}
case "r": {
fmt.Printf("Row %s will be flipped\n", t)
current = flipRow(current, v)
for i:=0;i<3;i++ {▼
if current[u-1][i]==0 {▼
current[u-1][i]=1▼
} else {▼
current[u-1][i]=0▼
}
default: {
Line 1,008 ⟶ 1,001:
}
return randMat
}
func flipRow(m matrix, row int) matrix {
}
return m
}
func flipCol(m matrix, col int) matrix {
for i:=0;i<3;i++ {
}
return m
}
</lang>
|