Skip to content

Instantly share code, notes, and snippets.

@mcmillhj mcmillhj/junction.p6
Last active Apr 30, 2018

What would you like to do?
Why does the below junction differ in result to the loop?
my @dates = <May 15>, <May 16>, <May 19>, <June 17>, <June 18>, <July 14>, <July 16>, <August 14>, <August 15>, <August 17>;
sub day (@date) { @date[1] }
sub month (@date) { @date[0] }
sub tell($data) {
@dates.grep({ day($_) eq $data or month($_) eq $data });
sub know(@possible-dates) { @possible-dates.elems == 1 }
# I don't know when Cheryl's birthday is, but I know that Bernard does not know too
sub statement-one(@date) {
my @possible-dates = tell month @date;
# why is this not the same as below?
#return not know(@possible-dates) and not know tell day all(@possible-dates);
my Bool $r = not know @possible-dates;
for @possible-dates -> $date {
$r = $r && not know tell day $date;
return $r;
# At first I don't know when Cheryl's birthday is, but I know now
sub statement-two(@date) {
my @possible-dates = tell day @date;
not know(@possible-dates) and know @possible-dates.grep(&statement-one);
# Then I also know when Cheryl's birthday is
sub statement-three(@date) {
my @possible-dates = tell month @date;
know @possible-dates.grep(&statement-two);
sub cheryls-birthday() {
@dates.grep({ statement-one($_) and statement-two($_) and statement-three($_) });
say cheryls-birthday();
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.