Skip to content

Instantly share code, notes, and snippets.

@mkrajc
Created June 21, 2017 14:15
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 mkrajc/3a1eeee5984e75323dea338a5c96e6c6 to your computer and use it in GitHub Desktop.
Save mkrajc/3a1eeee5984e75323dea338a5c96e6c6 to your computer and use it in GitHub Desktop.
object Pangrams {
import scala.io.StdIn
def main(args: Array[String]): Unit = {
println(isPangram(StdIn.readLine().toLowerCase()))
}
private val pangram = 67108863
def isPangram(s: String): String = {
var i = 0
var bitmask = 0
while (i < s.length) {
bitmask |= charToMask(s.charAt(i))
if (bitmask == pangram) {
return "pangram"
}
i += 1
}
"not pangram"
}
def charToMask(c: Char): Int = if (c >= 'a' && c <= 'z') 1 << (c - 'a') else 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment