Solve the no connection puzzle: Difference between revisions

Line 1,256:
\|/ \|/
3 4</lang>
 
 
=={{header|Julia}}==
<lang julia>
using Combinatorics
 
const HOLES = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
 
const PEGS = [1, 2, 3, 4, 5, 6, 7, 8]
 
const EDGES = [('A', 'C'), ('A', 'D'), ('A', 'E'),
('B', 'D'), ('B', 'E'), ('B', 'F'),
('C', 'G'), ('C', 'D'), ('D', 'G'),
('D', 'E'), ('D', 'H'), ('E', 'F'),
('E', 'G'), ('E', 'H'), ('F', 'H')]
 
function goodplacements()
goodtrials = Array{Vector{Int},1}()
for perm in permutations(PEGS)
trial = Dict()
for (i, p) in enumerate(perm)
trial[HOLES[i]] = p
end
goodtrial = true
for edge in EDGES
if abs(trial[edge[1]] - trial[edge[2]]) < 2
goodtrial = false
break
end
end
if goodtrial
push!(goodtrials, perm)
end
end
println("Found $(length(goodtrials)) solutions.")
goodtrials
end
 
const BOARD = raw"""
A B
/|\ /|\
/ | X | \
/ |/ \| \
C - D - E - F
\ |\ /| /
\ | X | /
\|/ \|/
G H
"""
 
function printsolutions()
solutions = goodplacements()
for soln in solutions
board = BOARD
for (i, n) in enumerate(soln)
board = replace(board, string('A' + i - 1) => string(n))
end
println(board); exit(1) # remove this exit for all solutions
end
end
 
printsolutions()
</lang> {{output}} <pre>
Found 16 solutions.
3 4
/|\ /|\
/ | X | \
/ |/ \| \
7 - 1 - 8 - 2
\ |\ /| /
\ | X | /
\|/ \|/
5 6
</pre>
 
 
4,105

edits