in reply to Re^2: Elegantly map fizz to buzz
in thread Elegantly map fizz to buzz

to generalize the problem by passing the moduli along as arguments.

If I've understood the task correctly, I think you're working the math too hard:

sub x{ my $v=shift; my $t=0; $t += !!($v%$_) for @_; return $t!=@_ };; sub fn{ my$n; x($_, @_) and $n+=$_ for 1 .. shift; $n };; print fn( 10, 3, 5 );; 33 print fn( 10, 3, 5, 7 );; 40 print fn( 100000, 3, 5, 7, 74017, 74027, 74047, 74077 );; 2714660445

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Elegantly map fizz to buzz
by oiskuu (Hermit) on May 18, 2016 at 18:06 UTC

    I suppose it would've been sensible to include use bigint; in my examples. (And make use of Math::BigInt::blcm.)

    print fn( 1e75, 3, 5, 7, 74017, 74027, 74047, 74077 );;

    All contributions are equally welcome, of course.

    Update. using bigint:

    print fk2( 1e75, 3, 5, 7, 74017, 74027, 74047, 74077 );; 2714409193835116782309092860748312946665048449396007497681808465165668 +014761062261823426471676870303814322114698720811164640573956951947124 +37887594397

      I suppose it would've been sensible to include use bigint;

      Wouldn't help very much with 1e75:

      Range iterator outside integer range at ...

      From this line of your code above:

      } 1 .. $max

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.