Skip to content

Instantly share code, notes, and snippets.

View jooyunghan's full-sized avatar

Jooyung Han jooyunghan

View GitHub Profile
import qualified Data.Map as M
-- Cell
data Cell = Cross | Naught | Empty deriving (Eq, Show)
to_char Cross = 'X'
to_char Naught = 'O'
to_char Empty = '.'
to_int Cross = 2
int[][] data = new int[3][3];
private void aiMove() {
Score s = minimax(null, true);
data[s.move.x][s.move.y] = COMPUTER;
}
static class Score {
Point move;
int score;
@jooyunghan
jooyunghan / markov.hs
Created July 18, 2014 15:39
Random text generation (The Practice of Programming)
import Data.Map
import System.Random
group assoc = fromListWith (++) [(k,[v]) | (k,v) <- assoc]
mapChooseRandom g = zipWith chooseRandom (randoms g)
chooseRandom r list = list !! (r `mod` (length list))
learn str = group $ zip prefices suffices
where prefices = zip w (tail w)
@jooyunghan
jooyunghan / Markov.java
Created July 18, 2014 13:49
Random text generation example (The Practice of Programming)
import java.util.*;
public class Markov {
final static int MAX = 100;
public static void main(String[] args) {
Map<List<String>,List<String>> map = new HashMap<>();
List<String> prefix = Arrays.asList("", "");
@jooyunghan
jooyunghan / Main.java
Created July 14, 2014 09:09
Retrofit + RxJava in Java
package com.company;
import retrofit.RestAdapter;
import retrofit.http.GET;
import retrofit.http.Path;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.functions.Func2;
@jooyunghan
jooyunghan / trie.cpp
Created October 30, 2013 13:59
trie initial
class trie {
int count;
unordered_map<char, trie> children;
int& get(const char* s) {
if (*s == '\0') {
return count;
} else {
return children[*s].get(s+1);
}
@jooyunghan
jooyunghan / mine.cpp
Created May 24, 2013 02:46
DevDay MineSweeper Part 1
#include <iostream>
using namespace std;
const char CLOSED = '#';
const char MINE = '*';
const char EMPTY = '-';
const int row = 2;
const int col = 6;
char input[row][col] = {
@jooyunghan
jooyunghan / Main.java
Created September 19, 2012 05:01
Main.java
package com.jooyunghan.concurrency;
import static java.lang.String.format;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class Message {
@jooyunghan
jooyunghan / concurrency_idioms.go
Created May 12, 2012 15:48
DevFestX Korea 2012 - Go concurrency idioms
package main
import (
"fmt"
"time"
)
type Data struct {
data string
rq1, rq2, rs1, rs2 chan bool
@jooyunghan
jooyunghan / about.md
Created August 29, 2011 08:11 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer