Re: Class and inheritance
- From: Todd Benson <caduceass@xxxxxxxxx>
- Date: Fri, 7 Mar 2008 14:01:11 -0500
On Thu, Mar 6, 2008 at 7:20 PM, August0866 <august0866@xxxxxxxxxxx> wrote:
On Mar 5, 4:36 am, Todd Benson <caduce...@xxxxxxxxx> wrote:
On Wed, Mar 5, 2008 at 3:08 AM, Todd Benson <caduce...@xxxxxxxxx> 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
.
- Follow-Ups:
- Re: Class and inheritance
- From: Marc Heiler
- Re: Class and inheritance
- References:
- Class and inheritance
- From: August0866
- Re: Class and inheritance
- From: Arlen Cuss
- Re: Class and inheritance
- From: F. Senault
- Re: Class and inheritance
- From: August0866
- Re: Class and inheritance
- From: Todd Benson
- Re: Class and inheritance
- From: Todd Benson
- Re: Class and inheritance
- From: August0866
- Re: Class and inheritance
- From: Todd Benson
- Re: Class and inheritance
- From: Todd Benson
- Re: Class and inheritance
- From: August0866
- Class and inheritance
- Prev by Date: Re: duplicating characters in a string
- Next by Date: Re: Monkeypatching is Destroying Ruby
- Previous by thread: Re: Class and inheritance
- Next by thread: Re: Class and inheritance
- Index(es):
Relevant Pages
|