Created
June 21, 2017 14:15
-
-
Save mkrajc/3a1eeee5984e75323dea338a5c96e6c6 to your computer and use it in GitHub Desktop.
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
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