regex

Standard

http://regexvisualizer.apphb.com/

http://www.regular-expressions.info/reference.html

http://en.wikipedia.org/wiki/Regular_language

http://en.wikipedia.org/wiki/Regular_grammar

http://en.wikipedia.org/wiki/Regular_expression

http://en.wikipedia.org/wiki/Chomsky_hierarchy

 

regex to check prime

http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/

http://qntm.org/greenery

http://www.cis.upenn.edu/~cis639/docs/fssyntax.html

http://www.dreambank.net/regex.html

 

making one-line code for {0,1}^n array with ruby

Standard

first idea

f = lambda{|x| x.zero?? [[]] : (y = f.call(x-1) and y.collect{|z| [Array.new(z) << 0, Array.new(z) << 1]}.flatten(1))}
def g(n) (0…2**n).collect {|x| (“%0#{n}d” % x.to_s(2)).split(”)} end

 

making better

f = lambda{|x| x.zero?? [[]] : f.call(x-1).collect{|y| [y.dup << 0, y.dup << 1]}.flatten(1)}

def g(n) (0…2**n).collect {|x| (“%0#{n}d”%x.to_s(2)).split(”)} end

 

found product function

f = lambda{|x| x.zero?? [[]] : f.call(x-1).product([0,1]).collect{|x|x.flatten}}

 

found product function can take multiple arguments

def h(x) [0,1].product(*x.times.map{[0,1]}) end

 

 

senior’s advice : %w{0 1}.repeated_permutation(n).to_a

senior’s non-recursive version : f = lambda{|x| x == 0 ? [[]] : [0,1].product(*([[0,1]]*(x-1)))}

 

haha I need to intensively study the documentations.