[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] BigInt sluggishness.



Hello all, first off let me just say it's wonderful how friendly and helpful
the folks on this list are...it is much appreciated. Having said that I hope
this question is appropriate:

I am trying to create a program that, when given a list of classes and their
meeting time, will sort through and output every possible combination where
no classes overlap. My problem is in how I'm trying to represent the class
times. I have a 71 digit number, each digit representing an hour of the week
during which classes can meet. It's a zero if there's no class at that hour,
one if there is (plus a one at the beginning or else it thinks i'm trying an
octal number?):

Basketweaving 101: 1000000111000000000000000111000000000000000000000

The example is shortened a bit, but Basketweaving would be a three hour
class twice a week. In order to see if a schedule works i add together all
the class's numbers and if there's nothing but ones and zeros in the sum
('cept for the first number) then they didn't overlap.

1000000111000000000000000111000000000000000000000
1000000000000000111000000000000001110000000000000   <--Fine

1000000111000000000000000111000000000000000000000
1000000000001000000000000011100000000000000000000   <--No

My problem is, quite simply, it's a 71 digit number, which gets chopped down
to 15 digits without Math::BigInt, and Math::BigInt is far too slow. A large
schedule can require 15,000+ iterations to check all the classes (I don't
mind waiting myself, but this may end up on a server eventually). When I
benchmarked BigInt vs. normal addition (with smaller numbers) it was over
ten times slower. Is there a better alternative? Am I doing something wrong
perhaps? I can't think of a better/simpler way to represent the classes, but
I'm only a dumb Graphic Design major and I'm not too familiar with many data
structures ;-)

Thanks a lot for any help and suggestions,
Brian Boucheron.


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org