Flipping bits game: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Incorrect.) |
(Now code ensures their is a solution) |
||
Line 891: | Line 891: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{incorrect|Go|No attempt to ensure target is reachable from starting position.}} |
|||
The code just works for N=3, but could easily be changed to accomodate higher Ns. |
The code just works for N=3, but could easily be changed to accomodate higher Ns. |
||
Line 913: | Line 913: | ||
var s,t string |
var s,t string |
||
var moves int |
var moves int |
||
moves = 1 |
|||
target = randMatrix() |
target = randMatrix() |
||
current = |
current = target |
||
⚫ | |||
current = flipCol(current, rand.Intn(2)+1) |
|||
current = flipRow(current, rand.Intn(2)+1) |
|||
} |
|||
fmt.Println("Target:") |
fmt.Println("Target:") |
||
Line 944: | Line 948: | ||
} |
} |
||
moves++ |
moves++ |
||
u, _ := strconv.ParseInt(t,0, |
u, _ := strconv.ParseInt(t,0,0) |
||
v := int(u) |
|||
if u>3 { |
if u>3 { |
||
fmt.Println("Wrong command!") |
fmt.Println("Wrong command!") |
||
Line 950: | Line 955: | ||
} |
} |
||
switch s { |
switch s { |
||
case "c": { |
case "c": { |
||
fmt.Printf("Column %s will be flipped\n", t) |
fmt.Printf("Column %s will be flipped\n", t) |
||
current = flipCol(current, v) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
case "r": { |
case "r": { |
||
fmt.Printf("Row %s will be flipped\n", t) |
fmt.Printf("Row %s will be flipped\n", t) |
||
current = flipRow(current, v) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
} |
|||
} |
} |
||
default: { |
default: { |
||
Line 1,008: | Line 1,001: | ||
} |
} |
||
return randMat |
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> |
</lang> |