Skip to content

Instantly share code, notes, and snippets.

@otobrglez
Created September 10, 2014 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otobrglez/28b70770b1d3b5de6620 to your computer and use it in GitHub Desktop.
Save otobrglez/28b70770b1d3b5de6620 to your computer and use it in GitHub Desktop.
FizzBuzz in Scala w/ lists, tuples and magic
object Application {
def fizzBuzzMega(e: Int): List[String] = {
var big = (1 to e).toList.map (i => i.toString)
val m = List(
(3, ((1 to e).toList zip List.range(0, e+3, 3)).drop(1).map (_._2)),
(5, ((1 to e).toList zip List.range(0, e+5, 5)).drop(1).map (_._2)),
(3*5, ((1 to e).toList zip List.range(0, e+3*5, 15)).drop(1).map (_._2))
).map(p =>
p._2.map (n =>
big = big.updated(n-1,
(Map(3->"Fizz", 5->"Buzz", 3*5->"Fizz Buzz").withDefault (i => p._1.toString))(p._1)
)
)
)
big
}
def main(args: Array[String]): Unit = {
fizzBuzzMega(30) foreach (i => print(s"$i "))
println
}
}
.PHONY: Application.scala
all: run
Application.class: Application.scala
@scalac Application.scala
clean:
@rm -f *.class
run: Application.class
@scala Application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment