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 static java.lang.System.out; | |
import com.google.code.jyield.*; | |
public class GeneratorDemo { | |
public static void main(String args[]) { | |
for(int n: YieldUtils.toIterable(take(25, sequenceOf(integers())))) | |
out.println(n); | |
} | |
public static Generator<Integer> take(int count, Generator<Integer> source) { |
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 com.fupfin.groovybase64 | |
import java.nio.ByteBuffer | |
class Base64 { | |
static RAW_CHUNK_SIZE = 3 | |
static ENC_CHUNK_SIZE = 4 | |
static encChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes() |
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
object MinSumCombination { | |
def findMin(nums: Array[Int]): Int = { | |
val result = tryCombinations(nums, 0) | |
if (result < Int.MaxValue) result else -1 | |
} | |
private def tryCombinations(nums: Array[Int], fixPos:Int): Int = { | |
//println((nums).mkString(",")) | |
if(fixPos >= nums.length - 1) Int.MaxValue |
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
public class ChangeCounter { | |
int cents[] = { 50, 25, 10, 5, 1 }; | |
public int count(int amount) { | |
return count(amount, 0); | |
} | |
private int count(int amount, int idx) { | |
if (amount == 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
(defn count-change-for-us [amount] (count-change amount [1 5 10 25 50])) | |
(defn count-change [amount coins] | |
(cond (= amount 0) 1 | |
(< amount 0) 0 | |
(empty? coins) 0 | |
:else (+ (count-change (- amount (first coins)) coins) | |
(count-change amount (rest coins))) | |
)) |
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 java.util.List; | |
import java.util.function.Function; | |
import java.util.stream.Collectors; | |
import org.javatuples.*; | |
public class Schwartz { | |
public static <T> List<T> transform(List<T> list, Function<T, Integer>fn) { | |
return list.stream() |
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 fupfin; | |
import static fupfin.Tuples.*; | |
import java.util.*; | |
import java.util.concurrent.ConcurrentHashMap; | |
public class MapBuilder<K, V> { | |
private Map<K, V> map = new ConcurrentHashMap<K, V>(); |
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 fupfin; | |
import java.util.NoSuchElementException; | |
/** | |
* A base class of simple value container that represents optional values. You can | |
* use subclass Some<A> for some existent values or None for non existent values. | |
* This is java version of scala Option class. | |
* | |
* @author fupfin@gmail.com |
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 fupfin; | |
public class Tuples { | |
private Tuples() {} | |
public static <T1, T2> Tuple2<T1, T2> tuple(T1 v1, T2 v2) { | |
return new Tuple2<T1, T2>(v1, v2); | |
} |
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 org.fupfin.insight.event1; | |
import java.lang.reflect.Array; | |
public abstract class AbstractArrayRotator<T> implements ArrayRotator<T>{ | |
@Override | |
public T[] rotateRight(T[] source, int step) { | |
if(isValidArguments(source, step)) | |
throw new IllegalArgumentException("step value have to be not negative number : " + step); |
OlderNewer