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
コレが中身。 |
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 java.util.List; | |
import java.util.ArrayList; | |
import java.util.Set; | |
import java.util.HashSet; | |
import java.util.Collections; | |
public class Exercise { | |
public static void main(String[] args) { | |
List<Integer> nums = new ArrayList<>(); | |
for (String str : args) |
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 SortWords { | |
def main(args: Array[String]): Unit = { | |
val list = args.toList sort (_ > _) | |
val foldList = (List((1, list.head)) /: list.tail) { | |
case (x, y) if (x.head._2 == y) => (x.head._1 + 1, x.head._2) :: x.tail | |
case (x, y) => (1, y) :: x | |
} | |
val result = foldList sort ((a, b) => a._1 > b._1 || a._1 == b._1 && a._2 < b._2) map (_._2) | |
println(result) |
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
package exercise; | |
import java.util.Comparator; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
import java.util.SortedSet; | |
import java.util.TreeSet; | |
public class SortWordsJ { |
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 java.util.ArrayList; | |
import java.util.List; | |
public class PythagoraSwitch { | |
public static void main(String[] args) { | |
final int MAX = Integer.parseInt(args[0]); | |
long start = System.nanoTime(); | |
List<PythagorasNum> result = new ArrayList<>(); | |
for (int c = 3; c <= MAX; c += 2) { |
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 java.util.ArrayList; | |
import java.util.List; | |
public class PythagoraSwitch2 { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
final int MAX = Integer.parseInt(args[0]); |
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 math._ | |
object PythagoraSwitch { | |
def main(args: Array[String]): Unit = { | |
val max = Integer.parseInt(args(0)) | |
val start = System.nanoTime() | |
/* | |
val result = for ( | |
c <- 3 to max by 2; |
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 MapBetween { | |
def main(args:Array[String]) = { | |
val range = 1 to 10 | |
println(mapBetween(range, (a1:Int,a2:Int)=>a1+a2)) | |
println(mapBetween(range, (a1:Int,a2:Int)=>a1*a2)) | |
println(mapBetween(range, (a1:Int,a2:Int)=>a1-a2)) | |
} | |
def mapBetween[A,B,T>:A](seq:Seq[A], f:(T,T)=>B): Seq[B] = { | |
((Seq[B](), seq.head) /: seq.tail) {(tup:(Seq[B], A), a:A) => (tup._1 :+ f(tup._2, a), a)}._1 |
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 mapBetween2 { | |
def main(args:Array[String]) = { | |
val range = 1 to 10 | |
println(mapBetween(range)(_+_) mkString ",") | |
println(mapBetween(range)(_*_) mkString ",") | |
println(mapBetween(range)(_-_) mkString ",") | |
} | |
def mapBetween[A,B,T>:A](seq:Seq[A])(f:(T,T)=>B): Iterator[B] = { | |
seq.sliding(2).map(s=>f(s(0),s(1))) |
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 mapBetween { | |
def main(args:Array[String]) = { | |
val range = new Range(1, 10, 1) with ExtSeq[Int] | |
println(range.mapBetween(_+_) mkString ",") | |
println(range.mapBetween(_*_) mkString ",") | |
println(range.mapBetween(_-_) mkString ",") | |
val range2 = 1 to 10 | |
println(range2.mapBetween(_+_) mkString ",") | |
println(range2.mapBetween(_*_) mkString ",") |
OlderNewer