Skip to content

Instantly share code, notes, and snippets.

@onli
Created December 6, 2012 21:37
Show Gist options
  • Save onli/4228709 to your computer and use it in GitHub Desktop.
Save onli/4228709 to your computer and use it in GitHub Desktop.
stops after until-loop if i reaches @cpus.size. why?
def getBetter()
puts "getBetter"
puts "@cpus.length: #{@cpus.length}"
puts "current cpu: #{self.cpu.type}"
begin
i = @cpus.index(self.cpu) + 0 # this only works if cpu is taken from this instance of @cpus
rescue Exception => e
@cpus.each do |cpu|
if cpu.type == self.cpu.type
i = @cpus.index(cpu)
break
end
end
puts "rescue-end"
end
puts "after cpu-rescue"
until i > @cpus.size
i += 1
puts "i: #{i}"
puts "#{@cpus[i].type}"
puts "self.cpu.normalizedRating: #{self.cpu.normalizedRating}"
puts " @cpus[i].normalizedRating: #{@cpus[i].normalizedRating}"
if @cpus[i].normalizedRating > self.cpu.normalizedRating
puts "setting cpu to: #{@cpus[i].type}"
cpu = @cpus[i]
# @cpus and @gpus are sorted by price, so the first better one is good enough
puts "breaking"
break
end
end
puts "done with cpus"
begin
i = @gpus.index(self.gpu) + 0
rescue Exception => e
@gpus.each do |gpu|
if gpu.type == self.gpu.type
i = @gpus.index(gpu)
break
end
end
end
puts "i: #{i}"
puts "@gpus.size: #{@gpus.size}"
until i > @gpus.size
i += 1
if @gpus[i].normalizedRating > self.gpu.normalizedRating
gpu = @gpus[i]
break
end
end
rec = Recommendation.new
rec.cpu = cpu
rec.gpu = gpu
return rec
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment