Front page | perl.fwp |
Postings from March 2002
Re: TPR1 post-mortem
Thread Previous
|
Thread Next
From:
Chris Dolan
Date:
March 8, 2002 09:19
Subject:
Re: TPR1 post-mortem
Message ID:
3C88F26E.9020100@clotho.com
Prakash Kailasa wrote:
>
> I request others to follow with their own accounts about how they
> arrived at their formula(e|s). I am especially intrigued with the
> usage of hex() by Ton and Chris (I haven't looked at all the results,
> so there might be others too). How the heck did you guys think of such
> a thing?
>
Like others did, I built a chart
perl -le 'for$i(0..9){for$j(0..9){printf"%3d",$i+$j}print}'
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10 11
3 4 5 6 7 8 9 10 11 12
4 5 6 7 8 9 10 11 12 13
5 6 7 8 9 10 11 12 13 14
6 7 8 9 10 11 12 13 14 15
7 8 9 10 11 12 13 14 15 16
8 9 10 11 12 13 14 15 16 17
9 10 11 12 13 14 15 16 17 18
and noted that I wanted everything above 9 to be smaller. First I
played with %9
but I got the unfortunate result that while 10%9 is 1, as desired, 9%9
is zero, not
9. I decided I needed a gap between 9 and 10, and it occured to me that
interpreted in a base larger than 10, there would be a gap. I also
realized that the reason that %9 was attractive was that it was the
largest single-digit number. So
perl -le 'for$i(0..9){for$j(0..9){printf"%3d",hex($i+$j)%15}print}'
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 1
2 3 4 5 6 7 8 9 1 2
3 4 5 6 7 8 9 1 2 3
4 5 6 7 8 9 1 2 3 4
5 6 7 8 9 1 2 3 4 5
6 7 8 9 1 2 3 4 5 6
7 8 9 1 2 3 4 5 6 7
8 9 1 2 3 4 5 6 7 8
9 1 2 3 4 5 6 7 8 9
gives the right chart. The 15 is crucial because in hex, its the largest
single digit number.
My biggest failing in this competition is that I couldn't get the $`
approach to work so I was stuck with $' and chop. Ton's ingenious
^s//pop/e was the thing I was missing.
Chris
Thread Previous
|
Thread Next