Skip to content

Instantly share code, notes, and snippets.

Last active November 8, 2015 21:51
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Classic program that prints strings based on results of using MOD function against a List
Write a program that prints out the numbers 1 to 100 (inclusive).
If the number is divisible by 3, print Crackle instead of the number.
If it's divisible by 5, print Pop. If it's divisible by both 3 and 5,
print CracklePop. You can use any language.
/// any number x where x % y is divisible by that number. We'll use that fact to match boolean patterns in Scala.
//// In Scala RePL, copy-paste the function first. Then use the function in a second call from the REPL.
def listEval( number: Int ): String = (number % 3, number % 5 ) match {
case( 0, 0 ) => "CracklePOP"
case(0, _ ) => "Crackle"
case( _, 0) => "Pop"
case _ => number.toString()
val myList = (1 to 100) map {listEval(_)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment