LoginSignup
0
0

More than 5 years have passed since last update.

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

Last updated at Posted at 2015-02-17
問題 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

縁起の悪い13言語になってしまいましたが、C++も合わせて14言語ということにしておいて下さい(未定)。
Perlはマッチ展開を初めて使いました。

hena28_fast.vb
' http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
' http://nabetani.sakura.ne.jp/hena/ord28spirwa/

imports System
imports System.Runtime.InteropServices

module Hena28
    <DllImport("c", CallingConvention := CallingConvention.Cdecl)>
    overloads shared function scanf(format as string, byref a as integer, byref b as integer, byref c as integer, byref d as integer, byref e as long) as integer
    end function

    sub Main()
        dim dir as string="ESWN"
        dim n,e,s,w as integer
        dim days as long
        while scanf("%d,%d,%d,%d:%lld",n,e,s,w,days)=5
            days+=1
            dim l as integer()=new integer(){e,s,w,n}
            dim f as boolean=true
            dim i as integer=0
            while f
                dim x as integer()=new integer(){l(i mod 4)+iif(i mod 4=0,1,0),(i\4+1)*2,l(i mod 4)-iif(i mod 4=3,1,0)}
                for j as integer=0 to 2
                    if days-x(j)<0
                        Console.WriteLine(dir((i+j) mod 4))
                        f=false
                        exit for
                    end if
                    days-=x(j)
                next
                i+=1
            end while
            Console.Out.Flush()
        end while
    end sub
end module
hena28_fast.fs
// http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
// http://nabetani.sakura.ne.jp/hena/ord28spirwa/

open System
open System.Runtime.InteropServices

module libc =
 [<DllImport("c", CallingConvention = CallingConvention.Cdecl)>]
 extern int scanf(string format, int& a, int& b, int& c, int& d, int64& e)

let dir="ESWN"
let mutable n=0
let mutable e=0
let mutable s=0
let mutable w=0
let mutable days:int64=0L
while libc.scanf("%d,%d,%d,%d:%lld",&n,&e,&s,&w,&days)=5 do
 days<-days+1L
 let l:int array=[|e;s;w;n|]
 let mutable f=true
 let mutable i=0
 while f do
  let x:int array=[|l.[i%4]+(if i%4=0 then 1 else 0);(i/4+1)*2;l.[i%4]-(if i%4=3 then 1 else 0)|]
  let mutable j=0
  while j<3 && days-int64(x.[j])>=0L do
   days<-days-int64(x.[j])
   j<-j+1
  if j<3 then
   Console.WriteLine(dir.[(i+j)%4])
   f<-false
  i<-i+1
 Console.Out.Flush()
hena28_fast.pl
#!/usr/bin/perl
# http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
# http://nabetani.sakura.ne.jp/hena/ord28spirwa/

use strict;
use warnings;
use feature 'say';
use IO::Handle;
STDOUT->autoflush(1);

my $dir="ESWN";
while(<>){
    my($n,$e,$s,$w,$days)=$_=~/^(\d+),(\d+),(\d+),(\d+):(\d+)$/;
    $days+=1;
    my @l=($e,$s,$w,$n);
    my $f=1;
    for(my $i=0;$f;$i++){
        my @x=($l[$i%4]+($i%4==0),($i/4<<1)+2,$l[$i%4]-($i%4==3));
        for(my $j=0;$j<3;$j++){
            if($days-$x[$j]<0){
                say substr($dir,($i+$j)%4,1);
                $f=0;
                last;
            }
            $days-=$x[$j];
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0