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
class FizzBuzz { | |
public static void main(String[] args) { | |
for (int i = 1; i <= 100; i++) { | |
if (i % 3 == 0) { | |
System.out.print("Fizz"); | |
} | |
if (i % 5 == 0) { | |
System.out.print("Buzz"); | |
} | |
if (i % 3 != 0 && i % 5 != 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
class FizzBuzz { | |
public static void main(String[] args) { | |
for (int i = 1; i <= 100; i++) { | |
if (!new Buzz(new Fizz(i)).apply()) { | |
System.out.print(i); | |
} | |
System.out.println(); | |
} | |
} | |
} |
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 test; | |
public class A { | |
protected int i; // ← コンストラクタ起動時にこいつにアクセスすると IllegalAccessError | |
public A(int i) { | |
this.i = i; | |
} | |
} |
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 test; | |
public class A { | |
protected int i; // ← コンストラクタ起動時にこいつにアクセスすると IllegalAccessError | |
public A(int i) { | |
this.i = i; | |
} | |
} |
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 groovyx.gpars.GParsPool | |
GParsPool.withPool { | |
def array = ["+", "-", "*", "/"] | |
def combi = GroovyCollections.combinations((1..2).collectParallel{ array }) // arrayから2つ選びだす順列 | |
println combi //=> [[1, 1], [2, 1], [3, 1], [1, 2], [2, 2], [3, 2], [1, 3], [2, 3], [3, 3]] | |
combi.each { | |
def s = "1" | |
def i = 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
scala> def hashMap[K,V](e:java.util.Map.Entry[K,V]*)={ | |
| e.foldLeft(new java.util.HashMap[K,V]()) { (map, e) => map.put(e.getKey, e.getValue); map } | |
| } | |
hashMap: [K, V](e: java.util.Map.Entry[K,V]*)java.util.HashMap[K,V] | |
scala> def $[K,V](k: K, v: V) = { new java.util.AbstractMap.SimpleEntry(k, v) } | |
$: [K, V](k: K, v: V)java.util.AbstractMap.SimpleEntry[K,V] | |
scala> hashMap($('a, 1), $('b, 2)) | |
res1: java.util.HashMap[Symbol,Int] = {'a=1, 'b=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
scala> def rotate[T](l: List[T], dist: Int) = { | |
| val _dist = (dist + (dist.abs / l.size + 1) * l.size) % l.size | |
| l.drop(_dist) ++ l.take(_dist) | |
| } | |
rotate: [T](l: List[T], dist: Int)List[T] | |
scala> rotate(List(1,2,3,4,5),0) | |
res13: List[Int] = List(1, 2, 3, 4, 5) | |
scala> rotate(List(1,2,3,4,5),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
scala> val v:Long = 3912657840L | |
v: Long = 3912657840 | |
scala> (1 to 9).map { v % _ } | |
res1: scala.collection.immutable.IndexedSeq[Long] = Vector(0, 0, 0, 0, 0, 0, 0, | |
0, 0) | |
scala> val sv = "3912657840" | |
sv: java.lang.String = 3912657840 | |
scala> sv.sliding(2).map { _.toInt }.map { v % _ }.toList | |
res2: List[Long] = List(0, 0, 0, 0, 0, 0, 0, 0, 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
public abstract class AC<T> { | |
protected abstract void cannot_override(T... xs); | |
} |
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
// yield 版 | |
IEnumerable<List<T>> Permutations<T>(IEnumerable<T> seq, int count) | |
{ | |
switch (count) { | |
case 0: // special | |
yield break; | |
case 1: // terminate | |
foreach (var t in seq) | |
yield return t; | |
yield break; |