Skip to content

Instantly share code, notes, and snippets.

@tyamagu2
tyamagu2 / gomoku.go
Created February 24, 2016 10:04
Go Moku Narabe
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var N, M = 19, 5
@tyamagu2
tyamagu2 / reversi.rb
Last active December 15, 2015 12:17
reversi
class Board
def initialize(size = 8)
@size = size
@board = []
@size.times do
row = []
@size.times { row << :none }
@board << row
end
(define atom?
(lambda (x)
(and (not (pair? x)) (not (null? x)))))
(define add1 (lambda (n) (+ n 1)))
(define sub1 (lambda (n) (- n 1)))
(define first car)
@tyamagu2
tyamagu2 / project_euler.hs
Last active August 29, 2015 14:22
project_euler
-- 1. Find the sum of all the multiples of 3 or 5 below 1000.
sum [ x | x <- [1..999], x `mod` 3 == 0 || x `mod` 5 == 0 ]
-- 2. By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
let p2 = sum [ x | x <- takeWhile (< 4000000) fibs, even x] where fibs = 1 : 2 : zipWith (+) fibs (tail fibs)
@tyamagu2
tyamagu2 / project_euler.ex
Last active August 29, 2015 14:22
project_euler
# 1. Find the sum of all the multiples of 3 or 5 below 1000.
1..999 |> Enum.filter(&(rem(&1, 3) == 0 || rem(&1, 5) == 0)) |> Enum.reduce(&+/2)
# 2. By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
Stream.unfold({1, 2}, fn {n1, n2} -> {n1, {n2, n1 + n2}} end) |> Stream.filter(&(rem(&1, 2) == 0)) |> Enum.take_while(&(&1 < 4000_000)) |> Enum.reduce(&+/2)
@tyamagu2
tyamagu2 / gist:b8c9344d6280339248ab
Last active August 29, 2015 14:13
神奈川Ruby会議01
# http://nabetani.sakura.ne.jp/kanagawa.rb/evalex/
def evaluate(str)
%w(| & + *).each_with_object(str.dup) { |op, e| while e.sub!(/\d+#{Regexp.escape(op)}\d+/) { |s| eval(s) }; end }
end
[
[ 0, "4*5+6&7|8", "44" ],
[ 1, "15*5", "75" ],
[ 2, "15+5", "20" ],