Skip to content

Instantly share code, notes, and snippets.

Sungchul Park fupfin

Block or report user

Report or block fupfin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View HashCodeFunctions.java
import java.util.Arrays;
public class HashCodeFunctions
{
private final static short DEFAULT_PRIME_NUMBER = 31;
private HashCodeFunctions()
{
throw new AssertionError("Could not be instantiated.");
}
@fupfin
fupfin / MapBuilder.java
Created Jun 16, 2015
Simple map builder for java using Tuple class I've made before (https://gist.github.com/fupfin/2299564)
View MapBuilder.java
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 / Schwartz.java
Last active Aug 29, 2015
Schwartz Transform Java 8 Version
View Schwartz.java
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()
View count-change.clj
(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)))
))
View ChangeCounter.java
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) {
View MinSumCombination.scala
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
View Base64.groovy
package com.fupfin.groovybase64
import java.nio.ByteBuffer
class Base64 {
static RAW_CHUNK_SIZE = 3
static ENC_CHUNK_SIZE = 4
static encChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes()
View GeneratorDemo.java
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) {
View pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples</groupId>
<artifactId>myfirstspring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<!-- Generic properties -->
@fupfin
fupfin / Problem2.scala
Last active Dec 16, 2015
오일러 프로젝트 문제 2: http://euler.synap.co.kr/prob_detail.php?id=2 피보나치 수열의 각 항은 바로 앞의 항 두 개를 더한 것이 됩니다. 1과 2로 시작하는 경우 이 수열은 아래와 같습니다. 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... 짝수이면서 4백만 이하인 모든 항을 더하면 얼마가 됩니까?
View Problem2.scala
package com.fupfin.euler.problem2
import scala.collection.immutable.Stream._
import scala.collection.GenIterable
object Problem2 {
def fib(max: Int): Stream[Int] = 1 #:: 2 #:: fib(1, 2, max)
private def fib(v1:Int, v2:Int, max:Int): Stream[Int] = if(v1 + v2 <= max) (v1 + v2) #:: fib(v2, v1 + v2, max) else Empty
def sum(that:GenIterable[Int], p: Int => Boolean): Int = {
You can’t perform that action at this time.