Skip to content

Instantly share code, notes, and snippets.

View jooyunghan's full-sized avatar

Jooyung Han jooyunghan

View GitHub Profile
@jooyunghan
jooyunghan / FunctionalJavaExample.java
Created May 12, 2015 20:51
Some examples using FunctionalJava
package com.jooyunghan;
import fj.P2;
import fj.data.List;
import fj.data.Stream;
import static fj.P.p;
import static fj.Show.*;
import static fj.data.List.list;
import static fj.data.Stream.iterate;
@jooyunghan
jooyunghan / minimal fp
Created April 23, 2015 17:41
solve euler project #18
@Test
public void no18_2() throws Exception {
String input = "75\n" +
"95 64\n" +
"17 47 82\n" +
"18 35 87 10\n" +
"20 04 82 47 65\n" +
"19 01 23 75 03 34\n" +
"88 02 77 73 07 63 67\n" +
"99 65 04 28 06 16 70 92\n" +
@jooyunghan
jooyunghan / flappy.html
Created March 30, 2015 08:40
Functional Flappy v1
<!DOCTYPE html>
<html>
<head>
<title>Functional Flappy</title>
</head>
<style type="text/css">
#playground {
width: 500px;
height: 500px;
border: 1px solid red;
@jooyunghan
jooyunghan / SeminarTest.java
Created March 26, 2015 04:06
TotallyLazy exercises with problems on Project Euler
import com.googlecode.totallylazy.Sequence;
import com.googlecode.totallylazy.Strings;
import com.googlecode.totallylazy.numbers.Integers;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static com.googlecode.totallylazy.Pair.functions.first;
import static com.googlecode.totallylazy.Pair.pair;
-- euler67
-- input file: https://projecteuler.net/project/resources/p067_triangle.txt
readInput = map (map read . words) . lines
solve = foldr1 merge
where merge xs ys = zipWith (+) xs $ zipWith max ys (tail ys)
main = do
content <- readFile "p067_triangle.txt"
@jooyunghan
jooyunghan / gist:7497419caaca7e579357
Created March 13, 2015 09:53
GitHub Repo Searches
var _ = require('lodash');
var github = require('octonode');
var Rx = require('rx');
// repos :: Search -> Options -> Observable Data
// callback style is converted to Promise and then to Observable
function repos(search, options) {
return Rx.Observable.fromPromise(new Promise(function (resolve, reject) {
search.repos(options, function (err, body, header) {
@jooyunghan
jooyunghan / RoseTree.java
Created February 23, 2015 16:22
An example for RoseTree in Java 8
import java.util.List;
import java.util.Arrays;
public class RoseTree<T> {
private final T value;
private final List<RoseTree<T>> children;
public RoseTree(T value, List<RoseTree<T>> children) {
this.value = value;
this.children = children;
import scala.collection.mutable.ListBuffer
object ListExercises {
object SetA {
// Exercise 1. print all names in list
def printAllNames = {
val names = IndexedSeq("Ben", "Jafar", "Matt", "Priya", "Brian")
for (i <- 0 until names.length) {
println(names(i))
@jooyunghan
jooyunghan / AlphaBetaImperative.scala
Created August 5, 2014 09:01
Minimax with Alpha-beta Pruning
class AlphaBetaImperative extends Evaluator {
override def evaluate(tree: Tree): Int = alphabeta(tree, Int.MinValue, Int.MaxValue, true)
def alphabeta(tree: Tree, alpha: Int, beta: Int, maximizing: Boolean): Int = {
tree match {
case leaf @ Leaf(_) => staticEval(leaf)
case node @ Node(subs) =>
if (maximizing) {
var a = alpha
@jooyunghan
jooyunghan / Minimax.hs
Created August 1, 2014 23:17
Haskell port of Tic-Tac-Toe example in 'Why Functional Programming Matters'
module Minimax (aimove) where
import Tree
-- Find value for max key from assoc list
maxkey :: (Ord k) => [(k, v)] -> v
maxkey = snd . foldl1 (\(k1,v1) (k2,v2) -> if k1 > k2 then (k1,v1) else (k2,v2))
max' :: (Ord a) => [a] -> a
max' = foldl1 max