Sha256: 07d7c00adca2802ae66422c7547cfd60ec114b00379c41b81aae799c939ac9e3

Contents?: true

Size: 1.32 KB

Versions: 67

Compression:

Stored size: 1.32 KB

Contents

module Bookkeeping
  VERSION = 1
end
class Diamond
  def self.make_diamond(letter)
    script = ""
    have_reached_middle = false
    space_from_middle = 0
    total_lines = ((letter.ord - 64) * 2 - 1)
    middle = total_lines/2
    letter_char_code = 65
    (0..total_lines - 1).each do |i|
      line = Array.new(total_lines," ")                      # creates a line in each loop
      if i == 0 || i == total_lines - 1                      # placing the letter A in the beginning and end
        line[middle] = "A"
      else
        first_repeated_letter = middle - space_from_middle   # find position and place letters in positions
        second_repeated_letter = middle + space_from_middle
        line[first_repeated_letter] = letter_char_code.chr
        line[second_repeated_letter] = letter_char_code.chr
      end
      script += line.join("") + "\n"
      if i == middle                    #check if reached middle so it can start decrementing position of letters
        have_reached_middle = true
      end
      if !have_reached_middle
        space_from_middle += 1
        letter_char_code += 1
      else
        space_from_middle -= 1
        letter_char_code -= 1
      end
    end                       #end loop
    # puts script             #shows the outputted diamond
    script
  end                          #end method
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
trackler-2.0.6.11 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.10 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.9 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.8 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.7 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.6 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.5 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.4 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.3 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.2 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.1 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.6.0 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.5.18 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.5.17 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.5.16 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.5.15 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.5.14 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.5.13 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.5.12 tracks/ruby/exercises/diamond/example.rb
trackler-2.0.5.11 tracks/ruby/exercises/diamond/example.rb