object HelloWorld { def main(args: Array[String]) { prtH(BigInt(8)) } def seq(n: BigInt, max: BigInt): String = { val l = if(max == BigInt(2)) " | " else "" if(max == BigInt(0)) "" else { if(n % BigInt(2) == BigInt(1)) "b"+ l + seq((BigInt(3)*n+BigInt(1))/BigInt(2), max-BigInt(1)) else "a" + l + seq(n / BigInt(2), max - BigInt(1)) } } def prt(n: BigInt, k: BigInt){ for(a <- BigInt(0) until n){ println(a+": "+seq(a, k)) if(a == power(BigInt(2), k-BigInt(1))-BigInt(1)) println("-------------------") } } def prtH(n: BigInt){ for(a <- BigInt(1) to n){ prt(power(BigInt(2), a), a) println("============================") } } def follow(k: BigInt, n: BigInt){ for(a <- BigInt(1) to n){ println(a+": "+seq(k, a)) println("============================") } } def power(a: BigInt, to: BigInt): BigInt = { if(to == BigInt(0)) BigInt(1) else a*power(a, to-BigInt(1)) } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more