Revision: 38184
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 28, 2010 09:59 by openote
Initial Code
class Asciiarray attr_accessor :a, :b def initialize(a = "Hello", b = "World") @a = a @b = b end def create isa = false equal = false if @a.length > @b.length c = @a d = @b.rjust(@a.length) isa = true displacement = @a.length - @b.length elsif @b.length > @a.length c = @a.rjust(@b.length) d = @b displacement = @b.length - @a.length elsif @a.length == @b.length c = @a.rjust(@b.length) d = @b equal = true else puts "Error. Please try again." end @a_array = c.split(//) @b_array = d.split(//) @a_array.length.times do |iterate| q = @a_array[iterate-1] @a_array[iterate-1] = ?q end @b_array.length.times do |iterate| x = @b_array[iterate-1] @b_array[iterate-1] = ?x end if equal == false if isa == true displacement.times do |takeout| @a_array[takeout-1] = 0 end else displacement.times do |takeout| @b_array[takeout-1] = 0 end end end end def operations @c_array = Array.new @a_array.length.times do |iterate| @c_array[iterate] = @a_array[iterate-1] + @b_array[iterate-1] end end def reverseconvert @c_array.length.times do |iterate| if @c_array[iterate-1] > 127 @c_array[iterate-1] = @c_array[iterate-1] % 127 @c_array[iterate-1] = @c_array[iterate-1].chr elsif @c_array[iterate-1] < 32 @c_array[iterate-1] = 32.chr else @c_array[iterate-1] = @c_array[iterate-1].chr end end end def printout lol = @c_array.join puts lol end end i = Asciiarray.new("HI I LIKE PIE", "ANDREW") i.create i.operations i.reverseconvert i.printout
Initial URL
Initial Description
This was an absolute failure. But here it is, if anyone would like to see horrible programming.
Initial Title
ASCII Addition in Ruby
Initial Tags
Initial Language
Ruby