Skip to content

Instantly share code, notes, and snippets.

@sakhtar-git
Created May 9, 2020 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakhtar-git/538849fcbe0acc2d386cc844c91a6c19 to your computer and use it in GitHub Desktop.
Save sakhtar-git/538849fcbe0acc2d386cc844c91a6c19 to your computer and use it in GitHub Desktop.
Coding Question
def shape(x)
j = 0
arr = Array.new(x.to_i){Array.new(x)}
while j < x
i = 0
while i < x
first = j
last = x - (j+1)
if (i == first || i == last)
arr[j][i] = "O"
else
arr[j][i] = "X"
end
i = i+1
end
j = j + 1
end
arr.each {|e| puts e.inspect}
end
shape(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment