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 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; |
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
@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" + |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Functional Flappy</title> | |
</head> | |
<style type="text/css"> | |
#playground { | |
width: 500px; | |
height: 500px; | |
border: 1px solid red; |
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 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; |
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
-- 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" |
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
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) { |
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 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; |
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 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)) |
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 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 |
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
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 |