diff options
| author | Markus "Holli" Holzer <holli.holzer@gmail.com> | 2020-03-21 20:28:00 +0100 |
|---|---|---|
| committer | Markus "Holli" Holzer <holli.holzer@gmail.com> | 2020-03-21 20:28:00 +0100 |
| commit | 0a645b1d8fbc6d3e0864d7a53306663d2c19d73a (patch) | |
| tree | 1fa2a434086c91921412fcb00b7840283e55f557 | |
| parent | 24c1eff36de2e63bc5205b15596835883a499648 (diff) | |
| download | perlweeklychallenge-club-0a645b1d8fbc6d3e0864d7a53306663d2c19d73a.tar.gz perlweeklychallenge-club-0a645b1d8fbc6d3e0864d7a53306663d2c19d73a.tar.bz2 perlweeklychallenge-club-0a645b1d8fbc6d3e0864d7a53306663d2c19d73a.zip | |
stepping isn't just consecutive. duh
| -rw-r--r-- | challenge-052/markus-holzer/perl/ch-1.pl | 6 | ||||
| -rw-r--r-- | challenge-052/markus-holzer/raku/ch-1.p6 | 6 |
2 files changed, 8 insertions, 4 deletions
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 |
