-
-
Save halcat0x15a/2700564 to your computer and use it in GitHub Desktop.
InverseFizzbuzz : http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html
This file contains 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
// Inversefizzbuzz | |
// http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html | |
// | |
// fork from https://gist.github.com/2699068 | |
import scalaz._ | |
import Scalaz._ | |
object InverseFizzbuzz extends App { | |
def zzubzzif(pattern: Seq[String]) = Stream.from(1).map(_.squared.mapElements(_ % 3 |> (1 -) |> ("fizz" *), _ % 5 |> (1 -) |> ("buzz" *)).fold(_ + _)).indexOfSlice(pattern).from.take(pattern.size) | |
def _p(s:Seq[String]) = { | |
println("pattern : %s" format (s.map{s => s.mkString("'", "", "'")})) | |
println(zzubzzif(s)) | |
println("") | |
} | |
_p(Seq("fizz")) | |
_p(Seq("buzz")) | |
_p(Seq("fizz","","buzz")) | |
_p(Seq("fizz","buzz")) | |
_p(Seq("buzz","fizz")) | |
_p(Seq("fizz","","buzz","fizz")) | |
_p(Seq("fizz","","","fizz")) | |
_p(Seq("fizz","","","fizz","buzz")) | |
// Result: | |
// | |
// pattern : List('fizz') | |
// List(2) | |
// | |
// pattern : List('buzz') | |
// List(4) | |
// | |
// pattern : List('fizz', '', 'buzz') | |
// List(2, 3, 4) | |
// | |
// pattern : List('fizz', 'buzz') | |
// List(8, 9) | |
// | |
// pattern : List('buzz', 'fizz') | |
// List(4, 5) | |
// | |
// pattern : List('fizz', '', 'buzz', 'fizz') | |
// List(2, 3, 4, 5) | |
// | |
// pattern : List('fizz', '', '', 'fizz') | |
// List(5, 6, 7, 8) | |
// | |
// pattern : List('fizz', '', '', 'fizz', 'buzz') | |
// List(5, 6, 7, 8, 9) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment