Created
November 6, 2022 02:50
-
-
Save nd3i/80311cb2ac3d2f542e37b5ffe42fca23 to your computer and use it in GitHub Desktop.
This file contains 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
use v6; | |
do -> @list, $target { | |
my $char = @list.sort.first(* gt $target); | |
say "List: (@list[]), ", | |
"Target: $target, ", | |
defined($char) ?? | |
"Found: $char" !! | |
"Not found"; | |
} for | |
<e m u g>, 'b', # Output: e | |
<d c e f>, 'a', # Output: c | |
<j a r>, 'o', # Output: r | |
<d c a f>, 'a', # Output: c | |
<t g a l>, 'v', # Output: v | |
# random list & target | |
(('a'..'z').pick((1..26).pick)), ('a'..'z').pick, | |
# first attempt -- junked: don't need numeric values to compare strings | |
do -> @list, $target { | |
my $char = @list.sort.map(*.ord).first(* > $target.ord); | |
say "List: (@list[]), ", | |
"Target: $target ({$target.ord}), ", | |
defined($char) ?? | |
"Found: {$char.chrs} ($char)" !! | |
"Not found"; | |
} for Empty; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment