Skip to content

Instantly share code, notes, and snippets.

View fupfin's full-sized avatar

Sungchul Park fupfin

  • Woowahan Bros.
  • Seoul, South Korea
View GitHub Profile
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) {
package com.fupfin.groovybase64
import java.nio.ByteBuffer
class Base64 {
static RAW_CHUNK_SIZE = 3
static ENC_CHUNK_SIZE = 4
static encChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes()
@fupfin
fupfin / MinSumCombination.scala
Created December 8, 2014 12:09
최소값 조합 찾기
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
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) {
(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)))
))
@fupfin
fupfin / Schwartz.java
Last active August 29, 2015 14:12
Schwartz Transform Java 8 Version
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()
@fupfin
fupfin / MapBuilder.java
Created June 16, 2015 11:31
Simple map builder for java using Tuple class I've made before (https://gist.github.com/fupfin/2299564)
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>();
@fupfin
fupfin / Option.java
Created October 5, 2011 06:52
java version of scala Option
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
@fupfin
fupfin / Tuples.java
Created April 4, 2012 07:52
Scala's tuple implmentation for Java
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);
}
@fupfin
fupfin / AbstractArrayRotator.java
Created September 7, 2012 10:22
‘문제로 풀어보는 알고리즘 0.3 생각해보기 풀이’
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);