This file contains hidden or 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 NumberText1 { | |
| val u = Map( | |
| 1 -> "one", 2 -> "two", 3 -> "three", 4 -> "four", 5 -> "five", | |
| 6 -> "six", 7 -> "seven", 8 -> "eight", 9 -> "nine", 10 -> "ten", | |
| 11 -> "eleven", 12 -> "twelve", 13 -> "thirteen", 14 -> "fourteen", 15 -> "fifteen", | |
| 16 -> "sixteen", 17 -> "seventeen", 18 -> "eighteen", 19 -> "nineteen" | |
| ) | |
| val t = Map( | |
| 2 -> "twenty", 3 -> "thirty", 4 -> "forty", 5 -> "fifty", |
This file contains hidden or 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 Z{ | |
| val z="teen";val k=1000;val t=""::""::"twenty"::"thirty"::"forty"::"fifty"::"sixty"::"seventy"::"eighty"::"ninety"::Nil | |
| val u=""::"one"::"two"::"three"::"four"::"five"::"six"::"seven"::"eight"::"nine"::"ten"::"eleven"::"twelve"::"thir"+z::"four"+z::"fif"+z::"six"+z::"seven"+z::"eight"+z::"nine"+z::Nil | |
| def c(n:Int)={def c(n:Int,x:String*):String={if(n>0){val m=n%k;val r=m%100;val s=if(r<20)u(r)else t(r/10)+(if(u(r%10)=="")""else" "+u(r%10)) | |
| val h=if(m/100>0)u(m/100)+" hundred "else"";val j=if(h=="")s else h+(if(s=="")""else"and ")+s;c(n/k,x.tail:_*)+j+(if(j=="")""else x.head)}else""} | |
| if(n>0){val f=c((n/k)*k,""," thousand "," million "," billion ");val r=c(n%k,"");f+(if(f==""||n%k>99)r else(if(r.isEmpty)""else"and "+r))}else"zero"} | |
| def main(x:Array[String]):Unit={println(c(10201))}} |
This file contains hidden or 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
| import Rank.{ _ } | |
| import Suit.{ _ } | |
| class Rank(val faceValues: Int*) { | |
| def of(suit: Suit) = Card(this, suit) | |
| } | |
| object Rank { | |
| case object Ace extends Rank(1, 11) | |
| case object Two extends Rank(2) | |
| case object Three extends Rank(3) |
This file contains hidden or 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
| import scala.util.Random | |
| trait Shuffle { | |
| var cards: List[Card] | |
| lazy val random = new Random | |
| def shuffle { | |
| def shuffle(cards: List[Card], size: Int, pile: List[Card] = Nil): List[Card] = { | |
| if (size > 0) { | |
| val card = cards(random.nextInt(size)) | |
| val (bef, aft) = cards.span(_ != card) |
This file contains hidden or 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
| trait Shuffle { | |
| var cards: List[Card] | |
| def next = { | |
| if (!cards.isEmpty) { | |
| val card = cards.head | |
| cards = cards.tail | |
| Some(card) | |
| } else None | |
| } | |
| lazy val random = new scala.util.Random |
This file contains hidden or 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
| abstract class Hand { | |
| val cards: Seq[Card] | |
| def +(card: Card): Hand | |
| def split: List[Hand] | |
| lazy val scores = { | |
| def combinations(cards: Seq[Card]): List[Seq[Int]] = { | |
| if (!cards.isEmpty) { | |
| for (c ← combinations(cards.tail); v ← cards.head.rank.faceValues) yield v +: c | |
| } else List(Nil) | |
| } |
This file contains hidden or 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
| import scala.actors.remote.RemoteActor.select | |
| import scala.actors.remote.Node | |
| import scala.actors.Actor | |
| object Reader { | |
| def main(args: Array[String]) { | |
| println("Reader running") | |
| val actor = new Actor { | |
| def act() { |
This file contains hidden or 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
| import scala.actors.Actor.self | |
| import scala.actors.remote.RemoteActor.{ select, register, alive } | |
| import scala.actors.remote.Node | |
| import scala.actors.Actor | |
| import scala.collection.mutable.Map | |
| import NumberText1.conv | |
| object Mapper { | |
| def main(args: Array[String]) { |
This file contains hidden or 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
| import scala.actors.Actor.self | |
| import scala.actors.remote.RemoteActor.{ register, alive } | |
| import scala.actors.Actor | |
| import scala.collection.immutable.TreeMap | |
| import scala.collection.mutable.Map | |
| object Reducer { | |
| def main(args: Array[String]) { | |
| println("Reducer running") |
This file contains hidden or 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
| /** | |
| * @see http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html | |
| */ | |
| private BufferedImage scale(BufferedImage image, int width, int height, int smoothingSteps) { | |
| int w = image.getWidth(); | |
| int h = image.getHeight(); | |
| int targetH, targetW; | |
| if (w > h) { | |
| targetW = width; |
OlderNewer