Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Perl6 Book Chapter 3 Example Ported to Ruby
use v6;
my @scores = 'Ana' => 8, 'Dave' => 6, 'Charlie' => 4, 'Beth' => 4;
my $screen-width = 30;
my $label-area-width = 1 + [max] @scores».key».chars;
my $max-score = [max] @scores».value;
my $unit = ($screen-width - $label-area-width) / $max-score;
my $format = '%- ' ~ $label-area-width ~ "s%snn"; # OMGWTFBBQ?
for @scores {
printf $format, .key, 'X' x ($unit * .value
}
scores = { 'Ana' => 8, 'Dave' => 6, 'Charlie' => 4, 'Beth' => 4 }
screen_width = 30
label_area_width = 1 + scores.keys.max_by(&:size).size
max_score = scores.values.max
unit = (screen_width - label_area_width) / max_score
scores.each do |k, v|
print "#{k}#{' ' * (label_area_width - k.size)}#{'X' * v * unit}\n"
end
@havenwood

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.