[過去ログ] プログラミングのお題スレ Part13 (1002レス)
前次1-
抽出解除 レス栞

このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
リロード規制です。10分ほどで解除するので、他のブラウザへ避難してください。
746
(7): 2019/03/21(木)13:37 ID:p+hkSRzH(1)調 AAS
お題
長方形の盤で左上から上下左右に一マスずつ移動して全てのマスを
辿る。
移動の順番を表した数字を向きと終点を表す文字(↑↓←→★、
上下左右終、UDLRG、^V<>Gなど)に変換する。

入力
1 4 5 6
2 3 8 7
15 14 9 10
16 13 12 11

出力
↓→→↓
→↑↓←
↓←→↓
★↑←←
747
(1): 2019/03/21(木)14:37 ID:Krn8F3T2(1)調 AAS
>>746 Perl5
@a = map{[split]} <DATA>;
for $y (0..$#a) {
 $h{$a[$y][$_]} = [$y,$_,''] for 0..$#a;
}
@s = keys %h;
%r = qw{-1,0 ↑ 1,0 ↓ 0,-1 ← 0,1 →};
for $i (1..@s) {
 if ($i == @s) {
  $d = '★'
 } else {
  $y = $h{$i+1}->[0] - $h{$i}->[0];
  $x = $h{$i+1}->[1] - $h{$i}->[1];
  $d = $r{"$y,$x"}
 }
 $h{$i}->[2] = $d;
}
($y, $x, $d) = @$_, $a[$y][$x] = $d for values %h;
use feature say;
say "@$_" for @a;
__DATA__
1 4 5 6
2 3 8 7
15 14 9 10
16 13 12 11

実行結果
~ $ perl 13_746.pl
↓ → → ↓
→ ↑ ↓ ←
↓ ← → ↓
★ ↑ ← ←
749
(1): 2019/03/22(金)05:04 ID:NMDgNTgg(1)調 AAS
>>746
Kotlin
https://paiza.io/projects/kKx0DA0gpsZ6He2ZxKSF_A
750: 2019/03/22(金)12:12 ID:bmKj2SZK(1)調 AAS
>>746 Squeak Smalltalk

| fn |

fn := [:str |
| map range sign goal position next atEnd |
map := str lines collect: [:line | line subStrings collect: #asInteger].
range := 1@1 extent: map first size @ map size.
sign := (0 asPoint fourNeighbors with: #(→ ↓ ← ↑) collect: #->) as: Dictionary.
goal := #★.
position := 1@1. next := 2. atEnd := false.
[atEnd] whileFalse: [
| found |
found := position fourNeighbors detect: [:neighPos |
(range containsPoint: neighPos) and: [((map at: neighPos y) at: neighPos x) = next]
] ifNone: [atEnd := true. Float nan].
(map at: position y) at: position x put: (sign at: found - position ifAbsent: goal).
position := found. next := next + 1.
].
(map collect: #join) asStringWithCr
].

fn value: '1 4 5 6
2 3 8 7
15 14 9 10
16 13 12 11'

"=>
'↓→→↓
→↑↓←
↓←→↓
★↑←←' "
751: 2019/03/22(金)20:50 ID:KB/r9SyN(1)調 AAS
>>746 octave
https://ideone.com/BacNm6
758: 2019/03/23(土)02:35 ID:FcxASXew(1)調 AAS
>>746 Common Lisp
https://ideone.com/7h7HT4
764: 2019/03/24(日)01:17 ID:TWBa+gHA(1/2)調 AAS
>>746 C
https://ideone.com/dQ2NRt
行けないところがある場合■で表示した
772: 2019/03/24(日)22:58 ID:3fqiTHWE(1)調 AAS
ちなみに、

>>746
の問題で、行列の周りに、番兵を作って、処理した人はいる?

漏れは、いつもこの手の問題では、番兵で周りを囲む
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.049s