Invert FizzBuzz by slightair

def m(d:Seq[(Int,Char)],t:Seq[Char],q:Seq[Seq[(Int,Char)]]):Seq[Seq[(Int,Any)]]=d.map(e=>e._2).indexOfSlice(t)match{case-1=>q
case x=>m(d.drop(x+1),t,q:+d.drop(x).take(t.size))}
def p:Unit=readLine match{case null=>case l=>{println(((t:Seq[Char])=>m(Seq.tabulate(181)(i=>(Seq(3,5,6,9,10,12,15)(i%7)+i/7*15,"FBFFBFZ"(i%7))),t,Seq()).sortBy(e=>e.last._1-e.head._1)match{case x if x.size==0=>""case x=>x.head.head._1+" "+x.head.last._1})(l.split(' ').map{case"Fizz"=>'F'case"Buzz"=>'B'case"FizzBuzz"=>'Z'}.toSeq))
p}}
p

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page