Skip to content

Instantly share code, notes, and snippets.

@p-pavel
Last active August 28, 2023 16:40
Show Gist options
  • Save p-pavel/17e40b2a52a473f620d0a3aca2782af4 to your computer and use it in GitHub Desktop.
Save p-pavel/17e40b2a52a473f620d0a3aca2782af4 to your computer and use it in GitHub Desktop.
flip flop
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