Skip to content

Instantly share code, notes, and snippets.

@atton
atton / okrb2.rb
Last active December 17, 2015 05:59
flush するスタイルに変更
#!/usr/bin/env ruby
# Okinawarb.new.H.e.l.l.o.comma.space.w.o.r.l.d!.flush("\n")
# => output 'Hello, wrold!'
class String
CharTable = {comma:',', space:' '}
def flush str
print self, str
end
@atton
atton / lisp.rb
Last active December 15, 2015 17:59 — forked from tompng/lisp2.rb
require './lisp_base.rb'
LISP do (cons 1,2) end
LISP do (cond true,(cond false,(cons 1,2),(cons 3,4)),(cons 5,6)) end
LISP do (defun :fact,:x,(cond (eq :x,0),1,(mult (sqrt (square :x)),(fact (minus :x,1))))) end
LISP do (defun :abs,:x,(cond (lt :x,0),(minus 0,:x),:x)) end
LISP do
(defun :sqrtrec,:x,:y,:d,
(cond (lt :d,0.0000000001),
:y,
(cond (lt (mult :y,:y),:x),
@atton
atton / hoge.rb
Created March 28, 2013 10:53
prime division から再構成
299999.prime_division.map{|a,b| a**b}.inject(:*)
@atton
atton / hoge.rb
Created March 28, 2013 10:38
ryudai.rb 005 謎の素数
(0..Float::INFINITY).lazy.select{|a| (a % 2 != 0) && (a % 3 != 0)}.take(1000).to_a.last
@atton
atton / aoj_0008.rb
Last active December 15, 2015 05:49
AOJ 0008
# after 1.9.2
while n = gets.chomp
puts (0..9).to_a.repeated_permutation(4).to_a.map{|a| a.inject(:+)}.select{|b| b == n.to_i}.size
end
@atton
atton / match.rb
Created February 21, 2013 12:53
2013/02/20 な Okinawa.rb の 正規表現でキャプチャしたのを変数に入れたりマッチオブジェクトにしたりなアレ
# vim:set fileencoding=utf-8:
string = "http://www.example.com/hoge/fuga"
/(?<protocol>[a-z]+):\/\/(?<server>[^\/]*)\/(?<path>.*)/ =~ string
p [protocol, server, path] # => ["http", "www.example.com", "hoge/fuga"]
m = /(?<protocol>[a-z]+):\/\/(?<server>[^\/]*)\/(?<path>.*)/.match(string)
p m
#=> #<MatchData "http://www.example.com/hoge/fuga" protocol:"http" server:"www.example.com" path:"hoge/fuga">
@atton
atton / convert.rb
Last active December 12, 2015 02:38
VLSIなアレ
# vim:set fileencoding=utf-8:
Point = 5 # 固定小数点の位置
def convert_2_to_10 bit_array
# 2進数複素数列から10進数複素数へ変換。
# bit_array は [String] を想定。Stringはsize1。
real_sign, real = convert_sign_2(bit_array[0..15])
imaginary_sign, imaginary = convert_sign_2(bit_array[16..32])
@atton
atton / .classpath
Created December 31, 2012 09:35
.classpath added jar in jdk
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home/jre/lib/jfxrt.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@atton
atton / gist:4275788
Created December 13, 2012 11:09
custom cd in zsh
function cd() {
if [ $# -eq 0 ]; then
builtin pushd $HOME
else
builtin cd $@
fi
}
@atton
atton / .gitattributes
Created November 26, 2012 13:15
.gitattributes example
.gitignore export-ignore