Re: Class and inheritance



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

.



Relevant Pages

  • Re: [fitsbits] CRPIX clarification
    ... the proposed changes to the new draft FITS ... array indices} that range in value from 1 to NAXISj on axis j. ... Integral pixel coordinate values coincide with the corresponding array ... If anyone objects to the use of the phrase "regular lattice ...
    (sci.astro.fits)
  • Re: newbee need help with code
    ... > Because of probably compatible reasons does the array in VBNet create two ... > One that fits the one indexer commands. ... > are forever -1 and start always with zero. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Organizing data for readability and efficiency
    ... the performance of single look-ups into each (rather than by whether the nature of your data best fits an array or best fits a hash), then I say you are engaging in micro-optimization. ... The difference between array access and hash access is small enough that if you are concerned about it, only actual tests on actual data will be satifactory. ...
    (comp.lang.perl.misc)
  • Re: Array Formula Help -IF / Else clause?
    ... I'm just getting to grips with Array formulae, and one of the formula I ... Creates (and sums) an array of 1s for every ... Isn't the second IF basically the ELSE clause of the first IF? ... I don't understand how this fits my usual ubderstanding of the ELSE ...
    (microsoft.public.excel)