Solve the no connection puzzle: Difference between revisions

Scala contribution added.
(Add task to ARM assembly Raspberry pi)
(Scala contribution added.)
Line 2,947:
</pre>
 
=={{header|Scala}}==
{{Out}}Best seen in running your browser either by [https://scalafiddle.io/sf/Ub2LEup/0 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/ZXGSJLFEQe21Frh4Vwp0WA Scastie (remote JVM)].
<lang Scala>object NoConnection extends App {
 
private def links = Seq(
Seq(2, 3, 4), // A to C,D,E
Seq(3, 4, 5), // B to D,E,F
Seq(2, 4), // D to C, E
Seq(5), // E to F
Seq(2, 3, 4), // G to C,D,E
Seq(3, 4, 5)) // H to D,E,F
 
private def genRandom: LazyList[Seq[Int]] = util.Random.shuffle((1 to 8).toList) #:: genRandom
 
private def notSolved(links: Seq[Seq[Int]], pegs: Seq[Int]): Boolean =
links.indices.forall(
i => !links(i).forall(peg => math.abs(pegs(i) - peg) == 1))
 
private def printResult(pegs: Seq[Int]) = {
println(f"${pegs(0)}%3d${pegs(1)}%2d")
println(f"${pegs(2)}%1d${pegs(3)}%2d${pegs(4)}%2d${pegs(5)}%2d")
println(f"${pegs(6)}%3d${pegs(7)}%2d")
}
 
printResult(genRandom.dropWhile(!notSolved(links, _)).head)
}</lang>
=={{header|Tcl}}==
{{tcllib|struct::list}}
Line 2,995 ⟶ 3,021:
}</lang>
{{out}}
<pre> 3 4
3 4
/|\ /|\
/ | X | \
Line 3,004 ⟶ 3,029:
\ | X | /
\|/ \|/
5 6</pre>
</pre>
 
=={{header|XPL0}}==
Anonymous user