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.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; |
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.*; | |
| 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("", ""); |
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 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) |
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
| 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; |
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 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 |
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 |
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
| 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
| 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
| 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) { |