-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carl Masak
committed
Dec 14, 2012
0 parents
commit 7b00546
Showing
13 changed files
with
651 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## The tasks | ||
|
||
t1. Tell knights from knaves based on what they say. | ||
|
||
t2. Generate rectangle haikus. | ||
|
||
t3. Arrange wire crossings to rearrange wires. | ||
|
||
t4. Simulate rain in a world of cubes. | ||
|
||
t5. Distribute weights in bags evenly. | ||
|
||
## See also | ||
|
||
`rules.md` and `notes.md` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Things that might be good to know | ||
|
||
We'd rather not go changing the `description` and `base-test` files | ||
after having released them, but sometimes new information turns up. | ||
This is where we'll put it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
## How to win | ||
|
||
* A randomly chosen person wins... | ||
|
||
* ...unless people actually send in solutions. | ||
|
||
* Then the choice is made from the "winning set" of people who submitted | ||
solutions to the most exercises. (Put differently, if you've submitted | ||
solutions to strictly fewer exercises than someone else, you're not in the | ||
winning set.) | ||
|
||
* If there's a single contestant in the winning set, that contestant wins. | ||
|
||
* Otherwise, the choice of winner is made by us (masak & moritz) based as | ||
much as possible on code quality. | ||
|
||
Since "code quality" is a slightly subjective measure, let us provide a few | ||
hints of what we'll be looking for: | ||
|
||
* Correctness. | ||
* Readability. | ||
* Consistency. | ||
* Clarity of intent. | ||
* Algorithmic efficiency. | ||
* Idiomatic use of Perl 6. | ||
* Brevity. | ||
|
||
In short, what we're looking for is top-quality code. That's how you win. | ||
|
||
You're free to make use of your own judgment in the shaping of your | ||
code. If you use code that doesn't originate with you, please indicate | ||
so in your comments. There's a spectrum of "copying" here: implementing | ||
an algorithm from somewhere is perfectly fine; sending in a copy of | ||
someone else's solution isn't. | ||
|
||
One final thing. Please be aware that, by entering the contest, you're not | ||
guaranteed the prize. That is, we're not legally bound to hand out the prize | ||
to you for any reasons *you* can think of. We might decide to hand out the | ||
prize to everybody, nobody, or the *worst* coder. We won't, though. We'll | ||
hand out the prize to the best coder. So just be best, and you'll be fine. | ||
Make sure you read each problem description carefully. | ||
|
||
## How to write a solution | ||
|
||
You're free to code however you want, but for the purposes of easy comparison | ||
between submissions, we have a few requests. | ||
|
||
* Put your main Perl 6 script in a file called `code` in the respective | ||
task directory. | ||
|
||
* Make sure this code passes all the tests in `t1/base-test`, | ||
`t2/base-test`, etc. | ||
|
||
We've created the `base-test` files to ascertain a couple of basic | ||
requirements about input and output. This is just to have some common basis | ||
of comparison between the submissions. | ||
|
||
You're certainly allowed to write and include your own tests in a t/ directory, | ||
and to separate code into modules in a `lib/` directory, as long as the file | ||
`t1/code`, etc., remains the main script. The `base-test` script will set | ||
`PERL6LIB` so that modules in the `lib/` directory are found. | ||
|
||
With everything else -- choice of algorithm, indentation, comments, naming -- | ||
you're completely free -- encouraged, even -- to use your own good judgment. | ||
|
||
When you're ready to submit a solution, send the file(s) along to | ||
cmasak@gmail.com. Put them in a `.zip` file if you want. You're free to send in | ||
solutions individually or all at once. Don't wait until the last moment with | ||
sending in solutions. | ||
|
||
If you're one of those Git octocats, you might want to consider cloning this | ||
repository, and then just building an archive out of your latest version: | ||
|
||
$ git archive -o p6cc-solutions-by-jrandomhacker.zip HEAD | ||
|
||
Both Rakudo and Niecza are appropriate platforms for developing solutions for | ||
the contest, and we're flexible as to under which version/release you've | ||
written your code. | ||
|
||
See the [compiler feature matrix](http://perl6.org/compilers/features) or ask | ||
on `#perl6` for up-to-date info about compiler features. | ||
|
||
We appreciate if you tell us which compiler version you're using, but in | ||
a pinch we'll figure it out. `:-)` The `base-test` files respond to an | ||
environment flag `PERL6EXECUTABLE` that you can set if your Perl 6 executable | ||
is not named `perl6`. For Niecza, something like `mono run/Niecza.exe` ought to | ||
work. | ||
|
||
You're allowed to send in several solutions to the same problem, but only the | ||
last one will count, and please don't send more than a total of 10. :-) All | ||
solutions will be published after the conclusion of the contest. All are up for | ||
review. | ||
|
||
## How to have the appropriate amount of fun | ||
|
||
First off, if you haven't entered the contest yet — do so! You've nothing | ||
to lose. | ||
|
||
Secondly, Perl 6 is a shoestring project but with very dedicated people who | ||
are working toward a single vision. (Or, on the days when we have a head-ache, | ||
double vision.) Part of this whole enterprise is making sure we're learning, | ||
about programming, about languages, and about communities. In some loose sense, | ||
that's what this contest is about too: learning new things, and enjoying the | ||
experience. | ||
|
||
So, enjoy! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#! /usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More tests => 8; | ||
|
||
my $code_file = 'code'; | ||
$ENV{PERL6LIB} = 'lib'; | ||
my $perl6 = $ENV{PERL6EXECUTABLE} || 'perl6'; | ||
|
||
sub run { | ||
my ($input) = @_; | ||
|
||
open my $INPUT, '>', 'input'; | ||
print {$INPUT} $input; | ||
close $INPUT; | ||
|
||
my $output = `$perl6 $code_file < input 2>&1`; | ||
unlink 'input'; | ||
|
||
return $output; | ||
} | ||
|
||
die qq[NO FILE "$code_file"] | ||
unless -e $code_file; | ||
|
||
die qq[\nFILE "$code_file" DOES NOT COMPILE] | ||
if system("$perl6 -c $code_file > /dev/null"); | ||
|
||
is run(""), ""; | ||
is run("marmelade"), "Lines must be on the form '<name>: <utterance>'\n"; | ||
is run("A: The quick brown fox."), | ||
"Unrecognized utterance 'The quick brown fox.'\n"; | ||
|
||
is run("A: A is a knight."), "Many solutions:\nA: knight\nA: knave\n"; | ||
is run("A: A is a knave."), "No solutions.\n"; | ||
|
||
is run("A: B is a knight."), "A mentions B but B doesn't say anything.\n"; | ||
is run("A: A and C are of the same type."), | ||
"A mentions C but C doesn't say anything.\n"; | ||
|
||
is run("A: A and B are of the same type.\nB: A and B are of different types.\n"), | ||
"A: knave; B: knight\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## Tell knights from knaves based on what they say | ||
|
||
On the mythical island of Smul, people suffer from a rare genetic disorder that | ||
make them either tell the truth all the time, or lie all the time. These are | ||
the only two types of people on the island, known as knights and knaves, | ||
respectively. | ||
|
||
Write a program that takes as input a number of utterances by islanders, and | ||
outputs for each person whether that person is a knight or a knave. If there is | ||
no possible assignment that works, the program should report that no solution | ||
exists. In the case of multiple solutions, the program should report every | ||
possible solution. | ||
|
||
The islanders can make four different classes of utterances: | ||
|
||
X is a knight. | ||
X is a knave. | ||
X and Y are of the same type. | ||
X and Y are of different types. | ||
|
||
(Here, X and Y are used as metavariables, of course, and can in fact be any | ||
name of an islander.) | ||
|
||
Islanders can refer to each other. The same islander can make several | ||
utterances. If an islander mentions another islander that doesn't say anything, | ||
your program should consider the entire input to be erroneous. | ||
|
||
Here are a few examples: | ||
|
||
A: A is a knight. | ||
|
||
Both a knight and a knave would assert the same thing. So this input has two | ||
solutions. | ||
|
||
B: B is a knave. | ||
|
||
Neither a knight or a knave would ever say this about themselves. So this input | ||
allows no solution. | ||
|
||
C: C and D are of the same type. | ||
D: D and C are of different types. | ||
|
||
Here, the two islanders are contradicting each other, so one of them must be a | ||
knight and the other a knave. But this is exactly what D is saying, so D is the | ||
knight. One solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#! /usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More tests => 5; | ||
|
||
my $code_file = 'code'; | ||
$ENV{PERL6LIB} = 'lib'; | ||
my $perl6 = $ENV{PERL6EXECUTABLE} || 'perl6'; | ||
|
||
sub run { | ||
my $output = `$perl6 $code_file 2>&1`; | ||
|
||
return $output; | ||
} | ||
|
||
sub conforms { | ||
my ($output) = @_; | ||
|
||
# A haiku has three lines | ||
my @lines = split /\n/, $output; | ||
return unless @lines == 3; | ||
|
||
# All lines should be of the same length | ||
return unless length($lines[0]) == length($lines[1]) | ||
&& length($lines[0]) == length($lines[2]); | ||
|
||
# No double spaces | ||
return if $output =~ / /; | ||
|
||
# No punctuation | ||
$output =~ s/[[:alpha:]]//g; | ||
$output =~ s/ //g; | ||
$output =~ s/\n//g; | ||
return if $output; | ||
|
||
return 1; | ||
} | ||
|
||
die qq[NO FILE "$code_file"] | ||
unless -e $code_file; | ||
|
||
die qq[\nFILE "$code_file" DOES NOT COMPILE] | ||
if system("$perl6 -c $code_file > /dev/null"); | ||
|
||
# Let's just test it five times | ||
for (1..5) { | ||
ok conforms(run); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## Generate rectangle haikus | ||
|
||
Write a program that generates haikus. A haiku has three lines, where the first | ||
and last lines have five syllables each, and the middle line has seven. For the | ||
purpose of this exercise, each line consists only of letters and spaces. | ||
|
||
The haikus generated have the additional requirement that each line be of equal | ||
length. The length requirement should not be gamed in any way, for example by | ||
padding lines with spaces. | ||
|
||
since this one does it | ||
rectangle plus a haiku | ||
it serves as fine text | ||
|
||
The program should attempt to generate a new haiku each time. The haiku should | ||
consist of English words. If the words make sense in some kind of sentence | ||
structure, that's considered a big bonus. Humor and/or deeper meanings are even | ||
bonuser. | ||
|
||
If you attempt to cheat at this task, you will be defeated by people who don't. | ||
|
||
You're free to supply your own wordlist. How you count syllables is up to you, | ||
and part of the task. You won't be challenged on trivial differences in | ||
syllable counts. | ||
|
||
It's OK for the program to run for a while, but it should preferably terminate | ||
within a reasonable span of time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#! /usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More tests => 2; | ||
|
||
my $code_file = 'code'; | ||
$ENV{PERL6LIB} = 'lib'; | ||
my $perl6 = $ENV{PERL6EXECUTABLE} || 'perl6'; | ||
|
||
sub run { | ||
my ($param) = @_; | ||
|
||
my $output = `$perl6 $code_file $param 2>&1`; | ||
return $output; | ||
} | ||
|
||
sub trim_trailing_space { | ||
my ($line) = @_; | ||
$line =~ s/ +$//; | ||
return $line; | ||
} | ||
|
||
sub trim_trailing_spaces { | ||
my ($text) = @_; | ||
return join "", | ||
map { trim_trailing_space($_) . "\n" } | ||
split "\n", $text; | ||
} | ||
|
||
die qq[NO FILE "$code_file"] | ||
unless -e $code_file; | ||
|
||
die qq[\nFILE "$code_file" DOES NOT COMPILE] | ||
if system("$perl6 -c $code_file > /dev/null"); | ||
|
||
is trim_trailing_spaces(run("0123456789")), <<'OUTPUT'; | ||
0 __ 0 | ||
1 __ 1 | ||
2 __ 2 | ||
3 __ 3 | ||
4 __ 4 | ||
5 __ 5 | ||
6 __ 6 | ||
7 __ 7 | ||
8 __ 8 | ||
9 __ 9 | ||
OUTPUT | ||
|
||
is trim_trailing_spaces(run("0123456798")), <<'OUTPUT'; | ||
0 ____ 0 | ||
1 ____ 1 | ||
2 ____ 2 | ||
3 ____ 3 | ||
4 ____ 4 | ||
5 ____ 5 | ||
6 ____ 6 | ||
7 ____ 7 | ||
8 _ _ 9 | ||
\/ | ||
9 _/\_ 8 | ||
OUTPUT |
Oops, something went wrong.