From: Todd Benson Date: 2008-03-08T04:01:11+09:00 Subject: Re: Class and inheritance On Thu, Mar 6, 2008 at 7:20 PM, August0866 wrote: > On Mar 5, 4:36 am, Todd Benson wrote: > > > On Wed, Mar 5, 2008 at 3:08 AM, Todd Benson wrote: > > > Least common denominator? > > > > I should point out, too, that my use of #min only works if you want to > > pick the first on the list that fits. Maybe what you really want are > > _all_ the jobs that apply for a person. > > > > Todd > > Wow Crunchy code. it will take ma awhile to decipher all the things > going on up there. > > originally the idea was first match out. I think that approach may > not be where i end up in the end. > > thanks again for the help With comments... require 'matrix' #need this for Matrix class joblist = ['adventurer', 'courier'] attributes = ['power', 'smarts', 'speed'] n, j = attributes.length, joblist.length a = [[14, 14, 14], [14, 10, 14]] #cheating here, need Hash really some_poor_guys_stats_copies = Array.new(j, Array.new(n) {rand(20) + 1}) #an array of arrays to be a matrix s = Matrix[*some_poor_guys_stats_copies] #make the requirements Matrix #using e for "employment", bad choice e = Matrix[*a] poss = [] #using poss for possibilities, bad choice (s - e).to_a.each_with_index do |v, i| poss << i if (v.select {|j| j >= 0}).length == n end p joblist[poss.min] rescue p "Commoner" Okay, the key here is: I have two matrices of same dimensions. I take the guys stats, subtract the requirements, and remove anything that is negative in each ability check. I'm not certain at the moment how I would clean that up for production use, but I have a few ideas. The only dodgy part of the code (discounting the variable names), IMHO, is the a = [[14, 14, 14], [14, 10, 14]] part. Not because of the logic, but because of the fact we're depending on the order of the array called "a". Like, what if somebody changes the attributes array? A Hash object would fit better here even if it requires more code. hth, Todd