Numbers k such that the last letter of k is the same as the first letter of k+1
- Definition
For the purposes of this task, a qualifying number is a non-negative integer, k, whose last letter is the same as the first letter of k+1 when written in English.
For example, 18 (i.e 'eighteen' in English) is a qualifying number because its last letter 'n' is the same as the first letter of 'nineteen'.
Take the English equivalent of 0 to be 'zero' and not 'nought' or similar words.
For numbers such as 100 or 1000, the equivalent English should be taken as 'one hundred' or 'one thousand' and not 'a hundred' or 'a thousand'.
- Task
1. Find and show here the first 50 qualifying numbers.
2. What are the 1,000th and 10,000th qualifying numbers?
3. For the first 1,000 and 10,000 qualifying numbers, show their breakdown by final digit. This can be shown numerically, graphically or both.
If it is difficult for your language to meet all of these requirements, then just do what you reasonably can.
- Stretch
4. What are the 100,000th and millionth qualifying numbers?
5. For the first 100,000 and million qualifying numbers, show their breakdown by final digit.
- References
- OEIS sequence A363659:Numbers k such that the last letter of k is the same as the first letter of k+1 when written in English.
- GCHQ, The GCHQ Puzzle Book, Penguin, 2016. See Puzzle 31, page 37 (referred to in OEIS link).
Wren
Simple brute force approach.
import "./fmt" for Name, Fmt
import "./math" for Nums
var i = 0
var c = 0
var nums = []
var lastDigs = List.filled(10, 0)
var labels = (0..9).map { |d| d.toString }.toList
var prev = Name.fromNum(0) // "zero"
var limit = 1000
while (limit <= 1e6) {
var next = Name.fromNum(i+1)
if (prev[-1] == next[0]) {
if (c < 50) nums.add(i)
var ld = i % 10
lastDigs[ld] = lastDigs[ld] + 1
c = c + 1
if (c == 50) {
System.print("First 50 numbers:")
Fmt.tprint("$3d ", nums, 10)
System.print()
} else if (c == limit) {
Fmt.print("The $,d number is $,d.\n", c, i)
var title = Fmt.swrite("Breakdown by last digit of first $,d numbers", c)
Nums.barChart(title, 80, labels, lastDigs)
System.print()
limit = limit * 10
}
}
prev = next
i = i + 1
}
- Output:
First 50 numbers: 0 18 28 38 79 81 83 85 97 102 122 132 142 152 162 172 182 192 208 228 238 248 258 268 278 288 298 308 328 338 348 358 368 378 388 398 799 801 803 805 809 812 821 823 825 829 831 833 835 839 The 1,000 number is 10,988. Breakdown by last digit of first 1,000 numbers -------------------------------------------------------------------------------- 0 ■■ 12 1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111 2 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 110 3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111 4 ■■ 11 5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111 6 ■■ 11 7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111 8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 301 9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111 -------------------------------------------------------------------------------- The 10,000 number is 106,652. Breakdown by last digit of first 10,000 numbers -------------------------------------------------------------------------------- 0 ■■■ 122 1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301 2 ■■■■■■■■■■■■■■■■■■■■■■■■■ 829 3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301 4 ■■■ 121 5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301 6 ■■■ 121 7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1211 8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 2392 9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301 -------------------------------------------------------------------------------- The 100,000 number is 1,095,542. Breakdown by last digit of first 100,000 numbers -------------------------------------------------------------------------------- 0 ■■■ 1122 1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301 2 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 18829 3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301 4 ■■■ 1121 5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301 6 ■■■ 1121 7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11211 8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 21392 9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301 -------------------------------------------------------------------------------- The 1,000,000 number is 10,984,428. Breakdown by last digit of first 1,000,000 numbers -------------------------------------------------------------------------------- 0 ■■ 11123 1 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301 2 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 110230 3 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301 4 ■■ 11121 5 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301 6 ■■ 11121 7 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111211 8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 299990 9 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301 --------------------------------------------------------------------------------