This file contains 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
(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)))))) | |
This file contains 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
(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)))) |
This file contains 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
(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)))))) |
This file contains 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 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 | |
This file contains 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 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)) |
This file contains 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
*.pyc | |
*.swp | |
.DS_STORE | |
.coverage |
This file contains 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
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 |
This file contains 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
# 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) |
This file contains 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
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 |
This file contains 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
(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)) |
OlderNewer