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

Re: [Omaha.pm] Math::BaseCalc



Wow! Arbitrary bases represented with only 10 characters! :) 

So if you're converting the string "13" to base 10 is it 13 or 17? :)

$ cat j.pl
use Math::BaseCalc;
my $base = new Math::BaseCalc(digits => [0..13]);
for (1..17) {
   print $base->to_base($_);
   print " ";
}

$ perl j.pl
1 2 3 4 5 6 7 8 9 10 11 12 13 10 11 12 13 
 



-----Original Message-----
Just change nights and/or rates, and run!


#!/usr/bin/perl
#
# combondler.pl
#
# Using number of nights and number of rates, this program
# calculates the number of combinations between each and prints
# it out.
#
# For example, 2 rates and 2 nights would display four combinations:
#
# 11 12 21 22
#
# 2 rates for 3 nights would display 8 combinations.
#
# 111 112 121 122 211 212 221 222
#
use Math::BaseCalc;

my $nights = 3;  # change this
my $rates = 2;   # or change this
my $base = new Math::BaseCalc(digits => [0..$rates]);  # change my base!
my $buns = $num = 0;

while (1) {
  $num++;
  my $str = $base->to_base($num);
  last if (length($str) > $nights);
  next if (length($str) < $nights or $str =~ /0/);
  $buns++;
  printf ("%${nights}s\n",$str);
}

print "If every rate was available, and inventory was available, the
$rates rate(s) and $nights night(s) combination would have $buns
bundle(s).\n";

exit;