4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paizaの問題の答えをAIに頼んで別言語に書き換えさせようという試みです。
Pythonの解答をPowerShellに書き換えさせてみます。

paizaとは

ブラウザ上でコードを書いて実行できる、無料プログラミング練習問題集です。

  • 難易度別に問題を選ぶ
  • 問題文を読んで、解答コードを書く
  • 提出するとテストケースが実行されて結果をわかる
  • 正解・不正解だけではなく、解答コード例や解説も見ることができるので、プログラミングの習得から復習まで活用できます

こんな人におすすめ

  • プログラミングスキルの腕試しをしたい方
  • プログラミングのスキルアップしたい方
  • 新しい言語にチャレンジをしたい方

問題

Bランク相当 神経衰弱

Pythonでの解答

h, w, n = map(int, input().split())

cards = [None] * h
player = [0] * n
jun = 0

for i in range(h):
	cards[i] = list(map(int, input().split()))

l = int(input())

for i in range(l):
	b, a, B, A = map(int, input().split())
	num1 = cards[b - 1][a - 1]
	num2 = cards[B - 1][A - 1]
	if num1 == num2:
		player[jun % n] += 2
		cards[b - 1][a - 1] = 0
		cards[B - 1][A - 1] = 0
	else:
		jun += 1

for i in player:
	print(i)

↑これを元にAIへ質問を投げます。

「PythonのプログラムをPowerShellに書き換えてよ」

AIの解答:

# Python: h, w, n = map(int, input().split())
$input = Read-Host
$h, $w, $n = $input -split " " | ForEach-Object { [int]$_ }

# Python: cards = [None] * h
$cards = @()
for ($i = 0; $i -lt $h; $i++) {
    # Python: cards[i] = list(map(int, input().split()))
    $line = Read-Host -split " " | ForEach-Object { [int]$_ }
    $cards += ,$line
}

# Python: player = [0] * n
$player = @(0) * $n
$jun = 0

# Python: l = int(input())
$l = [int](Read-Host)

for ($i = 0; $i -lt $l; $i++) {
    # Python: b, a, B, A = map(int, input().split())
    $input = Read-Host -split " " | ForEach-Object { [int]$_ }
    $b, $a, $B, $A = $input

    # Python: num1 = cards[b - 1][a - 1]
    #         num2 = cards[B - 1][A - 1]
    $num1 = $cards[$b - 1][$a - 1]
    $num2 = $cards[$B - 1][$A - 1]

    if ($num1 -eq $num2) {
        # Python: player[jun % n] += 2
        $player[$jun % $n] += 2

        # Python: cards[b - 1][a - 1] = 0
        #         cards[B - 1][A - 1] = 0
        $cards[$b - 1][$a - 1] = 0
        $cards[$B - 1][$A - 1] = 0
    } else {
        # Python: jun += 1
        $jun+=1
    }
}

# Python: for i in player:
#             print(i)
$player | ForEach-Object { Write-Output $_ }

解説:

ココが違う!
$h, $w, $n = $input -split " " | ForEach-Object { [int]$_ }

正解は

$h, $w, $n = $input.split() | ForEach-Object { [int]$_ }

PowerShellでは「input -split " " 」こんな書き方はできません

ココが違う!
$b, $a, $B, $A = $input

正解は

$B1, $A1, $B2, $A2 = $input

PowerShellでは変数名アルファベットの大文字・小文字の区別が無いので変数Aと変数aが同じになってしまいます。
変数名をB1, A1, B2, A2 と書き換えました。

全部書き直したのがこちら

# Python: h, w, n = map(int, input().split())
$input = Read-Host
$h, $w, $n = $input.split() | ForEach-Object { [int]$_ }

# Python: cards = [None] * h
$cards = @()
for ($i = 0; $i -lt $h; $i++) {
    # Python: cards[i] = list(map(int, input().split()))
    $line = (Read-Host).split() | ForEach-Object { [int]$_ }
    $cards += ,$line
}

# Python: player = [0] * n
$player = @(0) * $n
$jun = 0

# Python: l = int(input())
$l = [int](Read-Host)

for ($i = 0; $i -lt $l; $i++) {
    # Python: b, a, B, A = map(int, input().split())
    $input = (Read-Host).split() | ForEach-Object { [int]$_ }
    $B1, $A1, $B2, $A2 = $input

    # Python: num1 = cards[b - 1][a - 1]
    #         num2 = cards[B - 1][A - 1]
    $num1 = $cards[$B1 - 1][$A1 - 1]
    $num2 = $cards[$B2 - 1][$A2 - 1]

    if ($num1 -eq $num2) {
        # Python: player[jun % n] += 2
        $player[$jun % $n] += 2

        # Python: cards[b - 1][a - 1] = 0
        #         cards[B - 1][A - 1] = 0
        $cards[$B1 - 1][$A1 - 1] = 0
        $cards[$B2 - 1][$A2 - 1] = 0
    } else {
        # Python: jun += 1
        $jun+=1
    }
}

# Python: for i in player:
#             print(i)
$player | ForEach-Object { Write-Output $_ }

まとめ

AI、AIと騒がれていますけどまだ全然ですね。
動かないプログラムを提出してくるのはダメですよね。

AIに他の問題もやらせてみましたけど『PowerShellでは、変数名のアルファベット大文字・小文字の区別が無い』が分らんみたいです。初心者がツマヅキそうなポイントではあるけど、膨大な量を学習しているのなら、致命的な欠陥。

4
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
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?