Numbers k such that the last letter of k is the same as the first letter of k+1: Difference between revisions

m
Promoted to 'full' task.
m (Promoted to 'full' task.)
(21 intermediate revisions by 7 users not shown)
Line 1:
{{draft task}}
 
;Definition
Line 169:
9: ====================== (111301)
</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
 
std::string cardinal(int n) {
static const char* small[] = {
"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen",
};
static const char* tens[] = {
"twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety",
};
assert(n >= 0 && n < 1000);
std::string str;
if (n < 20)
str = small[n];
else if (n < 100) {
str = tens[n / 10 - 2];
if (n % 10 != 0) {
str += "-";
str += small[n % 10];
}
} else {
str = cardinal(n / 100);
str += " hundred";
if (n % 100 != 0) {
str += " ";
str += cardinal(n % 100);
}
}
return str;
}
 
class a363659_generator {
public:
explicit a363659_generator() : num(0) {
for (int i = 0; i < 1000; ++i) {
std::string name = cardinal(i);
first[i] = name.front();
last[i] = name.back();
}
}
int next() {
while (first_char(num + 1) != last_char(num))
++num;
return num++;
}
 
private:
char first_char(int n) const {
int i = 0;
for (; n > 0; n /= 1000)
i = n % 1000;
return first[i];
}
char last_char(int n) const {
int i = n % 1000;
if (i > 0)
return last[i];
else if (n == 0)
return last[0];
else if (n % 1000000 == 0)
return 'n';
return 'd';
}
int num;
char first[1000];
char last[1000];
};
 
template <typename Iterator>
void histogram(Iterator begin, Iterator end) {
if (begin == end)
return;
double max_value = *std::max_element(begin, end);
const int width = 60;
int i = 0;
for (Iterator it = begin; it != end; ++it) {
std::cout << i++ << ": ";
double value = *it;
int n = max_value != 0 ? std::lround((value * width) / max_value) : 0;
int j = 0;
for (; j < n; ++j)
std::cout << u8"\u2586";
for (; j < width; ++j)
std::cout << ' ';
std::cout << ' ' << *it << '\n';
}
}
 
int main() {
std::cout << "First 50 numbers:\n";
a363659_generator gen;
int count[10] = {};
int i = 1, n;
for (; i <= 50; ++i) {
n = gen.next();
++count[n % 10];
std::cout << std::setw(3) << n << (i % 10 == 0 ? '\n' : ' ');
}
for (int limit = 1000; limit <= 1000000; limit *= 10) {
for (; i <= limit; ++i) {
n = gen.next();
++count[n % 10];
}
std::cout << "\nThe " << limit << "th number is " << n << ".\n";
std::cout << "Breakdown by last digit of first " << limit
<< " numbers:\n";
histogram(count, count + 10);
}
}</syntaxhighlight>
 
{{out}}
<pre>
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 1000th number is 10988.
Breakdown by last digit of first 1000 numbers:
0: ▆▆ 12
1: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111
2: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 110
3: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111
4: ▆▆ 11
5: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111
6: ▆▆ 11
7: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111
8: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 301
9: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111
 
The 10000th number is 106652.
Breakdown by last digit of first 10000 numbers:
0: ▆▆▆ 122
1: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 1301
2: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 829
3: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 1301
4: ▆▆▆ 121
5: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 1301
6: ▆▆▆ 121
7: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 1211
8: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 2392
9: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 1301
 
The 100000th number is 1095542.
Breakdown by last digit of first 100000 numbers:
0: ▆▆▆ 1122
1: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 11301
2: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 18829
3: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 11301
4: ▆▆▆ 1121
5: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 11301
6: ▆▆▆ 1121
7: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 11211
8: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 21392
9: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 11301
 
The 1000000th number is 10984428.
Breakdown by last digit of first 1000000 numbers:
0: ▆▆ 11123
1: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111301
2: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 110230
3: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111301
4: ▆▆ 11121
5: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111301
6: ▆▆ 11121
7: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111211
8: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 299990
9: ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ 111301
</pre>
 
