Skip to content

Instantly share code, notes, and snippets.

@hpoit
hpoit / go board
Created January 9, 2018 15:48
go board
CellToolbar
In [3]:
abstract type Stone end
struct Empty <: Stone end
struct Black <: Stone end
struct White <: Stone end
Base.show(io::IO, ::Black) = print(io, "⚈")
@hpoit
hpoit / cormullion.jl
Last active January 9, 2018 16:59
go board
abstract type Stone end
struct Empty <: Stone end
struct Black <: Stone end
struct White <: Stone end
Base.show(io::IO, ::Black) = print(io, "⚈")
Base.show(io::IO, ::White) = print(io, "⚆")
Base.show(io::IO, ::Empty) = print(io, "·")
@hpoit
hpoit / temp1
Created January 10, 2018 14:01
temp1
julia> abstract type Stone end
julia> struct Empty <: Stone end
julia> struct Black <: Stone end
julia> struct White <: Stone end
julia> Base.show(io::IO, ::Black) = print(io, "⚈")
julia> Base.show(io::IO, ::White) = print(io, "⚆")
julia> Base.show(io::IO, ::Empty) = print(io, "·")
@hpoit
hpoit / react beginner tutorial go
Created January 11, 2018 20:45
Game logic for the board game Go
/*
* board.js - Game logic for the board game Go
*/
var Board = function(size) {
this.current_color = Board.BLACK;
this.size = size;
this.board = this.create_board(size);
this.last_move_passed = false;
this.in_atari = false;
this.attempted_suicide = false;
@hpoit
hpoit / onREPL
Created January 12, 2018 15:48
running on REPL
Last login: Fri Jan 12 13:47:11 on ttys000
Kevins-MBP:~ Corvus$ exec '/Applications/Julia-0.6.app/Contents/Resources/julia/bin/julia'
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.0 (2017-06-19 13:05 UTC)
_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-apple-darwin13.4.0
@hpoit
hpoit / Weiqi1_milestone.jl
Last active February 8, 2018 01:11
Weiqi1 - milestone
julia> abstract type Stone end
julia> struct Black <: Stone end
julia> struct White <: Stone end
julia> abstract type Emptiness end
julia> struct Empty <: Emptiness end
# julia> Base.show(io::IO, ::Empty) = print(io, "·")
# julia> Base.show(io::IO, ::Black) = print(io, "⚈")
# julia> Base.show(io::IO, ::White) = print(io, "⚆")
@hpoit
hpoit / Weiqi2.jl
Last active March 5, 2018 15:13
Weiqi2 - 2nd milestone, thanks to MEastwood at Caltech - func neighbors complete and now func liberties complete!
julia> abstract type Stone end
julia> struct Black <: Stone end
julia> struct White <: Stone end
julia> abstract type Emptiness end
julia> struct Empty <: Emptiness end
julia> Base.show(io::IO, ::Empty) = print(io, "·")
julia> Base.show(io::IO, ::Black) = print(io, "⚈")
julia> Base.show(io::IO, ::White) = print(io, "⚆")
@hpoit
hpoit / Cormen_123.jl
Last active February 26, 2018 23:42
Cormen 1.2.3
julia> i = 1;
julia> runningtime1 = 100i^2;
julia> runningtime2 = 2^i;
julia> while true # is a loop that never terminates, unless there's a break
println(i)
if runningtime1 < runningtime2 # if condition is true, break
break
@hpoit
hpoit / Cormen_122.jl
Last active February 27, 2018 14:33
Cormen 1.2.2
# for n = 1, `log(2, 1) = 0`, making merge time equal 0
# start with n = 2
julia> n = 2;
julia> insertiontime = 8*n^2;
julia> mergetime = 64*n*log(2,n);
julia> while true
@hpoit
hpoit / Cormen_232.jl
Last active March 13, 2018 22:49
Cormen_232 - sort and merge
https://rosettacode.org/wiki/Sorting_algorithms/Merge_sort#Julia
julia> function mergesort(arr::Vector)
if length(arr) ≤ 1 return arr end
mid = length(arr) ÷ 2
lpart = mergesort(arr[1:mid])
rpart = mergesort(arr[mid+1:end])
rst = similar(arr)
i = ri = li = 1
@inbounds while li ≤ length(lpart) && ri ≤ length(rpart)