Skip to content

Hw03 chessboard#4

Merged
chepsel merged 3 commits intomasterfrom
hw03_chessboard
Jan 10, 2024
Merged

Hw03 chessboard#4
chepsel merged 3 commits intomasterfrom
hw03_chessboard

Conversation

@chepsel
Copy link
Copy Markdown
Owner

@chepsel chepsel commented Dec 26, 2023

Домашнее задание №3 «Шахматная доска»

  • Напишите программу, создающую строку, содержащую решётку 8х8, в которой линии разделяются символами новой строки.
  • На каждой позиции либо пробел, либо #.
  • В результате должна получиться шахматная доска.
  • Сделайте размер доски переменным, чтобы можно было создавать доски любого размера. Размер доски настраивать через считывание ввода пользователя


func checkBoard(s int) (result string) {
h, w := s, s
var line string
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Писать все в строку не самый лучший вариант, так как строка в go неизменяемый тип данных. И при каждом сложение строк происходит выделение памяти и копирование данных. Лучше было бы либо сразу писать к консоль, либо использовать strings.Builder

func makeLine(w int, uneven bool) (line string) {
for i := 0; i < w; i++ {
switch {
case i%2 == 0 && uneven:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Условие слишком переусложнено.

@chepsel chepsel closed this Jan 10, 2024
@chepsel chepsel reopened this Jan 10, 2024
@chepsel chepsel merged commit 014148f into master Jan 10, 2024
@chepsel chepsel deleted the hw03_chessboard branch January 17, 2024 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants