#!/usr/bin/env perl use strict; use warnings; use utf8; use feature qw{ say signatures }; no warnings qw{ experimental::signatures }; my @roll = map { d6() } 1 .. 5; say join ' ', @roll; say score(@roll); sub score (@roll) { my $score = 0; my $count; map { $count->{$_} = 0 } 1 .. 6; for my $d (@roll) { $count->{$d}++; } if ( $count->{1} >= 3 ) { $score += 1000; $count->{1} -= 3 } if ( $count->{2} >= 3 ) { $score += 200; $count->{2} -= 3 } if ( $count->{3} >= 3 ) { $score += 300; $count->{3} -= 3 } if ( $count->{4} >= 3 ) { $score += 400; $count->{4} -= 3 } if ( $count->{5} >= 3 ) { $score += 500; $count->{5} -= 3 } if ( $count->{6} >= 3 ) { $score += 600; $count->{6} -= 3 } while ( $count->{1} > 0 ) { $score += 100; $count->{1}-- } while ( $count->{5} > 0 ) { $score += 50; $count->{5}-- } return $score; } sub d6 { return 1 + int rand 6; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Perl