Skip to content

Instantly share code, notes, and snippets.

@y-sumida
y-sumida / GBrainFuckResult.groovy
Created April 30, 2013 12:47
Yokohama.groovy #14の成果
package gbf
class GBrainFuckResult {
final String output
final String buffer
GBrainFuckResult(String output, String buffer) {
this.output = output
this.buffer = buffer
}
package xutp
class KeyValueStore {
private final store = [:]
void put(def key, def value) {
if (key == null) throw new IllegalArgumentException()
store[key] = value
}
@y-sumida
y-sumida / BaseballScore.groovy
Created February 18, 2013 12:48
オフラインリアルタイムどう書く第三回の参考問題 http://qiita.com/items/ebd8a56b41711ba459f9
package doukaku
class BaseballScore {
String ballCount(String s) {
def out = 0
def strike = 0
def ball = 0
def result = []
@y-sumida
y-sumida / CalcController.groovy
Created January 26, 2013 12:39
yokohama.groovy #11の成果 簡易電卓
package calc
import groovy.util.Eval
import java.awt.event.ActionEvent
class CalcController {
def model
def view
package doukaku
class Poker {
final def handPattern = ['14':'4K', '23':'FH', '113':'3K', '122':'2P', '1112':'1P', '11111':'-']
String judge(String hand) {
def eachNumberCount = [:].withDefault {0}
(hand =~ /([2-9AJQK]|10)/).each {
++eachNumberCount[it]
}
@y-sumida
y-sumida / irof.c
Created January 25, 2013 13:36
irofコマンド
#include <stdio.h>
int main(int argc, char* argv[]) {
printf(" \n");
printf(" .;BHHHHBBBBBBBBBBBBBBBBBHHBs........ \n");
printf(" ,:G@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#:: \n");
printf(" h@@@@@@@@@2X9, :GhGAAAB@@@@@@@@@@@@i \n");
printf(" r@@@@@&: S@@@@@@@; \n");
printf(" .B@@@@M, ,@@@@@@. \n");
printf(" 9@@@, :@@@@@ \n");
@y-sumida
y-sumida / Calculator.groovy
Created December 2, 2012 05:50
12/1 『JUnit実践入門』読書会で写経した内容
package Calculator
class Calculator {
Integer add(int x, int y) {
x + y
}
Integer multiply(int x, int y) {
x * y
}
@y-sumida
y-sumida / gist:4186955
Created December 2, 2012 04:25
Integerを拡張してfizzbuzz
@Category(Integer)
class IntegerCategory {
Integer fizzbuzz() {
if (this % 15 == 0) {
println "FizzBuzz"
} else if (this % 5 == 0) {
println "Buzz"
} else if (this % 3 == 0) {
println "Fizz"
} else {
class Tetromino {
private List patternL = [[1,1,10],[10,1,1],[10,10,1],[1,10,10],[10,9,1],[1,1,8],[1,9,10],[8,1,1]]
private List patternI = [[1,1,1],[10,10,10]]
private List patternT = [[9,1,10],[1,1,9],[10,1,9],[9,1,1]]
private List patternO = [[1,9,1]]
private List patternS = [[1,10,1],[1,8,1],[10,1,10],[9,1,9]]
String judge(List coordinates) {
if (isOverEdge(coordinates))
return "-"
@y-sumida
y-sumida / brainfuck.rb
Created July 18, 2012 11:57
BrainFuck
class BrainFuck
def convert(src)
dst = Array.new(65536, 0)
src_position = 0
dst_position = 0
while src_position < src.size
case src[src_position]
when ?>
dst_position += 1
when ?<