Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created February 5, 2013 03:57
Show Gist options
  • Save kmandreza/4712043 to your computer and use it in GitHub Desktop.
Save kmandreza/4712043 to your computer and use it in GitHub Desktop.
class Crossword
attr_accessor :line1, :line2, :line3, :line4, :line5, :line6
def initialize(layout)
layout_array = layout.split("\n")
@line1 = layout_array[0]
@line2 = layout_array[1]
@line3 = layout_array[2]
@line4 = layout_array[3]
@line5 = layout_array[4]
@line6 = layout_array[5]
end
def line1_translate
array_for_now = @line1.split("")
array_for1 = Array.new(7) {array_for_now.shift(1)}
array_for1.each do |small_array|
if small_array[0] == "X"
small_array[0] = ["######", "######", "######", "######"]
else
small_array[0] = ["######", "# #", "# #", "######"]
end
end
array_for1.flatten!(1)
n = 1
6.times do
array_for1[0].length.times do |index|
array_for1[0][index].chomp!("#")
array_for1[0][index] += array_for1[n][index]
end
n += 1
end
array_for1[0]
end
def line2_translate
array_for_now = @line2.split("")
array_for2 = Array.new(7) {array_for_now.shift(1)}
array_for2.each do |small_array|
if small_array[0] == "X"
small_array[0] = ["######", "######", "######"]
else
small_array[0] = ["# #", "# #", "######"]
end
end
array_for2.flatten!(1)
n = 1
6.times do
array_for2[0].length.times do |index|
array_for2[0][index].chomp!("#")
array_for2[0][index] += array_for2[n][index]
end
n += 1
end
array_for2[0]
end
def line3_translate
array_for_now = @line3.split("")
array_for3 = Array.new(7) {array_for_now.shift(1)}
array_for3.each do |small_array|
if small_array[0] == "X"
small_array[0] = ["######", "######", "######"]
else
small_array[0] = ["# #", "# #", "######"]
end
end
array_for3.flatten!(1)
n = 1
6.times do
array_for3[0].length.times do |index|
array_for3[0][index].chomp!("#")
array_for3[0][index] += array_for3[n][index]
end
n += 1
end
array_for3[0]
end
def line4_translate
array_for_now = @line4.split("")
array_for4 = Array.new(7) {array_for_now.shift(1)}
array_for4.each do |small_array|
if small_array[0] == "X"
small_array[0] = ["######", "######", "######"]
else
small_array[0] = ["# #", "# #", "######"]
end
end
array_for4.flatten!(1)
n = 1
6.times do
array_for4[0].length.times do |index|
array_for4[0][index].chomp!("#")
array_for4[0][index] += array_for4[n][index]
end
n += 1
end
array_for4[0]
end
def line5_translate
array_for_now = @line5.split("")
array_for5 = Array.new(7) {array_for_now.shift(1)}
array_for5.each do |small_array|
if small_array[0] == "X"
small_array[0] = ["######", "######", "######"]
else
small_array[0] = ["# #", "# #", "######"]
end
end
array_for5.flatten!(1)
n = 1
6.times do
array_for5[0].length.times do |index|
array_for5[0][index].chomp!("#")
array_for5[0][index] += array_for5[n][index]
end
n += 1
end
array_for5[0]
end
def line6_translate
array_for_now = @line6.split("")
array_for6 = Array.new(7) {array_for_now.shift(1)}
array_for6.each do |small_array|
if small_array[0] == "X"
small_array[0] = ["######", "######", "######"]
else
small_array[0] = ["# #", "# #", "######"]
end
end
array_for6.flatten!(1)
n = 1
6.times do
array_for6[0].length.times do |index|
array_for6[0][index].chomp!("#")
array_for6[0][index] += array_for6[n][index]
end
n += 1
end
array_for6[0]
end
def print_crossword
puts line1_translate
puts line2_translate
puts line3_translate
puts line4_translate
puts line5_translate
puts line6_translate
end
end
try_it = Crossword.new("X____XX\n__X____\n____X__\n_X__XXX\n___X___\nX_____X")
try_it.print_crossword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment