[QUIZ] Mexican Blanket (#127) Problem

A

Ari Brown

Hey all,
I was attempting Mexican Blanket today, and found it to be more of a
brain teaser (for me) than a coding problem.

Which doesn't mean there were no coding problems.

I keep getting an error for the Integer#times method. I think I'm
using it right, but could someone help me correct it please?

Also, do I have my shebang setup correctly to type ./
mexican_blanket.rb ETC and have it run? Because I can never seem to
get it to work.

------------------------------------------------------------------|
Error
------------------------------------------------------------------|
mexican_blanket.rb:21:in `weave': undefined method `times' for
"25":String (NoMethodError)
from mexican_blanket.rb:15:in `initialize'
from mexican_blanket.rb:49:in `new'
from mexican_blanket.rb:49

------------------------------------------------------------------|
Code
------------------------------------------------------------------|
#!/usr/bin/ruby
#this one is just a test thing. Not gonna do the designs diagonally

class Blanket

def initialize(colors, length, width, pattern_length)
@COLORS = colors.split(//)
@LENGTH = length
@WIDTH = width
@slot = -1
@SLOTS = @COLORS.length
@PL = pattern_length
@mainp = pattern_length
@offp = 1
weave()
end

def weave() # THIS IS LINE 15
@LENGTH.times do |i|
@mainp.times { #build the PATTERN long...
@slot = (@slot + 1)
width_ticker = 0
until width_ticker == @WIDTH #build it wide...
print '#{@COLOR[(@slot % @SLOTS)]}'
width_ticker = width_ticker + 1
ticker = ticker + 1
end
}
end

@offp.times do |i|
@slot = (@slot + 1)
width_ticker = 0
until width_ticker == @WIDTH #build it wide...
print '#{@COLOR[(@slot % @slots)]}'
width_ticker = width_ticker + 1
ticker = ticker + 1
end
end
@mainp = (@mainp + (@PL - 1)) % @PL
@offp = @offp.next % @PL
end
end

colors = ARGV[0]
length = ARGV[1]
width = ARGV[2]
pattern_length = ARGV[3]
mexico = Blanket.new(colors, length, width, pattern_length) #THIS
IS LINE 49
#end
-------------------------------------------|
~aRi
I did my version of it as a top-down pattern as opposed to a diagonal
pattern.
 
H

Harry Kakueki

Hey all,
I was attempting Mexican Blanket today, and found it to be more of a
brain teaser (for me) than a coding problem.

Which doesn't mean there were no coding problems.

I keep getting an error for the Integer#times method. I think I'm
using it right, but could someone help me correct it please?

------------------------------------------------------------------|
mexican_blanket.rb:21:in `weave': undefined method `times' for
"25":String (NoMethodError)
from mexican_blanket.rb:15:in `initialize'
from mexican_blanket.rb:49:in `new'
from mexican_blanket.rb:49

------------------------------------------------------------------|

It looks like "25" is a String. You need to change it to an Integer.

colors = ARGV[0]
length = ARGV[1]
width = ARGV[2]
pattern_length = ARGV[3]
p width.class # Add this line and take a look

mexico = Blanket.new(colors, length, width, pattern_length)

You may want to check the others, too.

Harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top