DEV Community

Discussion on: Daily Challenge #69 - Going to the Cinema

Collapse
 
choroba profile image
E. Choroba • Edited
#!/usr/bin/perl
use warnings;
use strict;

sub movie {
    my ($card, $ticket, $perc) = @_;
    my $reduced = my $sum = $ticket * $perc;
    my $count = 0;
    $sum += ($reduced *= $perc)
        while $ticket * ++$count < $card + int $sum;
    return $count
}

use Test::More tests => 3;

is movie(100, 200, 0.5),   1;
is movie(500,  15, 0.9),  43;
is movie(100,  10, 0.95), 24;