Skip to content

Instantly share code, notes, and snippets.

@arlandism
arlandism / counting.clj
Created May 28, 2013 16:18
Element Counting in Clojure
(defn element-counting [coll]
(loop [mapping {} coll coll]
(if (empty? coll)
mapping
(let [x (mapping (first coll) 0)]
(recur (assoc mapping (first coll) (inc x)) (rest coll))))))
@arlandism
arlandism / frequency.clj
Created May 28, 2013 20:33
Code Comparison
(defn frequency
([mapping x]
(assoc mapping x (inc (mapping x 0))))
([x]
(let [mapping (hash-map)]
(assoc mapping x (inc (mapping x 0))))))
;;Below code works
(defn addtomap [map string]
(assoc map string (inc (map string 0))))
@arlandism
arlandism / prime-factor.clj
Created May 29, 2013 14:54
Prime Factor function in Clojure
(defn prime-factors [n]
(loop [n n factors '() divisor 2]
(if (< n 2)
factors
(if (zero? (mod n divisor))
(recur (/ n divisor) (conj factors divisor) divisor)
(recur n factors (inc divisor))))))
@arlandism
arlandism / gist:5952822
Created July 8, 2013 21:54
Was thinking something like this...
class UserInterface(object):
# To insert fake scenario selector and fake prompter to test information flow
def __init__(self,display_object,input_object,scenario_selector,prompter):
self.display_object = display_object
self.input_object = input_object
self.selector = scenario_selector
self.prompter = prompter
@arlandism
arlandism / gist:5995116
Last active December 19, 2015 17:59
Trying to test-drive
class GameBuilder(object):
@staticmethod
def return_game(user_data):
parser = PromptParser(user_data)
player_one = PlayerFactory(parser.player_one(),parser.first_token())
player_two = PlayerFactory(parser.player_two(),parser.second_token())
board_size = parser.board_size()
return Game(player_one,player_two,BaseBoard(board_size))
@arlandism
arlandism / .gitignore_global
Created August 6, 2013 00:42
My .gitignore_global
*.pyc
*.swp
.DS_STORE
.coverage
@arlandism
arlandism / .vimrc
Created August 26, 2013 14:47
Lines 16 - 19 plus 23 relate to RainbowParentheses
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
set background=light
syntax on
syntax enable
colorscheme solarized
nmap <S-E> O<Esc>
map <F2> :NERDTreeToggle<CR>
set t_Co=256
set scrolloff=3
# old
post '/move' do
move = params[:player_move]
response.set_cookie(move, "x")
human_move = {move => "x"}
board_state = Helpers.add_hashes(request.cookies, human_move)
game_info = Helpers.call_ai(AI.new, {"board"=> board_state})
comp_move = Helpers.ai_move(game_info)
response.set_cookie(comp_move,"o")
set_winner_if_exists(response,game_info)
@arlandism
arlandism / .vimrc
Created September 13, 2013 20:22
My .vimrc file
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
set background=light
syntax on
syntax enable
colorscheme Tomorrow-Night-Eighties
nmap <S-E> O<Esc>
map <F2> :NERDTreeToggle<CR>
set t_Co=256
set scrolloff=3
(describe "other-bodies"
(it "excludes the body we're looking for"
(should= [1 2] (other-bodies 3 [1 2 3]))))
(defn other-bodies [the-body all-bodies]
(filter
#(not (= the-body))
all-bodies))