patternrubyMinor
Printing a Tic-Tac-Toe board in Ruby
Viewed 0 times
toetictacprintingrubyboard
Problem
I have two implementations of a function that prints out a basic board for Tic-Tac-Toe.
Which of these should I include and why?
Which of these should I include and why?
def display_board(board)
for i in 0...9
print " #{ board[i] }"
if (i+1)%3 != 0
print " |"
elsif i != 9
print " \n#{'-'*11}\n"
end
end
enddef display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
endSolution
Surely version two.
-
It makes no use of control structures such as
-
It lets you see in a single glance what the output will look like.
-
It makes no use of control structures such as
for or if, it has very low Kolmogorov complexity because of that, and it is good, as it is directly related to difficulty in understanding.-
It lets you see in a single glance what the output will look like.
Context
StackExchange Code Review Q#108196, answer score: 4
Revisions (0)
No revisions yet.