開発環境
- macOS Catalina - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Go (プログラミング言語)
入門Goプログラミング (Nathan Youngman(著)、Roger Peppé(著)、吉川 邦夫(監修, 翻訳)、翔泳社)のUNIT 4(コレクション)、LESSON 16(配列)の練習問題の解答を求めてみる。
コード
package main
import "fmt"
func printChessboard(chessboard [8][8]rune) {
for _, row := range chessboard {
for _, col := range row {
fmt.Printf("%1c", col)
}
fmt.Println()
}
}
func main() {
var chessboard [8][8]rune
chessboard[0][0] = 'r'
chessboard[0][1] = 'n'
chessboard[0][2] = 'b'
chessboard[0][3] = 'q'
chessboard[0][4] = 'k'
chessboard[0][5] = 'b'
chessboard[0][6] = 'n'
chessboard[0][7] = 'r'
for i := range chessboard[1] {
chessboard[1][i] = 'p'
}
for i := range chessboard[6] {
chessboard[6][i] = 'P'
}
chessboard[7][0] = 'R'
chessboard[7][1] = 'N'
chessboard[7][2] = 'B'
chessboard[7][3] = 'Q'
chessboard[7][4] = 'K'
chessboard[7][5] = 'B'
chessboard[7][6] = 'N'
chessboard[7][7] = 'R'
printChessboard(chessboard)
}
入出力結果(Zsh、PowerShell、Terminal)
% go run ./chess.go
rnbqkbnr
pppppppp
PPPPPPPP
RNBQKBNR
%
0 コメント:
コメントを投稿