Solve the no connection puzzle: Difference between revisions

m
→‎{{header|Java}}: small changes
(→‎{{header|Java}}: using prefined connections like the Go example is more convenient)
m (→‎{{header|Java}}: small changes)
Line 727:
 
// adopted from Go
static int[][] connectionslinks = {
{2, 3, 4}, // A to C,D,E
{3, 4, 5}, // B to D,E,F
{2, 4}, // D to C, E
{5}, // E to F
{2, 3, 4}, // G to C,D,E
{3, 4, 5}, // H to D,E,F
Line 740:
public static void main(String[] args) {
 
List<Integer> valuesvals = range(1, 9).mapToObj(i -> i).collect(toList());
do {
Collections.shuffle(valuesvals);
for (int i = 0; i < pegs.length; i++)
pegs[i] = valuesvals.get(i);
 
} while (!solved());
Line 752:
 
static boolean solved() {
for (int i = 0; i < connectionslinks.length; i++)
for (int peg : connectionslinks[i])
if (abs(pegs[i] - peg) == 1)
return false;
Anonymous user