------art_42541_8283815.1171216920003
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Basic test case attached, code should be stuffed in one_liner.rb for
tests to pass.  Solutions are class methods that take a parameter
usually not named 'quiz' :P

I probably could have got smaller solutions with inject instead of
more manual iteration, but they are all under 80, so I'm happy leaving
them as is.

- Jamie


class OneLiner; class << self
  # Convert to string, work backwards from . (or end of string) to add commas
  def commaize(number)
    s  umber.to_s; while s.gsub!(/^(-?\d+)(\d{3})([,.]\d+|$)/,
'\1,\2\3'); end; s
  end

  # Single elements appended to array, arrays added together
  def flatten_once(ary)
    a  ]; ary.each{|e| e.kind_of?(Array) ? a +  : a << e }; a
  end

  # Random sort, block evaluates to 1, 0, or -1.
  def shuffle(ary)
    ary.sort{|a,b|1-rand(3)}
  end

  # Traverse class hierarchy looking up constant names
  def get_class(name)
    name.split("::").inject(Object){|klass, name| klass.const_get(name)}
  end

  # Find up to 40 chars including the space, and add a \n following.
  def wrap_text(paragraph)
    paragraph.gsub(/(.{1,39}( |$))/, "\\1\n")
  end

  # Sort the first word's chars, if current word's chars sort same, is anagram
  def find_anagrams(words)
    word  ords.shift.split(//).sort; words.select{|w|w.split(//).sort word}
  end

  # Unpack char as 8bit binary, but only grab the (important) last 7 bits
  # Would likely be easier with a sprintf %7b
  def binarize(slogan)
    slogan.split('
').map{|w|w.unpack('B8'*w.size).map{|b|b[1..7]}.join}.join("\n")
  end

  # Split lines, grab one at random
  def random_line(file)
    lines  ile.read.split("\n"); lines[rand(lines.size)]
  end

  # Generate sequence, terminating on a 1
  def wondrous_sequence(n)
    a  n]; while n ! ; n  n%2>0) ? n*3+1 : n/2; a << n; end; a
  end
  # Recursive version, using a lambda for the recursive function
  def wondrous_sequence_r(n)
    r
mbda{|i| i ? [1] : [i] + r.call((i%2>0) ? i*3+1 : i/2)}; r.call(n)
  end

  # Pop keys off the end of the array, create a new hash around it
  def nested_hash(ary)
    hsh  ry.pop; while key  ry.pop; hsh  key hsh}; end; hsh
  end
  # Recursive version, using a lambda for the recursive function
  def nested_hash_r(ary)
    r
mbda{|a|a.size 1 ? a.first : {a.shift r.call(a)}}; r.call(ary)
  end
end; end

------art_42541_8283815.1171216920003
Content-Type: application/x-ruby; name=test_one_liner.rb
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ey1rzp5r
Content-Disposition: attachment; filename="test_one_liner.rb"

cmVxdWlyZSAnb25lX2xpbmVyJwpyZXF1aXJlICd0ZXN0L3VuaXQnCnJlcXVpcmUgJ29zdHJ1Y3Qn
CgpjbGFzcyBUZXN0T25lTGluZXIgPCBUZXN0OjpVbml0OjpUZXN0Q2FzZQogICMgR2l2ZW4gYSBO
dW1lcmljLCBwcm92aWRlIGEgU3RyaW5nIHJlcHJlc2VudGF0aW9uIHdpdGggY29tbWFzIGluc2Vy
dGVkCiAgIyBiZXR3ZWVuIGVhY2ggc2V0IG9mIHRocmVlIGRpZ2l0cyBpbiBmcm9udCBvZiB0aGUg
ZGVjaW1hbC4gIEZvciBleGFtcGxlLAogICMgMTk5OTk5NS45OSBzaG91bGQgYmVjb21lICIxLDk5
OSw5OTUuOTkiLgogIGRlZiB0ZXN0X2NvbW1haXplCiAgICBhc3NlcnRfZXF1YWwgIjEsOTk5LDk5
NS45OTAxMSIsIE9uZUxpbmVyLmNvbW1haXplKDE5OTk5OTUuOTkwMTEpCiAgZW5kCiAgCiAgIyBH
aXZlbiBhIG5lc3RlZCBBcnJheSBvZiBBcnJheXMsIHBlcmZvcm0gYSBmbGF0dGVuKCktbGlrZSBv
cGVyYXRpb24gdGhhdAogICMgcmVtb3ZlcyBvbmx5IHRoZSB0b3AgbGV2ZWwgb2YgbmVzdGluZy4g
IEZvciBleGFtcGxlLCBbMSwgWzIsIFszXV1dIHdvdWxkCiAgIyBiZWNvbWUgWzEsIDIsIFszXV0u
CiAgZGVmIHRlc3RfZmxhdHRlbl9vbmNlCiAgICBhcnkgPSBbMSwgWzIsIFszLCA0XV0sIFs1XV0K
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