Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Makes a "Hello, world!" program that has no literals.
class HelloWorldGenerator1
def initialize(s = "Hello, world!")
@message = s.chomp + "\n"
end
#!/usr/bin/env ruby
# ruby magicsquare.rb
# ruby magicsquare.rb -c
# ruby magicsquare.rb 2
# ruby magicsquare.rb 3
module MagicSquare
class Table
def initialize(t = nil)
@takehiko
takehiko / kukuplot.R
Created July 15, 2014 21:28
Kuku (a.k.a. multiplication table) Answer Accuracy
# kukuplot.R - Kuku (a.k.a. multiplication table) Answer Accuracy
# by takehikom
# http://berd.benesse.jp/berd/center/open/report/keisanryoku/2013/pdf/keisanryoku_2013_data_all.pdf#page=15
# http://i.imgur.com/tE4ncBy.gif
# http://qiita.com/wakuteka/items/c5910a54273d05577c5d
library(lattice)
kuku.acc <- c(
@takehiko
takehiko / TrianglePuzzleSolver.rb
Last active August 29, 2015 14:04
triangle puzzle solver
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# TrianglePuzzleSolver.rb
# by takehikom
# inspired by:
# http://www.huffingtonpost.jp/satoshi-kagimoto/triangle-puzzle_b_5590269.html
module TrianglePuzzle
@takehiko
takehiko / TrianglePuzzleSolver5x5.rb
Created July 19, 2014 14:42
triangle puzzle solver (5 numbers on a side)
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# TrianglePuzzleSolver5x5.rb
# by takehikom
# inspired by:
# http://www.ksproj.com/PDF/chirashi201405.pdf
# NOTE: Since we get 4354560 patterns (whereas TrianglePuzzleSolver.rb
@takehiko
takehiko / trips.rb
Created July 23, 2014 21:07
Triangle Puzzle Solver
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# trips.rb - Triangle Puzzle Solver
# by takehikom
# inspired by:
# http://www.huffingtonpost.jp/satoshi-kagimoto/triangle-puzzle_b_5590269.html
# ruby trips.rb
@takehiko
takehiko / trips5.rb
Created July 23, 2014 21:11
Trinagle Puzzle Solver (5 numbers on a side)
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# trips5.rb - Trinagle Puzzle Solver (5 numbers on a side)
# by takehikom
# inspired by:
# http://www.ksproj.com/PDF/chirashi201405.pdf
# see also:
# https://gist.github.com/takehiko/65dc59fb984e60bafb24 (trips.rb)
@takehiko
takehiko / constant.c
Created August 7, 2014 14:03
Compare "const int", "#define", and "enum".
#include <stdio.h>
/*
constant.c - compare "const int", "#define", and "enum".
inspired by:
http://stackoverflow.com/questions/1674032/static-const-vs-define-in-c
*/
/* gcc constant.c -o constant */
/* gcc -std=c89 -pedantic -DOPTION_1 constant.c -o constant */
@takehiko
takehiko / im-text-region.rb
Created August 25, 2014 12:14
Region calculator using ImageMagick's convert command
#!/usr/bin/env ruby
# im-text-region.rb - Region calculator using ImageMagick's convert command
# by takehikom
# ruby $S/priv/rb/im-text-region.rb
# ruby $S/priv/rb/im-text-region.rb '和歌山' Meiryo-UI-Regular
class TextRegion
def initialize(opt = {})
@takehiko
takehiko / auto_gdb_kuku.rb
Created November 21, 2014 20:57
How many times the value of inner loop's variable is changed
#!/usr/bin/env ruby
# auto_gdb_kuku.rb
# How many times the value of inner loop's variable is changed
# by takehikom
# ruby auto_gdb_kuku.rb
# ruby auto_gdb_kuku.rb | grep 'New value'
# ruby auto_gdb_kuku.rb | grep 'New value' | wc -l