yuin #2317(2007/08/18 15:48 GMT) [ Scala ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import scala.util.Sorting.stableSort def bingo(n:int) = { type PList = List[Pair[int,int]] val lst = stableSort[int,double](1 to n,x=>Math.random).zipWithIndex.toList val w = lst.size.toString.size+1 def format(n:int) = String.format("%"+w+"d",Array(n.asInstanceOf[AnyRef])) def printline(x:PList) = { println(x.map(y=>format(y._2+1)).mkString("")) println(x.map(y=>format(y._1)).mkString("")+"\n") } def show(l:PList):unit = l.splitAt(10) match { case (l,Nil) => printline(l) case (l,ls) => printline(l);show(ls) } show(lst) } bingo(30) bingo(35)
Rating0/0=0.00-0+
[ reply ]
yuin
#2317()
[
Scala
]
Rating0/0=0.00
import scala.util.Sorting.stableSort def bingo(n:int) = { type PList = List[Pair[int,int]] val lst = stableSort[int,double](1 to n,x=>Math.random).zipWithIndex.toList val w = lst.size.toString.size+1 def format(n:int) = String.format("%"+w+"d",Array(n.asInstanceOf[AnyRef])) def printline(x:PList) = { println(x.map(y=>format(y._2+1)).mkString("")) println(x.map(y=>format(y._1)).mkString("")+"\n") } def show(l:PList):unit = l.splitAt(10) match { case (l,Nil) => printline(l) case (l,ls) => printline(l);show(ls) } show(lst) } bingo(30) bingo(35)Rating0/0=0.00-0+
[ reply ]