Table of Contents
Problem
If the numbers $1$ to $5$ are written out in words: one, two, three, four, five, then there are $3 + 3 + 5 + 4 + 4 = 19$ letters used in total. If all the numbers from $1$ to $1000$ (one thousand) inclusive were written out in words, how many letters would be used?
NOTE: Do not count spaces or hyphens. For example, $342$ (three hundred and forty-two) contains $23$ letters and $115$ (one hundred and fifteen) contains $20$ letters. The use of "and" when writing out numbers is in compliance with British usage.
First, an apology
I didn't really think that this was an interesting problem to solve with Uiua. I don't feel like doing a thorough write-up of this one either. Since I suffer from ADHD there is no way around this, lmao, (that's a lie).
Just for completeness' sake though, I'll include the solution I came up with. It's not the best one and frankly it is hard to read and understand.
If you like, try dissecting it and figuring out how it works.
The basic idea is to create a pipeline which feeds the digits, as an array, to functions that figure out how many letters are in those components.
I used base,10 and reversed it to make it easier to reason about.
The tens, for example, have the teens (10-19) zeroed out and are instead handled
in the TeenPart pipeline.
Solution
You can take a look at the solution in the pad at the top of this article. Otherwise, here's a fun read.
D ← [
0 3 3 5
4 4 3
5 5 4
]
# Tens (exclude teens)
T ← [
0 0 6 6
5 5 5
7 6 6
]
# 10-19
E ← [
3 3 3
3 4 3
4 4 3
4
]
# A bunch of bois to
# act on the reversed base,10
# version of the number
AndsPart ← ×₃× ¬≍⊢ ⟜/+ ⟜(=₃⧻)
HundredsPart ← + ×₇ >1⊸∘ ט⊡ D ⊢⟜(=₃ ⧻)
TeenPart ← ט⊡E⊣ ⟜⍣(=₁⊡¯2|0)
DigitPart ← ˜⊡D ⊣
TensPart ← ˜⊡T⍣(⊡¯2|0)
OneThousand ← 11
/+≡(/+⊂₅⊃(AndsPart|HundredsPart|TeenPart|DigitPart|TensPart)⇌⊥₁₀) ⇡₁999
OneThousand
+