Last active
August 29, 2015 14:14
-
-
Save hiratara/8110e156360d358cb041 to your computer and use it in GitHub Desktop.
An answer for http://nabetani.sakura.ne.jp/hena/ord28spirwa/
This file contains hidden or 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
package Answer; | |
use strict; | |
use warnings; | |
use Exporter qw(import); | |
our @EXPORT_OK = qw(solve); | |
sub directions ($$$$$) { | |
my ($n, $e, $s, $w, $t) = @_; | |
my @directions = ( | |
[e => $e], | |
[s => $t + 1], | |
[w => $e], | |
[s => $s], | |
[w => $t + 1], | |
[n => $s], | |
[w => $w], | |
[n => $t + 1], | |
[e => $w], | |
[n => $n], | |
[e => $t + 1], | |
[s => $n - 1], | |
[e => 1] | |
); | |
} | |
sub solve ($) { | |
my ($n, $e, $s, $w, $days) = split /[,:]/, $_[0]; | |
my $t = 1; | |
my $d; | |
while ($days >= 0) { | |
my @directions = directions($n, $e, $s, $w, $t); | |
while ($days >= 0 and $d = shift @directions) { | |
$days -= $d->[1]; | |
} | |
$t += 2; | |
} | |
return uc($d->[0]); | |
} | |
1; |
This file contains hidden or 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
use strict; | |
use warnings; | |
use Test::More; | |
use Answer qw(solve); | |
while (<DATA>) { | |
tr/\r\n//d; | |
my ($no, $input, $expected) = split /\t/, $_, 4; | |
is solve $input, $expected, "test #$no"; | |
} | |
done_testing; | |
__END__ | |
0 2,3,5,4:85 S | |
1 1,2,3,4:1 E | |
2 1,2,3,4:2 S | |
3 1,2,3,4:3 S | |
4 1,2,3,4:4 W | |
5 1,2,3,4:27 E | |
6 1,2,3,4:63 E | |
7 1,2,3,4:40 W | |
8 1,4,3,2:40 S | |
9 3,3,3,3:30 S | |
10 3,3,3,3:31 E | |
11 3,3,3,3:32 E | |
12 3,3,3,3:70 S | |
13 3,3,3,3:71 E | |
14 3,3,3,3:72 E | |
15 1,1,1,1:7 N | |
16 1,2,1,1:7 W | |
17 1,6,1,1:7 S | |
18 1,8,1,1:7 E | |
19 1,1,1,1:30 N | |
20 1,2,1,1:30 W | |
21 1,5,1,1:30 S | |
22 1,8,1,1:30 E | |
23 9,9,9,9:99 W | |
24 5,6,3,8:3 E | |
25 5,8,1,1:11 W | |
26 2,8,1,2:18 S | |
27 3,2,3,1:20 N | |
28 3,3,8,1:28 N | |
29 2,5,1,2:32 E | |
30 2,5,1,6:33 E | |
31 1,2,5,7:34 N | |
32 3,6,5,6:36 E | |
33 6,2,8,1:39 S | |
34 3,1,2,3:41 W | |
35 1,1,3,4:45 W | |
36 1,3,1,2:46 N | |
37 4,4,4,4:49 W | |
38 3,1,4,4:55 N | |
39 6,6,2,1:56 W | |
40 3,2,1,2:59 S | |
41 2,7,7,1:60 S | |
42 3,1,1,1:63 N | |
43 4,6,4,1:78 E | |
44 7,5,3,6:79 W | |
45 7,8,3,1:81 E | |
46 3,2,5,2:82 S | |
47 1,1,3,4:84 N | |
48 7,4,1,5:88 S | |
49 3,6,5,3:89 S | |
50 1,4,2,3:92 N | |
51 1,3,4,5:93 W | |
52 2,4,8,1:94 W | |
53 3,6,1,7:99 S | |
54 1234,2345,3456,4567:978593417 E | |
55 1234,2345,3456,4567:978593418 S | |
56 31415,92653,58979,32384:9812336139 W | |
57 31415,92653,58979,32384:9812336140 S | |
58 314159,265358,979323,84626:89099331642 S | |
59 314159,265358,979323,84626:89099331643 W |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment