Sha256: 54523733fe566399d65b138d693888b2923803f4622fde39e32aa9244616bfa8

Contents?: true

Size: 1.32 KB

Versions: 329

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

329 entries across 329 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.179 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.178 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.177 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.176 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.175 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.174 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.173 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.172 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.171 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.170 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.169 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.167 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.166 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.165 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.164 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.163 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.162 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.161 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb
trackler-2.2.1.160 tracks/ruby/exercises/diamond/.meta/solutions/diamond.rb