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


|問題|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の多次元配列で最初の要素を加工して返したい<br>(tap/break等について)|http://qiita.com/cielavenir/items/3f209351b924e2615f5e|

入出力の練習ということで。
scanfがない言語は省略。

```d:hena28_fast.d
#!/usr/bin/env rdmd
// http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
// http://nabetani.sakura.ne.jp/hena/ord28spirwa/

import std.c.stdio;

int main(){
	const char* dir="ESWN";
	int n,e,s,w;
	long days;
	for(;~scanf("%d,%d,%d,%d:%lld",&n,&e,&s,&w,&days);){
		days+=1;
		int[] l=[e,s,w,n];
		int f=1;
		for(int i=0;f;i++){
			int[] x=[l[i%4]+(i%4==0),(i/4+1)*2,l[i%4]-(i%4==3)];
			for(int j=0;j<3;j++){
				if(days-x[j]<0){
					printf("%c\n",dir[(i+j)%4]);
					f=0;
					break;
				}
				days-=x[j];
			}
		}
		fflush(stdout);
	}
	return 0;
}
```

```go:hena28_fast.go
//usr/bin/env go run $0 $@;exit
// http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
// http://nabetani.sakura.ne.jp/hena/ord28spirwa/

package main
import (
	"fmt"
	"os"
)

func main(){
	dir:="ESWN";
	n:=0;e:=0;s:=0;w:=0;
	var days int64;
	for ;; {
		c,_:=fmt.Scanf("%d,%d,%d,%d:%d",&n,&e,&s,&w,&days)
		if c<5 {break}
		days+=1
		l:=[4]int{e,s,w,n}
		f:=1
		for i:=0;f!=0;i++ {
			x:=[3]int{l[i%4]+((i+3)%4/3),(i/4+1)*2,l[i%4]-(i%4/3)}
			for j:=0;j<3;j++ {
				if days-int64(x[j])<0 {
					fmt.Printf("%c\n",dir[(i+j)%4])
					f=0
					break
				}
				days-=int64(x[j])
			}
		}
		os.Stdout.Sync()
	}
}
```

```swift:hena28_fast.swift
//usr/bin/env xcrun swift $0 $@;exit
// http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
// http://nabetani.sakura.ne.jp/hena/ord28spirwa/

import Darwin
let dir="ESWN"
var	n=0,e=0,s=0,w=0;
var days: Int64=0
for ;(withUnsafePointer(&n){vscanf("%d",getVaList([COpaquePointer($0)]))}>0); {
	withUnsafePointer(&e){vscanf(",%d",getVaList([COpaquePointer($0)]))}
	withUnsafePointer(&s){vscanf(",%d",getVaList([COpaquePointer($0)]))}
	withUnsafePointer(&w){vscanf(",%d",getVaList([COpaquePointer($0)]))}
	withUnsafePointer(&days){vscanf(":%lld",getVaList([COpaquePointer($0)]))}
	days+=1
	let l=[e,s,w,n]
	var	f=1
	for var i=0;f != 0;i++ {
		let a=l[i%4]+((i+3)%4/3)
		let b=(i/4+1)*2
		let c=l[i%4]-(i%4/3)
		let x=[a,b,c]
		for var j=0;j<3;j++ {
			if days-x[j]<0 {
				println(dir[advance(dir.startIndex,(i+j)%4)])
				f=0
				break
			}
			days-=x[j]
		}
	}
	fflush(stdout)
}
```

```php:hena28_fast.php
#!/usr/bin/php
<?php
// http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
// http://nabetani.sakura.ne.jp/hena/ord28spirwa/

$dir="ESWN";
$n=0;$e=0;$s=0;$w=0;
$days=0;
for(;fscanf(STDIN,"%d,%d,%d,%d:%d",$n,$e,$s,$w,$days)==5;){
	$days+=1;
	$l=array($e,$s,$w,$n);
	$f=1;
	for($i=0;$f;$i++){
		$x=array($l[$i%4]+($i%4==0),($i/4<<1)+2,$l[$i%4]-($i%4==3));
		for($j=0;$j<3;$j++){
			if($days-$x[$j]<0){
				echo $dir[($i+$j)%4].PHP_EOL;
				$f=0;
				break;
			}
			$days-=$x[$j];
		}
	}
	fflush(STDOUT);
}
```

```vala:hena28_fast.vala
#!/usr/bin/env vala
//http://qiita.com/Nabetani/items/23ebddb44f0234e7fb15
//http://nabetani.sakura.ne.jp/hena/ord28spirwa/
static void main(){
	string dir="ESWN";
	int n=0,e=0,s=0,w=0;
	int64 days=0;
	for(;stdin.scanf("%d,%d,%d,%d:%"+int64.FORMAT_MODIFIER+"d",&n,&e,&s,&w,&days)!=-1;){
		days+=1;
		int[] l={e,s,w,n};
		int i=0,j,f=1;
		for(;f!=0;i++){
			int[] x={l[i%4]+(i%4==0?1:0),(i/4+1)*2,l[i%4]-(i%4==3?1:0)};
			for(j=0;j<3;j++){
				if(days-x[j]<0){
					stdout.printf("%c\n",dir[(i+j)%4]);
					f=0;
					break;
				}
				days-=x[j];
			}
		}
		stdout.flush();
	}
}
```