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

Hi

here goes my solution for Ruby Quiz #124.
This was quite tough, firstly to find the algorithms and secondly to
write concise code that still runs not too slowly.
I have therefore adapted my original solution (which runs 30% faster
and still is attached to this mail) to something more "readable", well
it is up to you to judge that :).

I know this is not DRY, but politeness cannot be ;). Ty again for the
great effort Ruby Quiz is.
BTW is there a book to be published one day about Ruby Quiz?

Cheers
Robert


Usage  <-EOS
  usage:
      ruby #{$0} [-t|--test] [-h|--html] <Square Order List>

      Prints Magic Squares for all indicated orders.
      Indicating -t also tests the results.
EOS
loop do
  case ARGV.first
    when "-t", "--test"
      require 'test-squares'
      ARGV.shift
    when "-h", "--html"
      require 'html-output'
      ARGV.shift
    when "-?", "--help", nil
      puts Usage
      exit
    when "--"
      ARGV.shift && break
    else
      break
  end
end

class Array
  def lpos; first end
  def cpos; self[1] end
end
#
# This is a default output module, another output
# module called HTMLOutput is provided as an example
# how to pull in an appropriate Output module
# as plugin.
#
module Output
  def to_s decoration  alse
    l  @order*@order).to_s.size
    return  @data.map{ |line|
                        line.map{ |cell|
                                   "%#{l}d" % cell
                                }.join(" ")
                      }.join("\n") unless decoration

    sep_line  +" << ( "-" * l.succ.succ << "+" ) * @order
    sep_line.dup << "\n" <<
    @data.map{ | line | "| " << line.map{ |cell| "%#{l}d" % cell
}.join(" | ") << " |" }.
      zip( [sep_line] * @order ).flatten.join("\n")
  end
end

#
# The usage of cursors is slowing down the program a little
# bit but I feel it is still fast enough.
#
class Cursor
  attr_reader :cpos, :lpos
  def initialize order, lpos, cpos
    @order  rder
    @lpos   pos
    @cpos   pos
  end

  def move ldelta, cdelta
    l  lpos + ldelta
    c  cpos + cdelta
    l % order
    c % order
    self.class.new @order, l, c
  end
  def next!
     s  up
     @cpos + 
     return s if @cpos < @order
     @cpos  
     @lpos + 
     @lpos % order
     s
  end
end

#
# This is where the work is done, like
# testing and outputting and what was it?
# Ah yes storing the data.
#
class SquareData
  include Output
  include HTMLOutput rescue nil
  include TestSquare rescue nil
  def initialize order
    @order  rder
    @data  rray.new( @order ){ Array.new( @order ) { nil } }
  end

  def [](c); @data[c.lpos][c.cpos] end
  def []
, v); @data[c.lpos][c.cpos] end def each_subdiagonal (@order/4).times do | line | (@order/4).times do | col | 4.times do | l | 4.times do | c | yield [ 4*line + l, 4*col + c ] if l
|| l+c 3 end end # 4.times do end # (@order/4).times do end # (@order/4).times do end def siamese_order model elf.class.new @order last order*@order @pos ursor.new @order, 0, @order/2 yield @pos.lpos, @pos.cpos, self[@pos] model[ @pos ] rue 2.upto last do npos pos.move -1, +1 npos pos.move +1, 0 if model[ npos ] model[ @pos pos ] rue yield @pos.lpos, @pos.cpos, self[@pos] end # @last.times do end end # class SquareData # # The base class for Magic Squares it basically # is the result of factorizing the three classes # representing the three differnt cases, odd, even and # double even. # # It's singleton class is used as a class Factory for # the three implementing classes. # class Square def to_s decoration alse @data.to_s decoration end private def initialize order @order rder.to_i @last order*@order @data quareData.new @order compute @data.test rescue nil end end # # The simplest case, the Siamese Order algorithm # is applied. # class OddSquare < Square private def compute count @data.siamese_order do | lpos, cpos, _ | @data[[ lpos, cpos]] ount count + end # @data.siamese_order do end end # class OddSquare # # The Double Cross Algorithm is applied # to double even Squares. # class DoubleCross < Square def compute pos ursor.new @order, 0, 0 1.upto( @last ) do | n | @data[ pos.next! ] end # 1.upto( @last ) do @data.each_subdiagonal do | lidx, cidx | @data[[ lidx, cidx ]] last.succ - @data[[lidx, cidx]] end end end # # And eventually we use the LUX algorithm of Conway for even # squares. # class FiatLux < Square L [0, 1], [1, 0], [1, 1], [0, 0] ] U [0, 0], [1, 0], [1, 1], [0, 1] ] X [0, 0], [1, 1], [1, 0], [0, 1] ] def compute half order / 2 lux_data quareData.new half n alf/2 pos ursor.new half, 0, 0 n.succ.times do half.times do lux_data[ pos.next! ] end # half.times do end # n.succ.times do half.times do lux_data[ pos.next! ] end # half.times do lux_data[[ n, n ]] lux_data[[ n+1, n]] 2.upto(n) do half.times do lux_data[ pos.next! ] end end # 2.upto(half) do count lux_data.siamese_order do | siam_row, siam_col, elem | elem.each do | r, c | @data[[ 2*siam_row + r, 2*siam_col + c ]] ount count + end # elem.each do end # lux_data.siamese_order do end end # class FiatLux class << Square # # trying to call the ctors with consistent values only # protected :new def Factory arg arg rg.to_i case arg % 4 when 1, 3 OddSquare.new arg when 0 DoubleCross.new arg else FiatLux.new arg end end end ARGV.each do |arg| puts Square::Factory( arg ).to_s( true ) puts end ------art_78371_25250453.1179662733670 Content-Type: application/x-ruby; name=124-magic-square-readable.rb Content-Transfer-Encoding: base64 X-Attachment-Id: f_f1xd0x0c Content-Disposition: attachment; filename="124-magic-square-readable.rb" IyB2aW06IHN0cz0yIHN3PTIgZnQ9cnVieSBleHBhbmR0YWIgbnUgdHc9MDoKVXNhZ2UgPSA8PC1F T1MKICB1c2FnZToKICAgICAgcnVieSAjeyQwfSBbLXR8LS10ZXN0XSBbLWh8LS1odG1sXSA8U3F1 YXJlIE9yZGVyIExpc3Q+CgogICAgICBQcmludHMgTWFnaWMgU3F1YXJlcyBmb3IgYWxsIGluZGlj YXRlZCBvcmRlcnMuCiAgICAgIEluZGljYXRpbmcgLXQgYWxzbyB0ZXN0cyB0aGUgcmVzdWx0cy4K RU9TCmxvb3AgZG8KICBjYXNlIEFSR1YuZmlyc3QKICAgIHdoZW4gIi10IiwgIi0tdGVzdCIKICAg ICAgcmVxdWlyZSAndGVzdC1zcXVhcmVzJwogICAgICBBUkdWLnNoaWZ0CiAgICB3aGVuICItaCIs ICItLWh0bWwiCiAgICAgIHJlcXVpcmUgJ2h0bWwtb3V0cHV0JwogICAgICBBUkdWLnNoaWZ0CiAg ICB3aGVuICItPyIsICItLWhlbHAiLCBuaWwKICAgICAgcHV0cyBVc2FnZQogICAgICBleGl0CiAg ICB3aGVuICItLSIKICAgICAgQVJHVi5zaGlmdCAmJiBicmVhawogICAgZWxzZQogICAgICBicmVh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9CiAgZW5kCiAgCiAgZGVmIFtdKGMpOyBAZGF0 YVtjLmxwb3NdW2MuY3Bvc10gZW5kCiAgZGVmIFtdPShjLCB2KTsgQGRhdGFbYy5scG9zXVtjLmNw b3NdID0gdiBlbmQKCiAgZGVmIGVhY2hfc3ViZGlhZ29uYWwKICAgIChAb3JkZXIvNCkudGltZXMg ZG8KICAgICAgfCBsaW5lIHwKICAgICAgKEBvcmRlci80KS50aW1lcyBkbwogICAgICAgIHwgY29s IHwKICAgICAgICA0LnRpbWVzIGRvCiAgICAgICAgICB8IGwgfAogICAgICAgICAgNC50aW1lcyBk bwogICAgICAgICAgICB8IGMgfAogICAgICAgICAgICB5aWVsZCBbIDQqbGluZSArIGwsIDQqY29s ICsgYyBdIGlmCiAgICAgICAgICAgIGw9PWMgfHwgbCtjID09IDMKICAgICAgICAgIGVuZAogICAg ICAgIGVuZCAjIDQudGltZXMgZG8KICAgICAgZW5kICMgKEBvcmRlci80KS50aW1lcyBkbwogICAg ZW5kICMgKEBvcmRlci80KS50aW1lcyBkbwogIGVuZAoKICBkZWYgc2lhbWVzZV9vcmRlcgogICAg bW9kZWwgPSBzZWxmLmNsYXNzLm5ldyBAb3JkZXIKICAgIGxhc3QgPSBAb3JkZXIqQG9yZGVyCiAg ICBAcG9zID0gQ3Vyc29yLm5ldyBAb3JkZXIsIDAsIEBvcmRlci8yCiAgICB5aWVsZCBAcG9zLmxw b3MsIEBwb3MuY3Bvcywgc2VsZltAcG9zXQogICAgbW9kZWxbIEBwb3MgXSA9IHRydWUKICAgIDIu dXB0byBsYXN0IGRvCiAgICAgIG5wb3MgPSBAcG9zLm1vdmUgLTEsICsxCiAgICAgIG5wb3MgPSBA cG9zLm1vdmUgKzEsIDAgaWYgbW9kZWxbIG5wb3MgXQogICAgICBtb2RlbFsgQHBvcyA9IG5wb3Mg XSA9IHRydWUKICAgICAgeWllbGQgQHBvcy5scG9zLCBAcG9zLmNwb3MsIHNlbGZbQHBvc10KICAg IGVuZCAjIEB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ICBlbHNlCiAgICAgICAgRmlhdEx1eC5uZXcgYXJnCiAgICBlbmQKICBlbmQKZW5kCkFSR1Yu ZWFjaCBkbwogIHxhcmd8CiAgcHV0cyBTcXVhcmU6OkZhY3RvcnkoIGFyZyApLnRvX3MoIHRydWUg KQogIHB1dHMKZW5kCgo------art_78371_25250453.1179662733670 Content-Type: application/x-ruby; name=124-magic-square.rb Content-Transfer-Encoding: base64 X-Attachment-Id: f_f1xd1kgn Content-Disposition: attachment; filename="124-magic-square.rb" IyB2aW06IHN0cz0yIHN3PTIgZnQ9cnVieSBleHBhbmR0YWIgbnUgdHc9MDoKVXNhZ2UgPSA8PC1F T1MKICB1c2FnZToKICAgICAgcnVieSAjeyQwfSBbLXR8LS10ZXN0XSBbLWh8LS1odG1sXSA8U3F1 YXJlIE9yZGVyIExpc3Q+CgogICAgICBQcmludHMgTWFnaWMgU3F1YXJlcyBmb3IgYWxsIGluZGlj YXRlZCBvcmRlcnMuCiAgICAgIEluZGljYXRpbmcgLXQgYWxzbyB0ZXN0cyB0aGUgcmVzdWx0cy4K RU9TCmxvb3AgZG8KICBjYXNlIEFSR1YuZmlyc3QKICAgIHdoZW4gIi10IiwgIi0tdGVzdCIKICAg ICAgcmVxdWlyZSAndGVzdC1zcXVhcmVzJwogICAgICBBUkdWLnNoaWZ0CiAgICB3aGVuICItaCIs ICItLWh0bWwiCiAgICAgIHJlcXVpcmUgJ2h0bWwtb3V0cHV0JwogICAgICBBUkdWLnNoaWZ0CiAg ICB3aGVuICItPyIsICItLWhlbHAiLCBuaWwKICAgICAgcHV0cyBVc2FnZQogICAgICBleGl0CiAg ICB3aGVuICItLSIKICAgICAgQVJHVi5zaGlmdCAmJiBicmVhawogICAgZWxzZQogICAgICBicmVh awogIGVuZAplbmQKCiMKIyBUaGlzIGlzIGEgZGVmYXVsdCBvdXRwdXQgbW9kdWxlLCBhbm90aGVy IG91dHB1dAojIG1vZHVsZSBjYWxsZWQgSFRNTE91dHB1dCBpcyBwcm92aWR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hY2hfc3ViZGlhZ29uYWwKICAgIChAb3JkZXIvNCkudGltZXMgZG8KICAgICAg fCBsaW5lIHwKICAgICAgKEBvcmRlci80KS50aW1lcyBkbwogICAgICAgIHwgY29sIHwKICAgICAg ICA0LnRpbWVzIGRvCiAgICAgICAgICB8IGwgfAogICAgICAgICAgNC50aW1lcyBkbwogICAgICAg ICAgICB8IGMgfAogICAgICAgICAgICB5aWVsZCBbIDQqbGluZSArIGwsIDQqY29sICsgYyBdIGlm CiAgICAgICAgICAgIGw9PWMgfHwgbCtjID09IDMKICAgICAgICAgIGVuZAogICAgICAgIGVuZCAj IDQudGltZXMgZG8KICAgICAgZW5kICMgKEBvcmRlci80KS50aW1lcyBkbwogICAgZW5kICMgKEBv cmRlci80KS50aW1lcyBkbwogIGVuZAoKICBkZWYgc2lhbWVzZV9vcmRlcgogICAgbW9kZWwgPSBz ZWxmLmNsYXNzLm5ldyBAb3JkZXIKICAgIGxhc3QgPSBAb3JkZXIqQG9yZGVyCiAgICBAcG9zID0g Q3Vyc29yLm5ldyBAb3JkZXIsIDAsIEBvcmRlci8yCiAgICB5aWVsZCBAcG9zLmxwb3MsIEBwb3Mu Y3BvcywgcGVlayggQHBvcy5scG9zLCBAcG9zLmNwb3MgKQogICAgbW9kZWxbIEBwb3MgXSA9IHRy dWUKICAgIDIudXB0byBsYXN0IGRvCiAgICAgIG5wb3MgPSBAcG9zLm1vdmUgLTEsICsxCiAgICAg IG5wb3MgPSBAcG9zLm1vdmUgKzEsIDAgaWYgbW9kZWxbIG5wb3MgXQogICAgICBtb2RlbFsgQHBv cyA9IG5wb3MgXSA9IHRydWUKICAgICAgeWllbGQgQHBvcy5scG9zLCBAcG9zLmNwb3MsIHBlZWso IEBwb3MubHBvcywgQHBvcy5jcG9zICkKICAgIGVuZCAjIEBsYXN0LnRpbWVzIGRvCiAgZW5kCmVu ZCAjIGNsYXNzIFNxdWFyZURhdGEKCiMKIyBUaGUgYmFzZSBjbGFzcyBmb3IgTWFnaWMg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F1YXJlLm5ldyBhcmcKICAgICAg d2hlbiAwCiAgICAgICAgRG91YmxlQ3Jvc3MubmV3IGFyZwogICAgICBlbHNlCiAgICAgICAgRmlh dEx1eC5uZXcgYXJnCiAgICBlbmQKICBlbmQKZW5kCkFSR1YuZWFjaCBkbwogIHxhcmd8CiAgcHV0 cyBTcXVhcmU6OkZhY3RvcnkoIGFyZyApLnRvX3MoIHRydWUgKQogIHB1dHMKZW5kCgo------art_78371_25250453.1179662733670 Content-Type: application/x-ruby; name=test-squares.rb Content-Transfer-Encoding: base64 X-Attachment-Id: f_f1xd1vdn Content-Disposition: attachment; filename="test-squares.rb" IyB2aW06IHN0cz0yIHN3PTIgZnQ9cnVieSBleHBhbmR0YWIgbnUgdHc9MDoKCm1vZHVsZSBUZXN0 U3F1YXJlCiAgZGVmIGFzc2VydCBjZHQsIG1zZwogICAgcmV0dXJuICRzdGRlcnIucHV0cyggIiN7 bXNnfSAuIC4gLiAuIC4gb2siICkgaWYgY2R0CiAgICByYWlzZSBFeGNlcHRpb24sIG1zZyA8PCAi XG4iIDw8IHRvX3MKICBlbmQKICBkZWYgdGVzdAogICAgZGlhMSA9IGRpYTIgPSAwCiAgICBAb3Jk ZXIudGltZXMgZG8KICAgICAgfCBpZHggfAogICAgICBkaWExICs9IHBlZWsoIGlkeCwgaWR4ICkK ICAgICAgZGlhMiArPSBwZWVrKCBpZHgsIC1pZHguc3VjYyApCiAgICBlbmQgIyBAbGluZXMuZWFj aF93aXRoX2luZGV4IGRvCiAgICBhc3NlcnQgZGlhMT09ZGlhMiwgIkJvdGggZGlhZ29uYWxzIgog ICAgQG9yZGVyLnRpbWVzIGRvIAogICAgICB8IGlkeDEgfAogICAgICBjb2xfbiA9IHJvd19uID0g MAogICAgICBAb3JkZXIudGltZXMgZG8gCiAgICAgICAgfCBpZHgyIHwKICAgICAgICBjb2xfbiAr PSBwZWVrIGlkeDIsIGlkeDEKICAgICAgICByb3dfbiArPSBwZWVrIGlkeDEsIGlkeDIKICAgICAg ZW5kCiAgICAgIGFzc2VydCBkaWExID09IGNvbF9uLCAiQ29sICN7aWR4MX0iCiAgICAgIGFzc2Vy dCBkaWExID09IHJvd19uLCAiUm93ICN7aWR4MX0iCiAgICBlbmQgIyBAbGluZXMuZWFjaF93aXRo X2luZGV4IGRvCiAgZW5kICMgZGVmIHRlc3QKCiAgZGVmIGlzX29rPwogICAgZGlhMSA9IGRpYTIg PSAwCiAgICBAb3JkZXIudGltZXMgZG8KICAgICAgfCBpZHggfAogICAgICBkaWExICs9IHBlZWso IGlkeCwgaWR4ICkKICAgICAgZGlhMiArPSBwZWVrKCBpZHgsIC1pZHguc3VjYyApCiAgICBlbmQg IyBAbGluZXMuZWFjaF93aXRoX2luZGV4IGRvCiAgICByZXR1cm4gZmFsc2UgdW5sZXNzIGRpYTE9 PWRpYTIKICAgIEBvcmRlci50aW1lcyBkbyAKICAgICAgfCBpZHgxIHwKICAgICAgY29sX24gPSBy b3dfbiA9IDAKICAgICAgQG9yZGVyLnRpbWVzIGRvIAogICAgICAgIHwgaWR4MiB8CiAgICAgICAg Y29sX24gKz0gcGVlayBpZHgyLCBpZHgxCiAgICAgICAgcm93X24gKz0gcGVlayBpZHgxLCBpZHgy CiAgICAgIGVuZAogICAgICByZXR1cm4gZmFsc2UgdW5sZXNzIGRpYTEgPT0gY29sX24KICAgICAg cmV0dXJuIGZhbHNlIHVubGVzcyBkaWExID09IHJvd19uCiAgICBlbmQgIyBAbGluZXMuZWFjaF93 aXRoX2luZGV4IGRvCiAgICB0cnVlCiAgICAKICBlbmQKCmVuZAo------art_78371_25250453.1179662733670 Content-Type: application/x-ruby; name=html-output.rb Content-Transfer-Encoding: base64 X-Attachment-Id: f_f1xd23gi Content-Disposition: attachment; filename="html-output.rb" IyB2aW06IHN0cz0yIHN3PTIgZnQ9cnVieSBleHBhbmR0YWIgbnUgdHc9MDoKbW9kdWxlIEhUTUxP dXRwdXQKICBkZWYgdG9fcyBkZWNvcmF0aW9uID0gZmFsc2UKICAgICV7PGgxPkEgTWFnaWMgU3F1 YXJlIG9mIG9yZGVyICN7QG9yZGVyfTwvaDE+CiAgICA8dGFibGUje2RlY29yYXRpb24gPyAiIGJv cmRlcj1cIjFcIiI6IiJ9IGNsYXNzPSJtYWdpYy1zcXVhcmUiPlxufSA8PAogICAgICAgIEBkYXRh Lm1hcHsgfGxpbmV8CiAgICAgICAgICAgICAgICAgICAgICAgICV7ICAgPHRyPlxufSA8PCBsaW5l Lm1hcHsgfGNlbGx8ICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAleyAgICAg IDx0ZD4lZDwvdGQ+fSAlIGNlbGwgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfS5q b2luKCJcbiIpIDw8ICV7XG4gICAgICA8L3RyPn0KICAgICAgICAgICAgICAgICAgICAgIH0uam9p bigiXG4iKSA8PCAiXG48L3RhYmxlPiIgCiAgZW5kCmVuZAo------art_78371_25250453.1179662733670--