aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScimon Proctor <simon.proctor@gmail.com>2021-07-28 09:25:58 +0100
committerScimon Proctor <simon.proctor@gmail.com>2021-07-28 09:25:58 +0100
commit89a81fa891a403ec8290cbe2a65732cc8b518835 (patch)
treef3219e7950d1542fbb2da0435f1216531ff89dce
parent0b7728d89268a2e08459260dab7725ea7a7ff727 (diff)
downloadperlweeklychallenge-club-89a81fa891a403ec8290cbe2a65732cc8b518835.tar.gz
perlweeklychallenge-club-89a81fa891a403ec8290cbe2a65732cc8b518835.tar.bz2
perlweeklychallenge-club-89a81fa891a403ec8290cbe2a65732cc8b518835.zip
Reducing code by making more Rakuish
-rw-r--r--challenge-123/simon-proctor/raku/ch-2.raku31
1 files changed, 14 insertions, 17 deletions
diff --git a/challenge-123/simon-proctor/raku/ch-2.raku b/challenge-123/simon-proctor/raku/ch-2.raku
index bff4cbcc4e..05ff2038ae 100644
--- a/challenge-123/simon-proctor/raku/ch-2.raku
+++ b/challenge-123/simon-proctor/raku/ch-2.raku
@@ -2,10 +2,10 @@
multi MAIN( 'Test' ) {
use Test;
- ok is-square( 10, 20, 20, 20, 20, 10, 10, 10 );
- ok !is-square( 12, 24, 16,10, 20, 12, 18, 16 );
- ok is-square( 0, 10, 10, 0, 0, -10, -10, 0 );
- is sq-dist-between( 0,0, 3, 4 ), 25;
+ ok is-square( (10, 20), (20, 20), (20, 10), (10, 10) );
+ ok !is-square( (12, 24), (16,10), (20, 12), (18, 16) );
+ ok is-square( (0, 10), (10, 0), (0, -10), (-10, 0) );
+ is sq-dist-between( (0,0), (3,4) ), 25;
done-testing;
}
@@ -14,21 +14,18 @@ multi MAIN( Num() $x1, Num() $y1,
Num() $x2, Num() $y2,
Num() $x3, Num() $y3,
Num()$x4, Num() $y4 ) {
- say +is-square( $x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4 );
+ say +is-square( ($x1, $y1), ($x2, $y2), ($x3, $y3), ($x4, $y4) );
}
-multi sq-dist-between( $x1, $y1, $x2, $y2 ) {
- ( $x1-$x2 )² + ( $y1-$y2 )²;
+multi sq-dist-between( @p1, @p2 ) {
+ ( @p1[0]-@p2[0] )² + ( @p1[1]-@p2[1] )²;
}
-multi is-square( $x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4 ) {
- my ( $d1, $d2, $d3, $d4, $d5, $d6 ) = (
- sq-dist-between( $x1,$y1, $x2, $y2),
- sq-dist-between( $x1,$y1, $x3, $y3),
- sq-dist-between( $x1,$y1, $x4, $y4),
- sq-dist-between( $x2,$y2, $x3, $y3),
- sq-dist-between( $x2,$y2, $x4, $y4),
- sq-dist-between( $x3,$y3, $x4, $y4),
- ).sort;
- return $d1 ~~ $d2 ~~ $d3 ~~ $d4 && $d5 ~~ $d6;
+multi is-square( @p1, @p2, @p3, @p4 ) {
+ my @d = ( @p1, @p2, @p3, @p4 )
+ .combinations(2)
+ .map( -> @l { sq-dist-between( @l[0], @l[1] ) } )
+ .sort;
+
+ return ([~~] @d[0..3]) && ([~~] @d[4..5]);
}