Skip to content

Instantly share code, notes, and snippets.

View dproject21's full-sized avatar

Daiki Tanoguchi dproject21

  • Yokohama, Japan
View GitHub Profile
@dproject21
dproject21 / line_item.rb
Created June 9, 2012 08:14
Agile Web Development with Rails (4th edition) on Rails 3.2.3 at CartCreation
# encoding: utf-8
class LineItem < ActiveRecord::Base
attr_accessible :product,:cart_id,:product_id
belongs_to :product
belongs_to :cart
end
@dproject21
dproject21 / fib_exist.rb
Created August 11, 2012 15:14
フィボナッチ数かどうかを検証する。
require './fib_map'
@fib_map = FibMap.new(100)
(0..100).each {|item|
if @fib_map.fibonacci?(item) then
p 'HENTAI!'
else
p item
end
@dproject21
dproject21 / fibonacci.groovy
Created September 4, 2012 11:41
Groovyでクロージャーで計算機とかフィボナッチとか
def baseInt = 0
def addInt = 1
Closure fibonacci = {
println baseInt
def nextBase = addInt
def nextAdd = baseInt + addInt
baseInt = nextBase
addInt = nextAdd
}
@dproject21
dproject21 / fibonacci.scala
Created September 4, 2012 14:31
Scalaでフィボナッチ
def fibonacci() = {
var baseInt = 0
var addInt = 1
() => {
val nextBase = addInt
val nextAdd = baseInt + addInt
baseInt = nextBase
addInt = nextAdd
}
println(baseInt)
@dproject21
dproject21 / tetromino.cs
Created October 6, 2012 10:10
#yhpg 4回目のお題。テトロミノ解析 力技バージョン。
using System;
using System.Collections.Generic;
namespace yhpg4
{
class MainClass
{
public static void Main (string[] args)
{
TetrominoChecker checker = new TetrominoChecker();
@dproject21
dproject21 / problem4.groovy
Created January 20, 2013 05:53
プロジェクトオイラーの解答。
ans = 0
for (int i: 100 .. 999) {
for (int j: i .. 999) {
m = i * j
str = m.toString()
reverseStr = str.reverse()
if (str == reverseStr) {
kaibun = str.toInteger()
if (ans < kaibun) {
@dproject21
dproject21 / problem5.groovy
Created January 20, 2013 06:22
プロジェクトオイラー problem5の解答
b = 2
while(true) {
canDiv = true
for (int i: 2 .. 20) {
if (b % i) {
canDiv = false
break
}
}
if (canDiv) {
@dproject21
dproject21 / problem6.groovy
Created January 20, 2013 06:42
プロジェクトオイラー problem6の解答
sum1 = 0
for (int i: 1..100) {
sum1 += i**2
}
sum2 = 0
for (int j: 1..100) {
sum2 += j
}
sum2 = sum2**2
@dproject21
dproject21 / problem7.groovy
Created January 20, 2013 07:20
プロジェクトオイラー problem7の解答
primeList = [2]
intList = []
for (int i : 3 .. 200000) {
if (i % 2 != 0) {
intList.push(i)
}
}
while(intList.size() != 0) {
primeList.push(intList.first())
intList.removeAll{it % primeList.last() == 0}
@dproject21
dproject21 / problem8.groovy
Created January 20, 2013 08:14
プロジェクトオイラー problem8の解答
line = "73167176531330624919225119674426574742355349194934" +
"96983520312774506326239578318016984801869478851843" +
"85861560789112949495459501737958331952853208805511" +
"12540698747158523863050715693290963295227443043557" +
"66896648950445244523161731856403098711121722383113" +
"62229893423380308135336276614282806444486645238749" +
"30358907296290491560440772390713810515859307960866" +
"70172427121883998797908792274921901699720888093776" +
"65727333001053367881220235421809751254540594752243" +
"52584907711670556013604839586446706324415722155397" +