Entries from 2007-03-01 to 1 month

Matz' TkLife Resurrected

Original: tklifegame.rb in "O-O Script Language Ruby," by Matz, ASCII 1999 Modifications to run on ruby 1.8: [1] hash clean up (ruby 1.8), "hash[key] = nil" --> "hash.delete key" [2] reduced screen size, 480x480 (tile size 6) --> 400x400 (…

Machine Epsilon - Really?

Function zeros do not necessarily fall on the discretely desirable points. For example, the Colinear checking function shows a pattern of zeros in yellow, positives in red, and negatives in blue. require 'tk' root = TkRoot.new $canvas = Tk…

Quaternary Tree

# "Spatial Tessellations: Concepts and Applications of Voronoi Diagrams," 2nd Ed. # A. Okabe, B. Boots, K, Sugihara, S.N. Chiu, Wiley 2000 # p.245 Algorithm 4.3.1, Ch4 Algorithms for Computing Voronoi Diagram # Given randomly generated 2D …

Euler's Totient Function

Euler's phi function: number of coprimes of an integer m phi(m) = m*Prod(1-1/p) [where p: prime number and p|m] def phi(m) r = (2..m) primes = r.inject(r){|p, i| p.select{|n| n==i || n%i!=0}} primes.inject(m){|e, p| e%p==0 ? e/p*(p-1) : e}…

Symbol Golf - Musical Score 2

Thanks to 記号ゴルファーΩ, code I posted on Musical Score reduces its size to 234: _='' $<.map{|$_|_<<chomp} k=a.size/12 (0...k).map{|i|$_=' '*12 (0..11).map{|j|$_[j]=_[k*j+i]} ($-=(~/\|/);$><<"FEDCBAGFE"[$_.index('o')-3,1])if i%4==0 $><<(~/\\{3}/?"/32":~/\\{2}/?"/16":~/\\{1}/?"/8":$-?"/4":'')+' 'if i%4==1…</chomp}>

Code Golf - Musical Score

Code Golf http://codegolf.com/musical-score a='' a=a+chomp while gets k=a.size/12 b=' '*12*k for i in 0...k for j in 0...12 b[12*i+j]=a[k*j+i] end $_=b[12*i...12*(i+1)] if i%4==0 print " FEDCBAGFE"[$_.index('o'),1] f=(~/\|/) end if i%4==1 …

Carmichael Numbers

A Carmichael number is an odd composite number n which satisfies Fermat's little theorem a^(n-1)-1=0 (mod n) for every choice of a satisfying (a,n)==1 (i.e., a and n are relatively prime) with 1 r = (2..101) primes = r.inject(r){|p, i| p.s…