From 0a645b1d8fbc6d3e0864d7a53306663d2c19d73a Mon Sep 17 00:00:00 2001 From: "Markus \"Holli\" Holzer" Date: Sat, 21 Mar 2020 20:28:00 +0100 Subject: stepping isn't just consecutive. duh --- challenge-052/markus-holzer/perl/ch-1.pl | 6 +++++- challenge-052/markus-holzer/raku/ch-1.p6 | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'challenge-052') diff --git a/challenge-052/markus-holzer/perl/ch-1.pl b/challenge-052/markus-holzer/perl/ch-1.pl index 582674b438..c6522aa1aa 100644 --- a/challenge-052/markus-holzer/perl/ch-1.pl +++ b/challenge-052/markus-holzer/perl/ch-1.pl @@ -5,7 +5,11 @@ sub stepping { my @n = split '', shift; my $m = shift @n; - for my $n ( @n ) { return 0 unless $m + 1 == ($m = $n) } + + for my $n ( @n ) { + return unless abs($m - $n) == 1; + $m = $n; + } 1; } diff --git a/challenge-052/markus-holzer/raku/ch-1.p6 b/challenge-052/markus-holzer/raku/ch-1.p6 index cabee9e7ea..4807703bbf 100644 --- a/challenge-052/markus-holzer/raku/ch-1.p6 +++ b/challenge-052/markus-holzer/raku/ch-1.p6 @@ -1,8 +1,8 @@ # Inspired by Simon -sub is-consecutive( UInt $n ) { - [==] ^$n.chars Z- $n.comb; +sub is-stepping( UInt $n ) { + not so $n.comb.rotor( 2 => -1 ).first: -> ($a, $b) { abs($a - $b) != 1 } } sub MAIN (UInt $start = 100, UInt $end = 999) { - .say for ($start..$end).grep( &is-consecutive ); + .say for ($start..$end).grep( &is-stepping ); } \ No newline at end of file -- cgit