Uri Guttman (
[email protected]) wrote on MMMMDXLVIII September MCMXCIII
in <URL:--
-- c> Wizard Solutions is now hosting it's first programming competition:
-- c>
http://www.wizardsolutionsusa.com/forum/showthread.php?p=2688#post2688
-- c> Test your skills against other elite programmers and have fun. The
-- c> prize includes money, reputation points,and a top coder ribbon on the
-- c> forum.
--
-- Your program should read a four-digit integer and encrypt it as
-- follows: Replace each digit by ((digit +7)mod 10).Then,swap the
-- first digit with the thir d,swap the second digit with the
-- fourth,and print the encrypted integer. An example session:
--
-- Enter a Four Digit Number:6254
-- The Encrypted Number is:2139
--
-- trivial in perl:
--
-- perl -lne 'print +(map {($_ + 7) %10 } /./g)[2,3,0,1]'
--
-- not something he will likely see in c++ or java. and when the golfers
-- get to work on it, he will be bamboozled.
It's still trivial in C and Java as well.
-- i am not in the mood to work on the other 2 problems. so here they are
-- (i also didn't care to login to the forum site to even bother submitting
-- that solution):
--
-- Peter the postman became bored one night and, to break the
-- monotony of the night shift, he carried out the following
-- experiment with a row of mailboxes in the post office. These
-- mailboxes were numbered 1 through n, and beginning with mailbox
-- 2, he opened the doors of all the even-numbered mailboxes,
-- leaving the other closed. Next, beginning with mailbox 3, he
-- went to every third mail box, opening its door if it were
-- closed, and closing it if it were open. Then he repeated this
-- procedure with every fourth mailbox, then every fifth mailbox,
-- and so on. When he finished, he was surprised at the
-- distribution of closed mailboxes. Write a program to determine
-- which mailboxes these were.
--
-- Input: The number of mailboxes, 99 < n < 1001;
-- Output number of closed mailboxes
Trivial, and it doesn't require much programming.
sub closed_mail_boxes {int sqrt shift}
-- A Magic square is an N <D7> N array of numbers consisting of the
-- positive integers from 1 to N 2 arranged such that each integer
-- is used exactly once, and the s um of the numbers in each
-- horizontal, vertical and corner-to-corner line is the same. You
-- will be given the size of the array (N) and an N <D7> N array of
-- integers. One cell in each row will be marked as a
-- <91>0<92>. You must determine, if possible, whether or not the
-- <91>0<92> values can be replaced by p ositive integers so that
-- the array is a Magic square. The input data begins with a line
-- containing an integer N representing the numbe r of rows in a
-- square (1 < N <= 6). The next N lines represent the array of
-- valu es, N integers per row. If a solution is found, output the
-- square array (N numbers per line). If no solu tion is found,
-- output <93>no solution<94>.
--
-- <i dunno where the wacko formating shit is from. i just downloaded the
-- files and they look like that. the guy who posted these problems is a
-- moron for calling it a .txt file but it is butchered with binary format
-- markup. calling themselves wizard solutions seems to be a false self
-- impression IMO>
--
-- Sample Input:
--
-- 5
-- 24 8 17 0 15
-- 0 5 14 23 7
-- 13 22 0 20 4
-- 10 0 3 12 21
-- 2 11 25 9 0
--
--
-- Sample Output:
--
-- 24 8 17 1 15
-- 16 5 14 23 7
-- 13 22 6 20 4
-- 10 19 3 12 21
-- 2 11 25 9 18
--
#!/usr/bin/perl
use strict;
use warnings;
my $N = <DATA>; chomp $N;
my @seen_numbers = (0) x $N ** 2;
my $row_total = ($N ** 3 + $N) / 2;
my @square; == ==
while (<DATA>) {
my @numbers = /\d+/g;
my $s = 0; $s += $_ for @numbers;
push @square => [map {$_ || $row_total - $s} @numbers];
$seen_numbers [$_] ++ for @{$square [-1]};
}