Last active
August 28, 2023 16:40
-
-
Save p-pavel/17e40b2a52a473f620d0a3aca2782af4 to your computer and use it in GitHub Desktop.
flip flop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flipFlopChain: List[Boolean] => List[Boolean] = | |
case Nil => Nil | |
case a :: rest => | |
val a1 = !a | |
val rest1 = if a1 then flipFlopChain(rest) else rest | |
a1 :: rest1 | |
def chainToString(l: Seq[Boolean]): String = | |
String(l.toArray.map { case true => '1'; case false => '0' }) | |
@main def testFlipFlop = | |
val numFlipFlops = 64 | |
val startState = List.fill(numFlipFlops)(false) | |
Stream | |
.iterate(startState)(flipFlopChain) | |
.map(chainToString) | |
.map(_ + "\r") | |
.foreach(print) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment