Skip to content

Instantly share code, notes, and snippets.

@nd3i
Created November 6, 2022 02:50
Show Gist options
  • Save nd3i/80311cb2ac3d2f542e37b5ffe42fca23 to your computer and use it in GitHub Desktop.
Save nd3i/80311cb2ac3d2f542e37b5ffe42fca23 to your computer and use it in GitHub Desktop.
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