Skip to content

Instantly share code, notes, and snippets.

@haru01
haru01 / gist:2708466
Created May 16, 2012 07:52
bowlinggame
class BowlingGame
attr_reader :rolls
def initialize(rolls)
@rolls = rolls
end
def score
(1..10).reduce([]) { |frame_calc_a, frame_number|
frame_calc_a << rolls[range(frame_number)]
# encoding: utf-8
class BowlingGame
attr_reader :rolls
def initialize(rolls)
@rolls = rolls
end
def score
(1..10).map { |frame_number|
@haru01
haru01 / gist:2907741
Created June 10, 2012 23:43
lifegame
# encoding: utf-8
describe "LifeGame" do
ALIVE = 1
DEAD = 0
subject { Space.new(seed).next_time.status(1,1) }
context "誕生:死んでいるセルに隣接する生きたセルがちょうど3つあれば次世代が誕生する" do
let(:seed) {[ [1,1,0],
[1,0,0],
[0,0,0]]}
@haru01
haru01 / gist:2941177
Created June 16, 2012 12:10
roman_add
class Calc
constructor: ->
@enters = []
enter: (n)->
@enters.push n
add: ->
added = this.roman_to_num(@enters[0]) + this.roman_to_num(@enters[1])
if (added >= 4000)
@haru01
haru01 / gist:3095328
Created July 12, 2012 02:38
LifeGame_Theories
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItems;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.theories.DataPoints;
@haru01
haru01 / gist:3231159
Created August 1, 2012 22:14
if_then_else
# -*- encoding: utf-8 -*-
class IfThenElse
def initialize(&block)
yield self
end
def exec
if @if.call
@then.call
# -*- encoding: utf-8 -*-
class And
def initialize(*node)
@node = node
end
def exec
@haru01
haru01 / gist:3593169
Created September 2, 2012 01:15
経路
# encoding: utf-8
class RouteMap
def initialize(&block)
@links = []
block.call(self) if block_given?
end
def link(station_a, station_b, time_cost=0)
@links << Link.new(station_a, station_b, time_cost)
@haru01
haru01 / gist:4145680
Created November 25, 2012 22:27
sudoku
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.Constraints;
namespace sudoku {
[TestFixture]
public class SudokuBoardTest
@haru01
haru01 / gist:4224595
Created December 6, 2012 13:52
lifegame
# encoding: utf-8
module LifeGame
describe "Spaceの中央セルの状態について" do
subject { Space.start(seeds).next_time.status(1, 1) }
context "誕生:死んでいるセルに隣接する生きたセルがちょうど3つあれば次世代が誕生する" do
let(:seeds) {[ [1,1,0],
[1,0,0],