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
// //src/main/scala/Main.scala | |
package hoge | |
case class Main(index: Int, name: String){ | |
lazy val ps: Stream[Int] = 2 #:: Stream.from(3).filter(i => | |
ps.takeWhile(j => j*j <= i).forall(i%_ != 0)) | |
def isPrime(n: Int): Boolean = Iterator.from(2).takeWhile(i => | |
i*i <= n).forall(n%_ != 0) | |
} |
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
package sony | |
import java.util.Calendar | |
/** | |
* Birth | |
* | |
* @constructor create a new birth date | |
* @param birthYear the year of birth | |
* @param birthMonth the month of birth | |
* @param birthDay the day of birth |
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
package sony | |
/** | |
* Factorial | |
* add the methods for factorial | |
* | |
*/ | |
trait Factorial{ | |
def fact(n: Int) = (1 to n).foldLeft(1)(_*_) | |
def fact(d: Double) = if (d > 0) factPositive(d) else factNegative(d) |
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
import scala.io.Source | |
import scala.annotation.tailrec | |
case class Node(connects: List[(Int, Int)], var value: Int = Int.MaxValue) | |
class Dijcstra(file: String) { | |
val lines = Source.fromFile(file).getLines | |
val adacent = lines map { n => n.replace(" ", "").split(',').toList map { _.toInt } } | |
val nodes = (for (ad <- adacent) yield Node(ad.zipWithIndex filter { _._1 != 0 })).toArray | |
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
// http://acm.pku.edu.cn/JudgeOnline/problem?id=1978 | |
package icpc | |
import java.util.Scanner | |
import scala.annotation.tailrec | |
class Hanafuda(sc: Scanner) { | |
def start(): Unit = { | |
@tailrec | |
def shuffle(cards: List[Int], r: Int) : List[Int] = { | |
if (r == 0) cards |
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
// http://acm.pku.edu.cn/JudgeOnline/problem?id=2683 | |
package icpc | |
import java.util.Scanner | |
import scala.annotation.tailrec | |
case class Deposit(first: Int, way: Int, rate: Double, fee:Int){ | |
def predict(year: Int): Int = way match { | |
case 0 => simpleR(first, year, 0) | |
case 1 => compoundR(first, year) | |
case _ => throw new IllegalArgumentException |
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
// http://www.deqnotes.net/acmicpc/p0003/judge | |
package icpc | |
import java.util.Scanner | |
class Keitai(sc: Scanner){ | |
val sm = Map(1 -> " .,!?", 2 -> "cab", 3 -> "fde", 4 -> "igh", | |
5 -> "ljk", 6 -> "omn", 7 -> "spqr", 8 -> "vtu", 9 -> "zwxy") | |
def start(c: Int): Unit = { | |
def convert(n: String): Char = sm.get(n.head.toString.toInt) match { | |
case Some(v) => v(n.length%v.length) |
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
// http://www.deqnotes.net/acmicpc/p0004/judge | |
package icpc | |
import java.util.Scanner | |
import scala.annotation.tailrec | |
class ExploringCaves(sc: Scanner) { | |
def findTreasure(routes: List[(Int, Int)]) = routes.sortBy(n => (n._1*n._1 + n._2*n._2)).last | |
def search(start: (Int, Int)): (Int, Int) = { | |
@tailrec |
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
// http://acm.pku.edu.cn/JudgeOnline/problem?id=2028 | |
// 配列のindexなどの使い方がいまいち分からない. | |
package icpc | |
import java.util.Scanner | |
class Meeting(sc: Scanner){ | |
def adjust(n: Int, q: Int): Int = { | |
val dates = Array.tabulate(101)(n => 0) | |
for (i <- 1 to n) { | |
val c = sc.nextInt |
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
// http://www.deqnotes.net/acmicpc/p0006/judge | |
package icpc | |
import java.util.Scanner | |
class Purse(sc: Scanner){ | |
def solve(amount: Int, own: Int): (Int, Int, Int, Int) = { | |
val diff = own - amount | |
(diff%500%100%50/10, diff%500%100/50, diff%500/100, diff/500) | |
} | |