From f96a2022413ad523fd2457cd419e7a3498c4f5f5 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 16 Oct 2023 11:06:49 +0000 Subject: Challenge 239 Solutions (Raku) --- challenge-239/mark-anderson/raku/ch-1.raku | 11 +++++++++ challenge-239/mark-anderson/raku/ch-2.raku | 39 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 challenge-239/mark-anderson/raku/ch-1.raku create mode 100644 challenge-239/mark-anderson/raku/ch-2.raku (limited to 'challenge-239') diff --git a/challenge-239/mark-anderson/raku/ch-1.raku b/challenge-239/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..4763f75e9f --- /dev/null +++ b/challenge-239/mark-anderson/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku +use Test; + +ok same-string(, ); +nok same-string(, ); +ok same-string(, []); + +sub same-string(@a, @b) +{ + [eq] ([~] @a), ([~] @b) +} diff --git a/challenge-239/mark-anderson/raku/ch-2.raku b/challenge-239/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..6a6935e85f --- /dev/null +++ b/challenge-239/mark-anderson/raku/ch-2.raku @@ -0,0 +1,39 @@ +#!/usr/bin/env raku +use Test; +use Benchy; + +is consistant-strings(, 'ab'), 2; +is consistant-strings(, 'ab'), 3; +is consistant-strings(, 'cad'), 4; +benchmark(); + +sub consistant-strings(@a, $allowed) +{ + @a.grep({ .comb (<=) $allowed.comb }).elems +} + +sub consistant-strings-slow(@a, $allowed) +{ + @a.match(/ <|w> <{"<[$allowed]>"}>+ <|w> /, :global).elems +} + +sub benchmark +{ + b 10, + { + consistant-strings-slow(, 'ab'); + consistant-strings-slow(, 'ab'); + consistant-strings-slow(, 'cad') + }, + + { + consistant-strings(, 'ab'); + consistant-strings(, 'ab'); + consistant-strings(, 'cad') + } + + # Bare: 0.000040891s + # Old: 11.435895767s + # New: 0.019084392s + # NEW version is 599.23x faster +} -- cgit From ab1293cfcddc7cf4d2c7ab6b2a46e96f356c0936 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 16 Oct 2023 11:19:23 +0000 Subject: Challenge 239 Solutions (Raku) --- challenge-239/mark-anderson/raku/ch-2.raku | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'challenge-239') diff --git a/challenge-239/mark-anderson/raku/ch-2.raku b/challenge-239/mark-anderson/raku/ch-2.raku index 6a6935e85f..f6c46defd7 100644 --- a/challenge-239/mark-anderson/raku/ch-2.raku +++ b/challenge-239/mark-anderson/raku/ch-2.raku @@ -2,17 +2,17 @@ use Test; use Benchy; -is consistant-strings(, 'ab'), 2; -is consistant-strings(, 'ab'), 3; -is consistant-strings(, 'cad'), 4; +is consistent-strings(, 'ab'), 2; +is consistent-strings(, 'abc'), 7; +is consistent-strings(, 'cad'), 4; benchmark(); -sub consistant-strings(@a, $allowed) +sub consistent-strings(@a, $allowed) { @a.grep({ .comb (<=) $allowed.comb }).elems } -sub consistant-strings-slow(@a, $allowed) +sub consistent-strings-slow(@a, $allowed) { @a.match(/ <|w> <{"<[$allowed]>"}>+ <|w> /, :global).elems } @@ -21,15 +21,15 @@ sub benchmark { b 10, { - consistant-strings-slow(, 'ab'); - consistant-strings-slow(, 'ab'); - consistant-strings-slow(, 'cad') + consistent-strings-slow(, 'ab'); + consistent-strings-slow(, 'abc'); + consistent-strings-slow(, 'cad') }, { - consistant-strings(, 'ab'); - consistant-strings(, 'ab'); - consistant-strings(, 'cad') + consistent-strings(, 'ab'); + consistent-strings(, 'abc'); + consistent-strings(, 'cad') } # Bare: 0.000040891s -- cgit