From 1f2c563d631e01a8707ee098c1bb3905bfe32501 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra Date: Thu, 21 Oct 2021 19:11:08 -0400 Subject: Week 135 --- challenge-135/conor-hoekstra/ch-01.apl | 12 ++++++++++++ challenge-135/conor-hoekstra/ch-01.bqn | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 challenge-135/conor-hoekstra/ch-01.apl create mode 100644 challenge-135/conor-hoekstra/ch-01.bqn diff --git a/challenge-135/conor-hoekstra/ch-01.apl b/challenge-135/conor-hoekstra/ch-01.apl new file mode 100644 index 0000000000..533de97ab0 --- /dev/null +++ b/challenge-135/conor-hoekstra/ch-01.apl @@ -0,0 +1,12 @@ +middleThreeDigits ← { + s ← ⍕|⍵ + 0=2|≢s : 'Even # of digits' ⋄ + 3>≢s : 'Too short' ⋄ + (3↑(2÷⍨¯3+≢)↓⊢)s +} + +⍝ Tests +middleThreeDigits 1234567 ⍝ 345 +middleThreeDigits ¯123 ⍝ 123 +middleThreeDigits 1 ⍝ Too short +middleThreeDigits 10 ⍝ Even # of digits diff --git a/challenge-135/conor-hoekstra/ch-01.bqn b/challenge-135/conor-hoekstra/ch-01.bqn new file mode 100644 index 0000000000..7d91a8a263 --- /dev/null +++ b/challenge-135/conor-hoekstra/ch-01.bqn @@ -0,0 +1,12 @@ +Fmt ← '0'+·⌽10|·⌊⊢÷(10⋆↕∘(⌊1+10⋆⁼1⌈|)) + +MiddleThreeDigits ← { + 0=2|≠Fmt|𝕩 ? "Even # of digits" ; + 3>≠Fmt|𝕩 ? "Too short" ; + (3↑(2÷˜¯3+≠)↓⊢)Fmt|𝕩 +} + +MiddleThreeDigits 1234567 # "345" +MiddleThreeDigits ¯123 # "123" +MiddleThreeDigits 1 # "Too short" +MiddleThreeDigits 10 # "Even # of digits" -- cgit From d70091ac8bc2b89a6244990f840a91c9f8979527 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra Date: Thu, 21 Oct 2021 19:15:19 -0400 Subject: Refactor --- challenge-135/conor-hoekstra/ch-01.bqn | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/challenge-135/conor-hoekstra/ch-01.bqn b/challenge-135/conor-hoekstra/ch-01.bqn index 7d91a8a263..c93246ea4a 100644 --- a/challenge-135/conor-hoekstra/ch-01.bqn +++ b/challenge-135/conor-hoekstra/ch-01.bqn @@ -1,9 +1,7 @@ -Fmt ← '0'+·⌽10|·⌊⊢÷(10⋆↕∘(⌊1+10⋆⁼1⌈|)) - MiddleThreeDigits ← { - 0=2|≠Fmt|𝕩 ? "Even # of digits" ; - 3>≠Fmt|𝕩 ? "Too short" ; - (3↑(2÷˜¯3+≠)↓⊢)Fmt|𝕩 + 0=2|≠•Fmt|𝕩 ? "Even # of digits" ; + 3>≠•Fmt|𝕩 ? "Too short" ; + (3↑(2÷˜¯3+≠)↓⊢)•Fmt|𝕩 } MiddleThreeDigits 1234567 # "345" -- cgit