=={{header|FreeBASIC}}==
Using https://rosettacode.org/wiki/Number_names#FreeBASIC
<syntaxhighlight lang="vb">Dim As Uinteger i = 0, c = 0, j = 0
Dim As Integer l
Dim As Uinteger nums(50)
Dim As Integer lastDigs(9)
Dim As String prev = "zero", sgte = ""
Dim As Uinteger limit = 1000
While limit <= 1000000
sgte = numname(i+1)
If Right(prev,1) = Left(sgte,1) Then
If c < 50 Then nums(c) = i
Dim As Integer ld = i Mod 10
lastDigs(ld) += 1
c += 1
If c = 50 Then
Print "First 50 numbers:"
For j = 0 To c-1
Print Using "### "; nums(j);
If (j+1) Mod 10 = 0 Then Print
Next j
Elseif c = limit Then
Print Using !"\nThe & number is ##,###,###."; numname(c); i
Print !"Breakdown by last digit of the qualifiers up to this:\nFrequencies"
Print String (80, "-")
For j = 0 To 9
l = Cint(lastDigs(j) * 28 / lastDigs(9))
Print j; " "; String(l, Chr(254)); " "; lastDigs(j)
Next j
Print String (80, "-")
limit *= 10
End If
End If
prev = sgte
i += 1
Wend
 
Sleep</syntaxhighlight>
{{out}}
<pre>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 one thousand number is 10,988.
Breakdown by last digit of the qualifiers up to this:
Frequencies
--------------------------------------------------------------------------------
0 ■■■■ 12
1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
2 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 110
3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
4 ■■■ 11
5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
6 ■■■ 11
7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 301
9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
--------------------------------------------------------------------------------
 
The ten thousand number is 106,652.
Breakdown by last digit of the qualifiers up to this:
Frequencies
--------------------------------------------------------------------------------
0 ■■■ 122
1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301
2 ■■■■■■■■■■■■■■■■■■■■■■■■ 829
3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301
4 ■■■ 121
5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301
6 ■■■ 121
7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1211
8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 2392
9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301
--------------------------------------------------------------------------------
 
The one hundred thousand number is 1,095,542.
Breakdown by last digit of the qualifiers up to this:
Frequencies
--------------------------------------------------------------------------------
0 ■■■ 1122
1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301
2 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 18829
3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301
4 ■■■ 1121
5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301
6 ■■■ 1121
7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11211
8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 21392
9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301
--------------------------------------------------------------------------------
 
The one million number is 10,984,428.
Breakdown by last digit of the qualifiers up to this:
Frequencies
--------------------------------------------------------------------------------
0 ■■■ 11123
1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301
2 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 110230
3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301
4 ■■■ 11121
5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301
6 ■■■ 11121
7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111211
8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 299990
9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301
--------------------------------------------------------------------------------</pre>
 
 
=={{header|J}}==
Line 207 ⟶ 499:
8 2392
9 1301</syntaxhighlight>
 
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq.'''
 
The following is probably mainly of interest because of the utility functions:
 
* lpad # left pad
* rpad # right pad
* tprint # tabular print
* whilst # control structure
* number2name # English name of a number
* barChart # horizontal barchart
 
'''Preliminaries'''
<syntaxhighlight lang="jq">
# The following may be omitted if using the C implementation of jq
def _nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l) + .;
 
def rpad($len): tostring | ($len - length) as $l | . + (" " * $l);
 
# tabular print
def tprint(columns; wide):
reduce _nwise(columns) as $row ("";
. + ($row|map(lpad(wide)) | join(" ")) + "\n" );
 
# If cond then emit f and use that value to recurse
def whilst(cond; f): def r: select(cond) | f | (., r); r;
 
# Input: a positive or negative number for which tostring prints with only characters from [-.0-9]
# Output: the name of the number, e.g. "zero" for 0
# An error is raised if the above-mentioned requirement is not met.
def number2name:
 
def __small: [
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven",
"twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" ];
 
def __tens: ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
 
def __illions: [
"", " thousand", " million", " billion"," trillion", " quadrillion", " quintillion",
" sextillion", " septillion", " octillion", " nonillion", "decillion" ];
 
. as $n
| if tostring | test("[eE]") then "number2name cannot handle \(.)" | error else . end
| false as $_uk # United Kingdom mode
| "minus" as $_neg
| "point" as $_point
| {f: "",
and: (if $_uk then "and " else "" end) }
| if $n < 0
then .t = $_neg + " "
| .n = - $n
else .n = $n
end
| if (.n | (. != floor))
then .f = (.n | tostring | sub("^[0-9]*[.]";""))
| .n |= trunc
else .
end
| if .n < 20
then .t += __small[.n]
elif .n < 100
then .t += __tens[(.n/10)|floor]
| (.n % 10) as $s
| if $s > 0 then .t += "-" + __small[$s] else . end
elif .n < 1000
then .t += __small[(.n/100)|floor] + " hundred"
| (.n % 100) as $s
| if $s > 0 then .t += " " + .and + ($s|number2name) else . end
else .sx = ""
| .i = 0
| until (.n <= 0;
(.n % 1000) as $p
| .n |= ((./1000)|floor)
| if $p > 0
then .ix = ($p|number2name) + __illions[.i]
| if .sx != "" then .ix += " " + .sx else . end
| .sx = .ix
else .
end
| .i += 1)
| .t += .sx
end
| if .f != ""
then .t += " " + $_point
| reduce (.f | explode[] | [.] | implode | tonumber) as $d
(.; .t += " \(__small[$d])" )
else .
end
| .t ;
 
# Draws a horizontal bar chart on the terminal representing an array
# of numerical 'data', which must be non-negative, for example:
 
# Title
# --------------------------------------------------
# a □ 0
# bb ■■■■■■■■■■■■■■■■■■■■■■ 1
# ccc ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 2
# --------------------------------------------------
 
# 'labels' is a list of the corresponding text for each bar.
# If 'rjust' is true then the labels are right-justified within their maximum length,
# otherwise they are left-justified.
# 'width' is the desired total width of the chart in characters.
# 'symbol' is the character to be used to draw each bar,
# 'symbol2' is used to represent scaled non-zero data and 'symbol3' zero data which
# would otherwise be blank. The actual data is printed at the end of each bar.
#
def barChart ($title; $width; $labels; $data; $rjust; $symbol; $symbol2; $symbol3):
 
def times($n): if $n > 0 then . * $n else "" end;
def n: if isinfinite then "∞" else tostring end;
($labels|length) as $barCount
| if ($data|length) != $barCount then "Mismatch between labels and data." | error else . end
| ($labels | map(length) | max) as $maxLabelLen
| ($labels
| if $rjust
then map( lpad( $maxLabelLen ) )
else map( rpad( $maxLabelLen ) )
end ) as $labels
| ($data|max) as $maxData
| ($data|map(if isinfinite then 1 else tostring|length end)|max) as $maxDataLength
| ($width - $maxLabelLen - $maxDataLength - 2) as $maxLen # maximum length of a bar
| ($data | map( if isinfinite then $maxLen else ((. * $maxLen / $maxData)|floor) end)) as $scaledData
| ( "-" * ([$width, ($title|length)] | max)) as $dashes
| $title,
$dashes,
(range(0; $barCount) as $i
| ($symbol | times($scaledData[$i]))
| if . == "" then (if $data[$i] > 0 then $symbol2 else $symbol3 end) else . end
| "\($labels[$i]) \(.) \($data[$i]|n)" ),
$dashes ;
 
# Convenience version of the above function using default symbols:
def barChart($title; $width; $labels; $data; $rjust):
barChart($title; $width; $labels; $data; $rjust; "■"; "◧"; "□");
 
# Convenience version using right justification for labels.
def barChart($title; $width; $labels; $data):
barChart($title; $width; $labels; $data; true; "■"; "◧"; "□");
</syntaxhighlight>
'''The task'''
<syntaxhighlight lang="jq">
def task($limit):
[range(0;10) | tostring] as $labels
| {i: 0,
c: 0,
nums: [],
lastDigs: [range(0;10)|0],
prev: "zero",
limit: 1000 }
| whilst (.limit <= $limit;
.emit = null
| (.i+1 | number2name) as $next
| if .prev[-1:] == $next[:1]
then if (.c < 50) then .nums += [.i] else . end
| .lastDigs[.i % 10] += 1
| .c += 1
| if .c == 50
then .emit = ["First 50 numbers:", (.nums|tprint(10;3))]
elif .c == .limit
then .emit = ["\nThe \(.c)th number is \(.i)\n"]
| "Breakdown by last digit of first \(.c) numbers" as $title
| .emit += [barChart($title; 80; $labels; .lastDigs)]
| .limit *= 10
else .
end
else .
end
| .prev = $next
| .i += 1 )
| select(.emit).emit[] ;
 
task(1e6)
</syntaxhighlight>
{{output}}
<pre>
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 1000th number is 10988
 
Breakdown by last digit of first 1000 numbers
--------------------------------------------------------------------------------
0 ■■ 12
1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
2 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 110
3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
4 ■■ 11
5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
6 ■■ 11
7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 301
9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■ 111
--------------------------------------------------------------------------------
 
The 10000th number is 106652
 
Breakdown by last digit of first 10000 numbers
--------------------------------------------------------------------------------
0 ■■■ 122
1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301
2 ■■■■■■■■■■■■■■■■■■■■■■■■■ 829
3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301
4 ■■■ 121
5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301
6 ■■■ 121
7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1211
8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 2392
9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1301
--------------------------------------------------------------------------------
 
The 100000th number is 1095542
 
Breakdown by last digit of first 100000 numbers
--------------------------------------------------------------------------------
0 ■■■ 1122
1 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301
2 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 18829
3 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301
4 ■■■ 1121
5 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301
6 ■■■ 1121
7 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11211
8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 21392
9 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11301
--------------------------------------------------------------------------------
 
The 1000000th number is 10984428
 
Breakdown by last digit of first 1000000 numbers
--------------------------------------------------------------------------------
0 ■■ 11123
1 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301
2 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 110230
3 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301
4 ■■ 11121
5 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301
6 ■■ 11121
7 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111211
8 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 299990
9 ■■■■■■■■■■■■■■■■■■■■■■■■■■ 111301
--------------------------------------------------------------------------------
</pre>
 
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Formatting, SpelledOut, UnicodePlots
 
spell(n)const spelledcache = [spelled_out(n, lang = :en) for n in 1:999]
const firstcache, lastcache = map(first, spelledcache), map(last, spelledcache)
 
function inOEIS363659(n)
qualifies(n) = spell(n)[end] == spell(n + 1)[begin]
lastchar = n % 1000 > 0 ? lastcache[n % 1000] : n == 0 ? 'o' : n % 1_000_000 == 0 ? 'n' : 'd'
n += 1
j = 0
while n > 0
n, j = divrem(n, 1000)
end
return firstcache[j] == lastchar
end
 
""" test the sequence """
function testqualifies()
function testOEIS363659()
ncount = 0
lastdigits = UInt8[]
println("First 50 qualifying numbers:")
for n in 0:typemax(Int32)
if qualifiesinOEIS363659(n)
ncount += 1
push!(lastdigits, n % 10)
if ncount < 51
print(rpad(n, 5), ncount % 10 == 0 ? "\n" : "")
elseif ncount in [10^3, 10^4, 10^5, 10^6, 10^7, 10^8]
println("\nThe $(spellspelled_out(ncount))th number is $(format(n, commas = true)).")
println("Breakdown by last digit of the qualifiers up to this:")
display(histogram(lastdigits, nbins = 10))
println()
ncount == 1_000_000100_000_000 && break
end
end
Line 236 ⟶ 797:
end
 
testOEIS363659()
testqualifies()
</syntaxhighlight>{{out}}
<pre>
Line 310 ⟶ 871:
[ 8.0, 9.0) ┤███████████████████████████████ 299 990
[ 9.0, 10.0) ┤███████████▌ 111 301
└ ┘
Frequency
 
 
The ten millionth number is 106,650,962.
Breakdown by last digit of the qualifiers up to this:
┌ ┐
[ 0.0, 1.0) ┤█▌ 121 134
[ 1.0, 2.0) ┤███████████████▊ 1 301 301
[ 2.0, 3.0) ┤██████████▏ 828 817
[ 3.0, 4.0) ┤███████████████▊ 1 301 301
[ 4.0, 5.0) ┤█▌ 121 121
[ 5.0, 6.0) ┤███████████████▊ 1 301 301
[ 6.0, 7.0) ┤█▌ 121 121
[ 7.0, 8.0) ┤██████████████▋ 1 211 211
[ 8.0, 9.0) ┤█████████████████████████████ 2 391 392
[ 9.0, 10.0) ┤███████████████▊ 1 301 301
└ ┘
Frequency
 
 
The one hundred millionth number is 1,095,538,742.
Breakdown by last digit of the qualifiers up to this:
┌ ┐
[ 0.0, 1.0) ┤█▌ 1 121 234
[ 1.0, 2.0) ┤██████████████▊ 11 301 301
[ 2.0, 3.0) ┤████████████████████████▋ 18 828 717
[ 3.0, 4.0) ┤██████████████▊ 11 301 301
[ 4.0, 5.0) ┤█▌ 1 121 121
[ 5.0, 6.0) ┤██████████████▊ 11 301 301
[ 6.0, 7.0) ┤█▌ 1 121 121
[ 7.0, 8.0) ┤██████████████▋ 11 211 211
[ 8.0, 9.0) ┤████████████████████████████ 21 391 392
[ 9.0, 10.0) ┤██████████████▊ 11 301 301
└ ┘
Frequency
</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">s99</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'?'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">),</span> <span style="color: #000080;font-style:italic;">// starting char of 0..99</span>
<span style="color: #000000;">e99</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'?'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">// ending char of 0..99</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">99</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">ordinal</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">s99</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">e99</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[$]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">d_count</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- nb 0s in [1] .. 9s in [10]</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">this_end</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">'o'</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">// zero </span>
<span style="color: #000000;">next_to_show</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1e3</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">;</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 50 numbers:\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">count</span><span style="color: #0000FF;"><</span><span style="color: #000000;">1e6</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">next</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">next</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1000</span> <span style="color: #008080;">do</span> <span style="color: #000000;">next</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">next</span><span style="color: #0000FF;">/</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">next</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">100</span> <span style="color: #008080;">then</span> <span style="color: #000000;">next</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">next</span><span style="color: #0000FF;">/</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">next_start</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">s99</span><span style="color: #0000FF;">[</span><span style="color: #000000;">next</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #000080;font-style:italic;">// (wrong for 0, but no e*illion anyway)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">next_start</span><span style="color: #0000FF;">=</span><span style="color: #000000;">this_end</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">d_count</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;"><=</span> <span style="color: #000000;">50</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" %4d%n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">next_to_show</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nThe %,dth number is: %,d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Breakdown by final digit of the numbers:\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">mv</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d_count</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span> <span style="color: #008080;">in</span> <span style="color: #000000;">d_count</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%2d: %s (%d)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'*'</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">round</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">/</span><span style="color: #000000;">mv</span><span style="color: #0000FF;">)),</span><span style="color: #000000;">d</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">next_to_show</span> <span style="color: #0000FF;">*=</span> <span style="color: #000000;">10</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">n99</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">// from table or hundred,thousand -&gt; 'd', million (etc) -&gt; 'n':</span>
<span style="color: #000000;">this_end</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n99</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span><span style="color: #0000FF;">?</span><span style="color: #000000;">e99</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n99</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]:</span><span style="color: #7060A8;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1e6</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">?</span><span style="color: #008000;">'n'</span><span style="color: #0000FF;">:</span><span style="color: #008000;">'d'</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
The 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,000th number is: 10,988
Breakdown by final digit of the numbers:
0: ** (12)
1: ********************** (111)
2: ********************** (110)
3: ********************** (111)
4: ** (11)
5: ********************** (111)
6: ** (11)
7: ********************** (111)
8: ************************************************************ (301)
9: ********************** (111)
 
The 10,000th number is: 106,652
Breakdown by final digit of the numbers:
0: *** (122)
1: ********************************* (1301)
2: ********************* (829)
3: ********************************* (1301)
4: *** (121)
5: ********************************* (1301)
6: *** (121)
7: ****************************** (1211)
8: ************************************************************ (2392)
9: ********************************* (1301)
 
The 100,000th number is: 1,095,542
Breakdown by final digit of the numbers:
0: *** (1122)
1: ******************************** (11301)
2: ***************************************************** (18829)
3: ******************************** (11301)
4: *** (1121)
5: ******************************** (11301)
6: *** (1121)
7: ******************************* (11211)
8: ************************************************************ (21392)
9: ******************************** (11301)
 
The 1,000,000th number is: 10,984,428
Breakdown by final digit of the numbers:
0: ** (11123)
1: ********************** (111301)
2: ********************** (110230)
3: ********************** (111301)
4: ** (11121)
5: ********************** (111301)
6: ** (11121)
7: ********************** (111211)
8: ************************************************************ (299990)
9: ********************** (111301)
</pre>
You can trivially extend the limit to 1e8, on 64-bit or change next_to_show (etc) to atom, and in about 75s, a tad slow, also get:
<pre>
The 10,000,000th number is: 106,650,962
Breakdown by final digit of the numbers:
0: *** (121134)
1: ********************************* (1301301)
2: ********************* (828817)
3: ********************************* (1301301)
4: *** (121121)
5: ********************************* (1301301)
6: *** (121121)
7: ****************************** (1211211)
8: ************************************************************ (2391392)
9: ********************************* (1301301)
 
The 100,000,000th number is: 1,095,538,742
Breakdown by final digit of the numbers:
0: *** (1121234)
1: ******************************** (11301301)
2: ***************************************************** (18828717)
3: ******************************** (11301301)
4: *** (1121121)
5: ******************************** (11301301)
6: *** (1121121)
7: ******************************* (11211211)
8: ************************************************************ (21391392)
9: ******************************** (11301301)
</pre>
 
=={{header|Python}}==
<syntaxhighlight lang="python">""" rosettacode.org, wiki task regarding OEIS sequence A363659 """
 
from collections import Counter
from ascii_graph import Pyasciigraph
from num2words import num2words
 
sspelledcache = [num2words(n) for n in range(1000)]
firstcache, lastcache = [s[0] for s in spelledcache], [s[-1] for s in spelledcache]
 
def qualifies(n):
lastchar = lastcache[n % 1000] if n % 1000 > 0 else 'o' if n == 0 else \
'n' if n % 1_000_000 == 0 else 'd'
n += 1
j = 0
while n > 0:
n, j = divmod(n, 1000)
return firstcache[j] == lastchar
 
def testqualifies():
""" Test the generation of OEIS sequence A363659 """
ncount = 0
lastdigits = Counter()
print("First 50 qualifying numbers:")
for num in range(1_000_000_000):
if qualifies(num):
ncount += 1
lastdigits.update([num % 10])
if ncount < 51:
print(f'{num:5}', end='\n' if ncount % 10 == 0 else '')
elif ncount in [10**3, 10**4, 10**5, 10**6]:
print(f'\nThe {num2words(ncount)}th number is {num:,}.')
print('Breakdown by last digit of the qualifiers up to this:')
graph = Pyasciigraph()
for line in graph.graph('Frequencies', sorted(lastdigits.items())):
print(line)
print()
 
if ncount == 1_000_000:
break
 
 
if __name__ == '__main__':
 
testqualifies()
</syntaxhighlight>{{out}}
<pre>
First 50 qualifying 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 one thousandth number is 10,988.
Breakdown by last digit of the qualifiers up to this:
Frequencies
###############################################################################
██ 12 0
██████████████████████████ 111 1
█████████████████████████ 110 2
██████████████████████████ 111 3
██ 11 4
██████████████████████████ 111 5
██ 11 6
██████████████████████████ 111 7
███████████████████████████████████████████████████████████████████████ 301 8
██████████████████████████ 111 9
 
 
The ten thousandth number is 106,652.
Breakdown by last digit of the qualifiers up to this:
Frequencies
###############################################################################
███ 122 0
██████████████████████████████████████ 1301 1
████████████████████████ 829 2
██████████████████████████████████████ 1301 3
███ 121 4
██████████████████████████████████████ 1301 5
███ 121 6
███████████████████████████████████ 1211 7
██████████████████████████████████████████████████████████████████████ 2392 8
██████████████████████████████████████ 1301 9
 
 
The one hundred thousandth number is 1,095,542.
Breakdown by last digit of the qualifiers up to this:
Frequencies
###############################################################################
███ 1122 0
████████████████████████████████████ 11301 1
████████████████████████████████████████████████████████████ 18829 2
████████████████████████████████████ 11301 3
███ 1121 4
████████████████████████████████████ 11301 5
███ 1121 6
████████████████████████████████████ 11211 7
█████████████████████████████████████████████████████████████████████ 21392 8
████████████████████████████████████ 11301 9
 
 
The one millionth number is 10,984,428.
Breakdown by last digit of the qualifiers up to this:
Frequencies
###############################################################################
██ 11123 0
█████████████████████████ 111301 1
████████████████████████ 110230 2
█████████████████████████ 111301 3
██ 11121 4
█████████████████████████ 111301 5
██ 11121 6
█████████████████████████ 111211 7
████████████████████████████████████████████████████████████████████ 299990 8
█████████████████████████ 111301 9
</pre>
 
=={{header|Raku}}==
{{trans|Wren}}
<syntaxhighlight lang="raku" line># 20230713 Raku programming solution
 
###### https://rosettacode.org/wiki/Number_names#Raku
 
constant @I = <zero one two three four five six seven eight nine
ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen>;
constant @X = <0 X twenty thirty forty fifty sixty seventy eighty ninety>;
constant @C = @I X~ ' hundred';
constant @M = (<0 thousand>,
((<m b tr quadr quint sext sept oct non>,
(map { ('', <un duo tre quattuor quin sex septen octo novem>).flat X~ $_ },
<dec vigint trigint quadragint quinquagint sexagint septuagint octogint nonagint>),
'cent').flat X~ 'illion')).flat;
 
sub int-name ($num) {
if $num.substr(0,1) eq '-' { return "negative {int-name($num.substr(1))}" }
if $num eq '0' { return @I[0] }
my $m = 0;
return join ', ', reverse gather for $num.flip.comb(/\d ** 1..3/) {
my ($i,$x,$c) = .comb».Int;
if $i or $x or $c {
take join ' ', gather {
if $c { take @C[$c] }
if $x and $x == 1 { take @I[$i+10] }
else {
if $x { take @X[$x] }
if $i { take @I[$i] }
}
take @M[$m] // die "WOW! ZILLIONS!\n" if $m;
}
}
$m++;
}
}
######
 
my ($i, $c, $limit, $prev, @nums, @lastDigs) = 0, 0, 1000, int-name(0);
 
while $limit <= 1e4 {
my $next = int-name $i+1;
if $prev.substr(*-1) eq $next.substr(0,1) {
if ($c < 50) { @nums.append: $i };
@lastDigs[$i % 10] += 1;
$c++;
if $c == 50 {
say "First 50 numbers:";
say [~] $_>>.fmt('%4s') for @nums.rotor(10);
say();
} elsif $c == $limit {
print "The {$c}th number is $i.\n";
say "Breakdown by last digit of first {$c}th numbers";
say 'N Freq';
for 0..9 -> $d {
say "$d {@lastDigs[$d].fmt('%4s')} ",
'█' x (@lastDigs[$d]/@lastDigs.max*72).Int;
}
say();
$limit *= 10
}
}
$prev = $next;
$i++;
}</syntaxhighlight>
You may [https://ato.pxeger.com/run?1=bVbBbttGEL0W_IoJw4CkLFFUm6CtJQtGUwQQkDhAWyBGFSOgyJW0tbgrL5eWVIM59wtyySWH9it662f02C_pzC4pUbYJmTu7nHnzduYtzc9_quS6_PLlr1LPe9_9-5X71Fyw1HpdnPb7ShZM6ySVGYukWvQ3_Jr3L8p8xtQHkeSsePoTxjtOKkWhE6HhfAJnMPqdKQlSMMBLb6QZloqZ-VyWCozBb81CwbdmXrBbJozF-GKpyRBcMAeOL01ObGWc9YatEEQvudIM54RtDT43I2LbkdyNZbDJIGwyxsMW-0tiH1OayzrbBuN2NsPOsLejybCz7O1oMuwa9ruavd4d4b9EfCzR5UfwYVmKTLHMbz9_g88DJKCXsiwSkY27ZvtBMMphBlrBTZlkdOfoXbAt3dYaZKpBSNF458ka7iDw_S6MSgFZKTGUUazWpbThFG2CsRQYLjH-luXjMJqvEk0EvQ9QWbxRxlK45QvKqZUdDY-kNrnA6aKm1BhrXa8RujGQoVkZhxbXT7Fi_iGjz1crLoUf2qWh4xTlDDCgR1KDwBNlHsKdieVzoGmEHoVWQdwdhMBuwO_5uHPFdKkEuIItEk0qu2tAgnbQIAwrF6o2nsGIWxjnk2l8VfvkO_BybFA8NNPa4zeJxcRK40-hBlTBALMumSKtWJLzFV9HqcxnQf99Bp0ODKLom36zlRo68HjX23a9NMQUxvufv6OJ0MO9E3HkQKBbc09bAEaryTWr6RCbmsXd_QNkcDDW-p-_nHpps8P7XltADdJwdgaDfcRk6vGTQfxYEFvh9h9mPOA1GJdTb_sYwGGf7WyPeT5csf5vpl5-Bf0-ZJyB--7tuyfw6-T168nbi5-fvBeuQc-HzuNQB8vLT06sV-VUjn0tOk7dJ6wf_q14zjWOa-x7F86x0wUOq6TQP_JFQW2Mu_QbxDHe9xKMQ1T2ZslXrIaAEVaXPbd1I5EJOthnB-VTuQ0X4k7ZGgV3elb2JuLoLDQ9wIgAmz2CFzEuWpJRsl4zkZ1SlaumEnveWG54BtTeE6TVPPbSphyNflASL-J2r4tkB-4rrgpND4T5J1GcusNjj-nHK3y1jMfRPNeB_-x54YfmoFhmSmqJB5NK1I4KwiHUCxVpbM-gLmCLxVrRq8b9ZYk69NJKL2smwAvcb4QKuEfI_UGx5DqTGwGzHVAVUDkLBJVzfMnTbo5wivvx_gW8UuzGby3TfuIo-h56Y_AyLPuR2kxSWm6VPLtq1aMCt_tA3P5_n_7wYQvBUVR_P4vyZNv59uvw-JXRPiXHdaSe2uJ1sM2x03I3N6MzFKGRlgFEFaIEKvupUH8xNF8O_wM Attempt This Online!]
 
=={{header|Wren}}==
Line 318 ⟶ 1,231:
{{libheader|Wren-math}}
Simple brute force approach.
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Name, Fmt
import "./math" for Nums
 
9,486

edits