Skip to content

Instantly share code, notes, and snippets.

@parambirs
Created September 6, 2015 01:31
Show Gist options
  • Save parambirs/9d713d6c283072038c27 to your computer and use it in GitHub Desktop.
Save parambirs/9d713d6c283072038c27 to your computer and use it in GitHub Desktop.
#!/usr/bin/env scala
import scala.collection.immutable.IndexedSeq
import scala.io.StdIn
val version = "Scala Insult Generator v0.1"
val cmdArg = if(args.length > 0) Some(args(0).toUpperCase) else None
val result = cmdArg match {
case Some("-H") => "Usage: ./insult.scala [INSULT WORD]"
case Some("-V") => version
case Some(insult) => getInsult(insult)
case None => getInsult(askUserForInsult)
}
println(result)
def askUserForInsult =
StdIn.readLine("Please enter your insult word: ")
def spaced(str: IndexedSeq[Char]) = str.mkString(" ")
def getInsult(insult: IndexedSeq[Char]) = {
val alphabets = 'A' to 'Z'
val heading = alphabets filterNot (insult contains(_))
s"""
| ${spaced(heading)}
|
| "You must be wondering what happened to the rest of the letters"
|
|
|
| "They are written below"
|
|
|
|
|
|
|
| .
| .
| .
|
|
| ${spaced(insult)}
|
| [$version]
""".stripMargin
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment