all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
25
Task/Soundex/Scala/soundex-1.scala
Normal file
25
Task/Soundex/Scala/soundex-1.scala
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
def soundex(s:String)={
|
||||
var code=s.head.toUpper.toString
|
||||
var previous=getCode(code.head)
|
||||
for(ch <- s.drop(1); current=getCode(ch.toUpper)){
|
||||
if (!current.isEmpty && current!=previous)
|
||||
code+=current
|
||||
previous=current
|
||||
}
|
||||
code+="0000"
|
||||
code.slice(0,4)
|
||||
}
|
||||
|
||||
def getCode(c:Char)={
|
||||
val code=Map("1"->List('B','F','P','V'),
|
||||
"2"->List('C','G','J','K','Q','S','X','Z'),
|
||||
"3"->List('D', 'T'),
|
||||
"4"->List('L'),
|
||||
"5"->List('M', 'N'),
|
||||
"6"->List('R'))
|
||||
|
||||
code.find(_._2.exists(_==c)) match {
|
||||
case Some((k,_)) => k
|
||||
case _ => ""
|
||||
}
|
||||
}
|
||||
27
Task/Soundex/Scala/soundex-2.scala
Normal file
27
Task/Soundex/Scala/soundex-2.scala
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
def main(args: Array[String]): Unit = {
|
||||
val tests=Map(
|
||||
"Soundex" -> "S532",
|
||||
"Euler" -> "E460",
|
||||
"Gauss" -> "G200",
|
||||
"Hilbert" -> "H416",
|
||||
"Knuth" -> "K530",
|
||||
"Lloyd" -> "L300",
|
||||
"Lukasiewicz" -> "L222",
|
||||
"Ellery" -> "E460",
|
||||
"Ghosh" -> "G200",
|
||||
"Heilbronn" -> "H416",
|
||||
"Kant" -> "K530",
|
||||
"Ladd" -> "L300",
|
||||
"Lissajous" -> "L222",
|
||||
"Wheaton" -> "W350",
|
||||
"Ashcraft" -> "A226",
|
||||
"Burroughs" -> "B622",
|
||||
"Burrows" -> "B620",
|
||||
"O'Hara" -> "O600")
|
||||
|
||||
tests.foreach{(v)=>
|
||||
val code=soundex(v._1)
|
||||
val status=if (code==v._2) "OK" else "ERROR"
|
||||
printf("Name: %-20s Code: %s Found: %s - %s\n", v._1, v._2, code, status)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue