Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Fwd: Please Forward: Ruby Quiz Submission
James Gray
5/20/2007 3:12:00 PM
>
> I consulted
http://mathworld.wolfram.com/MagicS...
for the
> methods to generate the magic squares.
>
> Timing on my C2D MacBook Pro seems good.
>
> $ cat run_magic_square.rb
> require 'magic_square'
>
> puts Matrix.new_magic_square(ARGV[0]).to_s_pretty
>
> $ time ruby run_magic_square.rb 9
> +--------------------------------------------+
> | 47 | 58 | 69 | 80 | 1 | 12 | 23 | 34 | 45 |
> +--------------------------------------------+
> | 57 | 68 | 79 | 9 | 11 | 22 | 33 | 44 | 46 |
> +--------------------------------------------+
> | 67 | 78 | 8 | 10 | 21 | 32 | 43 | 54 | 56 |
> +--------------------------------------------+
> | 77 | 7 | 18 | 20 | 31 | 42 | 53 | 55 | 66 |
> +--------------------------------------------+
> | 6 | 17 | 19 | 30 | 41 | 52 | 63 | 65 | 76 |
> +--------------------------------------------+
> | 16 | 27 | 29 | 40 | 51 | 62 | 64 | 75 | 5 |
> +--------------------------------------------+
> | 26 | 28 | 39 | 50 | 61 | 72 | 74 | 4 | 15 |
> +--------------------------------------------+
> | 36 | 38 | 49 | 60 | 71 | 73 | 3 | 14 | 25 |
> +--------------------------------------------+
> | 37 | 48 | 59 | 70 | 81 | 2 | 13 | 24 | 35 |
> +--------------------------------------------+
>
> real 0m0.017s
> user 0m0.010s
> sys 0m0.007s
>
> $ for i in 298 300; do
> > time ruby run_magic_square.rb $i > /dev/null
> > done
>
> real 0m1.513s
> user 0m1.006s
> sys 0m0.505s
>
> real 0m1.344s
> user 0m0.836s
> sys 0m0.506s
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Fwd: Please Forward: Ruby Quiz Submission
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password