-
-
Save smls/732115c66cd29aa2e9d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
my %grade = "grades.txt".IO.lines.map: { | |
m:s/^ (\w+) (<[A..F]><[+-]>?) $/ or die "Can't parse line '$_'"; | |
~$0 => ~$1 | |
}; | |
say "Zsófia's grade: %grade<Zsófia>"; | |
say "List of students with a failing grade:"; | |
say " " ~ %grade.grep(*.value ge "E")».key.join(', '); | |
say "Distribution of grades by letter:"; | |
say " {.key}: {+.value} student{"s" if .value != 1}" | |
for %grade.classify(*.value.comb[0]).sort(*.key); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
use feature 'say'; | |
use utf8; | |
binmode STDOUT, ":utf8"; | |
open my $fh, '<:utf8', "grades.txt" or die "Failed to open file: $!"; | |
my %grade; | |
while (<$fh>) { | |
m/^ (\w+) \s+ ([A-F][+-]?) $/x or die "Can't parse line '$_'"; | |
$grade{$1} = $2; | |
}; | |
say "Zsófia's grade: $grade{Zsófia}"; | |
say "List of students with a failing grade:"; | |
say " " . join ", ", grep { $grade{$_} ge "E" } keys %grade; | |
say "Distribution of grades by letter:"; | |
my %freq; | |
$freq{substr $grade{$_}, 0, 1}++ for keys %grade; | |
say " $_: $freq{$_} student".($freq{$_} != 1 ? "s" : "") | |
for sort keys %freq; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Peter B | |
Celine A- | |
Zsófia B+ | |
João F | |
Maryam B+ | |
秀英 B- | |
Finn D+ | |
Aarav A | |
Emma F | |
Omar B |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
my %grade = "grades.txt".IO.lines.map: { | |
m:s/^ (\w+) (<[A..F]><[+-]>?) $/ or die "Can't parse line '$_'"; | |
~$0 => ~$1 | |
}; | |
say "Zsófia's grade: %grade<Zsófia>"; | |
say "List of students with a failing grade:"; | |
say " " ~ %grade.grep(*.value ge "E")».key.join(', '); | |
say "Distribution of grades by letter:"; | |
say " $(.key): $(+.value) student$("s" if .value != 1)" | |
for %grade.classify(*.value.comb[0]).sort(*.key); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment