Sum multiples of 3 and 5: Difference between revisions

m
→‎{{header|Perl}}: 2nd example needed integer results from division
m (Added Crystal solution - pre extra credits.)
m (→‎{{header|Perl}}: 2nd example needed integer results from division)
Line 2,242:
{{Trans|Tcl}}
An alternative approach, using the analytical solution from the Tcl example.
<lang Perl>subuse trifeature 'say'
sub tri
{
my $n = shift;
Line 2,251 ⟶ 2,252:
{
my $n = (shift) - 1;
return (3 * tri( int($n / 3) ) + 5 * tri( int($n / 5) ) - 15 * tri( int($n / 15) ) );
}
 
2,392

edits