十字の壁がそそり立つ世界の中を君は螺旋状に歩く (規則性、Crystal/Perl6)

問題 http://nabetani.sakura.ne.jp/hena/ord28spirwa/
シミュレーション (Python/Ruby/C++) http://qiita.com/cielavenir/items/8c77a158136bd668a27b
規則性 (Python/Ruby/C/C#/Java) http://qiita.com/cielavenir/items/a285b0cea4a26ff886b8
規則性 (D/Go/Swift/PHP/ Vala ) http://qiita.com/cielavenir/items/edb1daff9ea861a418ec
規則性 (VB/F#/Perl) http://qiita.com/cielavenir/items/0c84af4049ab161f82c1
規則性 (PowerShell) http://qiita.com/cielavenir/items/d9ef9f12068e99e888f2
規則性 ( AIR-lang ) http://qiita.com/cielavenir/items/d804f61412fb4f07ba06
規則性 (Crystal/Perl6) http://qiita.com/cielavenir/items/13896a662b05da8b77a2
Rubyの多次元配列で最初の要素を加工して返したい
(tap/break等について)
http://qiita.com/cielavenir/items/3f209351b924e2615f5e

完全についでですなこりゃ

tyama_hena28_fast.cr
#!/usr/bin/env crystal
#http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
#http://nabetani.sakura.ne.jp/hena/ord28spirwa/

dir="ESWN"
while l_=gets
    line=l_.chomp.split(':')
    n,e,s,w=line[0].split(',').map(&.to_i64)
    l=[e,s,w,n]
    days=line[1].to_i64+1
    (0..1/0.0).each{|i|
        [
            l[i%4]+(i%4==0 ? 1 : 0),
            (i/4+1)*2,
            l[i%4]-(i%4==3 ? 1 : 0),
        ].each_with_index{|e,j|
            days-=e
            if days<0
                puts dir[(i+j)%4]
                break
            end
        }
        break if days<0
    }
    STDOUT.flush
end
tyama_hena28_fast.p6
#!/usr/bin/env perl6
# http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
# http://nabetani.sakura.ne.jp/hena/ord28spirwa/

$*OUT.out-buffer=False;
my $dir="ESWN";
loop (;my $line=get();) {
    $line ~~ /^(\d+)","(\d+)","(\d+)","(\d+)":"(\d+)/;
    my $n=+$0;
    my $e=+$1;
    my $s=+$2;
    my $w=+$3;
    my $days=+$4+1;
    my @l=($e,$s,$w,$n);
    my $f=1;
    loop (my $i=0;$f;$i++) {
        my $j=0;
        my @x=(@l[$i%4]+($i%4==0),($i/4 +< 1)+2,@l[$i%4]-($i%4==3));
        loop ($j=0;$j < 3;$j++) {
            if ($days-@x[$j] < 0) {
                say substr($dir,($i+$j)%4,1);
                $f=0;
                last;
            }
            $days-=@x[$j];
        }
    }
    #$*OUT.flush();
}

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.