Esthetic numbers: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|Phix}}: extended limits)
(Add Factor)
Line 127: Line 127:
<pre>
<pre>
Same as Go entry.
Same as Go entry.
</pre>

=={{header|Factor}}==
The <code>bfs</code> word is an adaptation of the algorithm from the Geeks for Geeks reference. It has been adapted to work with any base. In summary, this algorithm constructs esthetic numbers directly using a breadth first search. For example, we know the only two esthetic numbers that can be constructed from 23 are 232 and 234, or in other words, the last digit of 23 ± 1 appended to 23. This forms a tree where each node is an esthetic number and can have at most two children. This is very fast and has been used to find the count of esthetic numbers in base 10 between zero and one quadrillion.
{{works with|Factor|0.99 2020-01-23}}
<lang factor>USING: combinators deques dlists formatting grouping io kernel
locals make math math.order math.parser math.ranges
math.text.english prettyprint sequences sorting strings ;

:: bfs ( from to num base -- )
DL{ } clone :> q
base 1 - :> ld
num q push-front
[ q deque-empty? ]
[
q pop-back :> step-num
step-num from to between? [ step-num , ] when
step-num zero? step-num to > or
[
step-num base mod :> last-digit
step-num base * last-digit 1 - + :> a
step-num base * last-digit 1 + + :> b

last-digit
{
{ 0 [ b q push-front ] }
{ ld [ a q push-front ] }
[ drop a q push-front b q push-front ]
} case

] unless

] until ;

:: esthetics ( from to base -- seq )
[ base <iota> [| num | from to num base bfs ] each ]
{ } make natural-sort ;

: .seq ( seq width -- )
group [ [ dup string? [ write ] [ pprint ] if bl ] each nl ]
each nl ;

:: show ( base -- )
base [ 4 * ] [ 6 * ] bi :> ( from to )
from to [ dup ordinal-suffix ] bi@ base
"%d%s through %d%s esthetic numbers in base %d\n" printf
from to 1 + 0 5000 ! enough for base 16
base esthetics subseq [ base >base ] map 17 .seq ;

2 16 [a,b] [ show ] each

"Base 10 numbers between 1,000 and 9,999:" print
1,000 9,999 10 esthetics 16 .seq

"Base 10 numbers between 100,000,000 and 130,000,000:" print
100,000,000 130,000,000 10 esthetics 9 .seq

"Count of base 10 esthetic numbers between zero and one quadrillion:"
print 0 1e15 10 esthetics length .</lang>
{{out}}
<pre>
8th through 12th esthetic numbers in base 2
10101010 101010101 1010101010 10101010101 101010101010

12th through 18th esthetic numbers in base 3
1210 1212 2101 2121 10101 10121 12101

16th through 24th esthetic numbers in base 4
323 1010 1012 1210 1212 1232 2101 2121 2123

20th through 30th esthetic numbers in base 5
323 343 432 434 1010 1012 1210 1212 1232 1234 2101

24th through 36th esthetic numbers in base 6
343 345 432 434 454 543 545 1010 1012 1210 1212 1232 1234

28th through 42nd esthetic numbers in base 7
345 432 434 454 456 543 545 565 654 656 1010 1012 1210 1212 1232

32nd through 48th esthetic numbers in base 8
432 434 454 456 543 545 565 567 654 656 676 765 767 1010 1012 1210 1212

36th through 54th esthetic numbers in base 9
434 454 456 543 545 565 567 654 656 676 678 765 767 787 876 878 1010
1012 1210

40th through 60th esthetic numbers in base 10
454 456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898
987 989 1010 1012

44th through 66th esthetic numbers in base 11
456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a
987 989 9a9 a98 a9a 1010

48th through 72nd esthetic numbers in base 12
543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987
989 9a9 9ab a98 a9a aba ba9 bab

52nd through 78th esthetic numbers in base 13
545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989
9a9 9ab a98 a9a aba abc ba9 bab bcb cba

56th through 84th esthetic numbers in base 14
565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9
9ab a98 a9a aba abc ba9 bab bcb bcd cba cbc cdc

60th through 90th esthetic numbers in base 15
567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab
a98 a9a aba abc ba9 bab bcb bcd cba cbc cdc cde dcb dcd

64th through 96th esthetic numbers in base 16
654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab a98
a9a aba abc ba9 bab bcb bcd cba cbc cdc cde dcb dcd ded def edc

Base 10 numbers between 1,000 and 9,999:
1010 1012 1210 1212 1232 1234 2101 2121 2123 2321 2323 2343 2345 3210 3212 3232
3234 3432 3434 3454 3456 4321 4323 4343 4345 4543 4545 4565 4567 5432 5434 5454
5456 5654 5656 5676 5678 6543 6545 6565 6567 6765 6767 6787 6789 7654 7656 7676
7678 7876 7878 7898 8765 8767 8787 8789 8987 8989 9876 9878 9898

Base 10 numbers between 100,000,000 and 130,000,000:
101010101 101010121 101010123 101012101 101012121 101012123 101012321 101012323 101012343
101012345 101210101 101210121 101210123 101212101 101212121 101212123 101212321 101212323
101212343 101212345 101232101 101232121 101232123 101232321 101232323 101232343 101232345
101234321 101234323 101234343 101234345 101234543 101234545 101234565 101234567 121010101
121010121 121010123 121012101 121012121 121012123 121012321 121012323 121012343 121012345
121210101 121210121 121210123 121212101 121212121 121212123 121212321 121212323 121212343
121212345 121232101 121232121 121232123 121232321 121232323 121232343 121232345 121234321
121234323 121234343 121234345 121234543 121234545 121234565 121234567 123210101 123210121
123210123 123212101 123212121 123212123 123212321 123212323 123212343 123212345 123232101
123232121 123232123 123232321 123232323 123232343 123232345 123234321 123234323 123234343
123234345 123234543 123234545 123234565 123234567 123432101 123432121 123432123 123432321
123432323 123432343 123432345 123434321 123434323 123434343 123434345 123434543 123434545
123434565 123434567 123454321 123454323 123454343 123454345 123454543 123454545 123454565
123454567 123456543 123456545 123456565 123456567 123456765 123456767 123456787 123456789

Count of base 10 esthetic numbers between zero and one quadrillion:
161914
</pre>
</pre>



Revision as of 15:43, 18 March 2020

Esthetic numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

An esthetic number is a positive integer where every adjacent digit differs from its neighbour by 1.


E.G.
  • 12 is an esthetic number. One and two differ by 1.
  • 5654 is an esthetic number. Each digit is exactly 1 away from its neighbour.
  • 890 is not an esthetic number. Nine and zero differ by 9.


These examples are nominally in base 10 but the concept extends easily to numbers in other bases. Traditionally, single digit numbers are included in esthetic numbers; zero may or may not be. For our purposes, for this task, do not include zero (0) as an esthetic number. Do not include numbers with leading zeros.

Esthetic numbers are also sometimes referred to as stepping numbers.


Task
  • Write a routine (function, procedure, whatever) to find esthetic numbers in a given base.
  • Use that routine to find esthetic numbers in bases 2 through 16 and display, here on this page, the esthectic numbers from index (base × 4) through index (base × 6), inclusive. (E.G. for base 2: 8th through 12th, for base 6: 24th through 36th, etc.)
  • Find and display, here on this page, the base 10 esthetic numbers with a magnitude between 1000 and 9999.
  • Stretch: Find and display, here on this page, the base 10 esthetic numbers with a magnitude between 1.0e8 and 1.3e8.


See also


C

Translation of: Go

<lang c>#include <stdio.h>

  1. include <string.h>

typedef int bool; typedef unsigned long long ull;

  1. define TRUE 1
  2. define FALSE 0

char as_digit(int d) {

   return (d >= 0 && d <= 9) ? d + '0' : d - 10 + 'a';  

}

void revstr(char *str) {

   int i, len = strlen(str);
   char t; 
   for (i = 0; i < len/2; ++i) { 
       t = str[i]; 
       str[i] = str[len - i - 1]; 
       str[len - i - 1] = t; 
   } 

}

char* to_base(char s[], ull n, int b) {

   int i = 0; 
   while (n) { 
       s[i++] = as_digit(n % b); 
       n /= b; 
   } 
   s[i] = '\0'; 
   revstr(s);
   return s;  

}

ull uabs(ull a, ull b) {

   return a > b ? a - b : b - a;

}

bool is_esthetic(ull n, int b) {

   int i, j;
   if (!n) return FALSE;
   i = n % b;
   n /= b;
   while (n) {
       j = n % b;
       if (uabs(i, j) != 1) return FALSE;
       n /= b;
       i = j;
   }
   return TRUE;

}

int main() {

   ull n;
   int b, c;
   char ch[12] = {0};
   for (b = 2; b <= 16; ++b) {
       printf("Base %d: %dth to %dth esthetic numbers:\n", b, 4*b, 6*b);
       for (n = 1, c = 0; c < 6 * b; ++n) {
           if (is_esthetic(n, b)) {
               if (++c >= 4 * b) printf("%s ", to_base(ch, n, b));
           }
       }
       printf("\n\n");
   } 
   printf("Base 10: esthetic numbers between 1,000 and 9,999:\n");
   /* clearly esthetic numbers must be in range [1010, 9898] */ 
   for (n = 1010, c = 0; n <= 9898; ++n) {
       if (is_esthetic(n, 10)) {
           printf("%llu ", n);
           if (!(++c % 16)) printf("\n");
       }
   } 
   printf("\n\nBase 10: esthetic numbers between 100,000,000 and 130,000,000:\n");
   /* clearly esthetic numbers must be in range [101010101, 123456789] */
   for (n = 101010101, c = 0; n <= 123456789; ++n) {
       if (is_esthetic(n, 10)) {
           printf("%llu ", n);
           if (!(++c % 9)) printf("\n");
       }
   }
   return 0;

}</lang>

Output:
Same as Go entry.

Factor

The bfs word is an adaptation of the algorithm from the Geeks for Geeks reference. It has been adapted to work with any base. In summary, this algorithm constructs esthetic numbers directly using a breadth first search. For example, we know the only two esthetic numbers that can be constructed from 23 are 232 and 234, or in other words, the last digit of 23 ± 1 appended to 23. This forms a tree where each node is an esthetic number and can have at most two children. This is very fast and has been used to find the count of esthetic numbers in base 10 between zero and one quadrillion.

Works with: Factor version 0.99 2020-01-23

<lang factor>USING: combinators deques dlists formatting grouping io kernel locals make math math.order math.parser math.ranges math.text.english prettyprint sequences sorting strings ;

bfs ( from to num base -- )
   DL{ } clone :> q
   base 1 - :> ld
   num q push-front
   [ q deque-empty? ]
   [
       q pop-back :> step-num
       step-num from to between? [ step-num , ] when
       step-num zero? step-num to > or
       [
           step-num base mod :> last-digit
           step-num base * last-digit 1 - + :> a
           step-num base * last-digit 1 + + :> b
           last-digit
           {
               { 0 [ b q push-front ] }
               { ld [ a q push-front ] }
               [ drop a q push-front b q push-front ]
           } case
       ] unless
   ] until ;
esthetics ( from to base -- seq )
   [ base <iota> [| num | from to num base bfs ] each ]
   { } make natural-sort ;
.seq ( seq width -- )
   group [ [ dup string? [ write ] [ pprint ] if bl ] each nl ]
   each nl ;
show ( base -- )
   base [ 4 * ] [ 6 * ] bi :> ( from to )
   from to [ dup ordinal-suffix ] bi@ base
   "%d%s through %d%s esthetic numbers in base %d\n" printf
   from to 1 + 0 5000   ! enough for base 16
   base esthetics subseq [ base >base ] map 17 .seq ;

2 16 [a,b] [ show ] each

"Base 10 numbers between 1,000 and 9,999:" print 1,000 9,999 10 esthetics 16 .seq

"Base 10 numbers between 100,000,000 and 130,000,000:" print 100,000,000 130,000,000 10 esthetics 9 .seq

"Count of base 10 esthetic numbers between zero and one quadrillion:" print 0 1e15 10 esthetics length .</lang>

Output:
8th through 12th esthetic numbers in base 2
10101010 101010101 1010101010 10101010101 101010101010 

12th through 18th esthetic numbers in base 3
1210 1212 2101 2121 10101 10121 12101 

16th through 24th esthetic numbers in base 4
323 1010 1012 1210 1212 1232 2101 2121 2123 

20th through 30th esthetic numbers in base 5
323 343 432 434 1010 1012 1210 1212 1232 1234 2101 

24th through 36th esthetic numbers in base 6
343 345 432 434 454 543 545 1010 1012 1210 1212 1232 1234 

28th through 42nd esthetic numbers in base 7
345 432 434 454 456 543 545 565 654 656 1010 1012 1210 1212 1232 

32nd through 48th esthetic numbers in base 8
432 434 454 456 543 545 565 567 654 656 676 765 767 1010 1012 1210 1212 

36th through 54th esthetic numbers in base 9
434 454 456 543 545 565 567 654 656 676 678 765 767 787 876 878 1010 
1012 1210 

40th through 60th esthetic numbers in base 10
454 456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 
987 989 1010 1012 

44th through 66th esthetic numbers in base 11
456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a 
987 989 9a9 a98 a9a 1010 

48th through 72nd esthetic numbers in base 12
543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 
989 9a9 9ab a98 a9a aba ba9 bab 

52nd through 78th esthetic numbers in base 13
545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 
9a9 9ab a98 a9a aba abc ba9 bab bcb cba 

56th through 84th esthetic numbers in base 14
565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 
9ab a98 a9a aba abc ba9 bab bcb bcd cba cbc cdc 

60th through 90th esthetic numbers in base 15
567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab 
a98 a9a aba abc ba9 bab bcb bcd cba cbc cdc cde dcb dcd 

64th through 96th esthetic numbers in base 16
654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab a98 
a9a aba abc ba9 bab bcb bcd cba cbc cdc cde dcb dcd ded def edc 

Base 10 numbers between 1,000 and 9,999:
1010 1012 1210 1212 1232 1234 2101 2121 2123 2321 2323 2343 2345 3210 3212 3232 
3234 3432 3434 3454 3456 4321 4323 4343 4345 4543 4545 4565 4567 5432 5434 5454 
5456 5654 5656 5676 5678 6543 6545 6565 6567 6765 6767 6787 6789 7654 7656 7676 
7678 7876 7878 7898 8765 8767 8787 8789 8987 8989 9876 9878 9898 

Base 10 numbers between 100,000,000 and 130,000,000:
101010101 101010121 101010123 101012101 101012121 101012123 101012321 101012323 101012343 
101012345 101210101 101210121 101210123 101212101 101212121 101212123 101212321 101212323 
101212343 101212345 101232101 101232121 101232123 101232321 101232323 101232343 101232345 
101234321 101234323 101234343 101234345 101234543 101234545 101234565 101234567 121010101 
121010121 121010123 121012101 121012121 121012123 121012321 121012323 121012343 121012345 
121210101 121210121 121210123 121212101 121212121 121212123 121212321 121212323 121212343 
121212345 121232101 121232121 121232123 121232321 121232323 121232343 121232345 121234321 
121234323 121234343 121234345 121234543 121234545 121234565 121234567 123210101 123210121 
123210123 123212101 123212121 123212123 123212321 123212323 123212343 123212345 123232101 
123232121 123232123 123232321 123232323 123232343 123232345 123234321 123234323 123234343 
123234345 123234543 123234545 123234565 123234567 123432101 123432121 123432123 123432321 
123432323 123432343 123432345 123434321 123434323 123434343 123434345 123434543 123434545 
123434565 123434567 123454321 123454323 123454343 123454345 123454543 123454545 123454565 
123454567 123456543 123456545 123456565 123456567 123456765 123456767 123456787 123456789 

Count of base 10 esthetic numbers between zero and one quadrillion:
161914

Go

Simple brute force with obvious range limitations for last two parts. <lang go>package main

import (

   "fmt"
   "strconv"

)

func uabs(a, b uint64) uint64 {

   if a > b {
       return a - b
   }
   return b - a

}

func isEsthetic(n, b uint64) bool {

   if n == 0 {
       return false
   }
   i := n % b
   n /= b
   for n > 0 {
       j := n % b
       if uabs(i, j) != 1 {
           return false
       }
       n /= b
       i = j
   }
   return true

}

func main() {

   for b := uint64(2); b <= 16; b++ {
       fmt.Printf("Base %d: %dth to %dth esthetic numbers:\n", b, 4*b, 6*b)
       for n, c := uint64(1), uint64(0); c < 6*b; n++ {
           if isEsthetic(n, b) {
               c++
               if c >= 4*b {
                   fmt.Printf("%s ", strconv.FormatUint(n, int(b)))
               }
           }
       }
       fmt.Println("\n")
   }
   fmt.Println("Base 10: esthetic numbers between 1,000 and 9,999:")
   // clearly esthetic numbers must be in range [1010, 9898]
   for n, c := uint64(1010), uint64(0); n <= 9898; n++ {
       if isEsthetic(n, 10) {
           c++
           fmt.Printf("%d ", n)
           if c%16 == 0 {
               fmt.Println()
           }
       }
   }
   fmt.Println("\n\nBase 10: esthetic numbers between 100,000,000 and 130,000,000:")
   // clearly esthetic numbers must be in range [101010101, 123456789]
   for n, c := uint64(101_010_101), uint64(0); n <= 123_456_789; n++ {
       if isEsthetic(n, 10) {
           c++
           fmt.Printf("%d ", n)
           if c%9 == 0 {
               fmt.Println()
           }
       }
   }

}</lang>

Output:
Base 2: 8th to 12th esthetic numbers:
10101010 101010101 1010101010 10101010101 101010101010 

Base 3: 12th to 18th esthetic numbers:
1210 1212 2101 2121 10101 10121 12101 

Base 4: 16th to 24th esthetic numbers:
323 1010 1012 1210 1212 1232 2101 2121 2123 

Base 5: 20th to 30th esthetic numbers:
323 343 432 434 1010 1012 1210 1212 1232 1234 2101 

Base 6: 24th to 36th esthetic numbers:
343 345 432 434 454 543 545 1010 1012 1210 1212 1232 1234 

Base 7: 28th to 42th esthetic numbers:
345 432 434 454 456 543 545 565 654 656 1010 1012 1210 1212 1232 

Base 8: 32th to 48th esthetic numbers:
432 434 454 456 543 545 565 567 654 656 676 765 767 1010 1012 1210 1212 

Base 9: 36th to 54th esthetic numbers:
434 454 456 543 545 565 567 654 656 676 678 765 767 787 876 878 1010 1012 1210 

Base 10: 40th to 60th esthetic numbers:
454 456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 987 989 1010 1012 

Base 11: 44th to 66th esthetic numbers:
456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 a98 a9a 1010 

Base 12: 48th to 72th esthetic numbers:
543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab a98 a9a aba ba9 bab 

Base 13: 52th to 78th esthetic numbers:
545 565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab a98 a9a aba abc ba9 bab bcb cba 

Base 14: 56th to 84th esthetic numbers:
565 567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab a98 a9a aba abc ba9 bab bcb bcd cba cbc cdc 

Base 15: 60th to 90th esthetic numbers:
567 654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab a98 a9a aba abc ba9 bab bcb bcd cba cbc cdc cde dcb dcd 

Base 16: 64th to 96th esthetic numbers:
654 656 676 678 765 767 787 789 876 878 898 89a 987 989 9a9 9ab a98 a9a aba abc ba9 bab bcb bcd cba cbc cdc cde dcb dcd ded def edc 

Base 10: esthetic numbers between 1,000 and 9,999:
1010 1012 1210 1212 1232 1234 2101 2121 2123 2321 2323 2343 2345 3210 3212 3232 
3234 3432 3434 3454 3456 4321 4323 4343 4345 4543 4545 4565 4567 5432 5434 5454 
5456 5654 5656 5676 5678 6543 6545 6565 6567 6765 6767 6787 6789 7654 7656 7676 
7678 7876 7878 7898 8765 8767 8787 8789 8987 8989 9876 9878 9898 

Base 10: esthetic numbers between 100,000,000 and 130,000,000:
101010101 101010121 101010123 101012101 101012121 101012123 101012321 101012323 101012343 
101012345 101210101 101210121 101210123 101212101 101212121 101212123 101212321 101212323 
101212343 101212345 101232101 101232121 101232123 101232321 101232323 101232343 101232345 
101234321 101234323 101234343 101234345 101234543 101234545 101234565 101234567 121010101 
121010121 121010123 121012101 121012121 121012123 121012321 121012323 121012343 121012345 
121210101 121210121 121210123 121212101 121212121 121212123 121212321 121212323 121212343 
121212345 121232101 121232121 121232123 121232321 121232323 121232343 121232345 121234321 
121234323 121234343 121234345 121234543 121234545 121234565 121234567 123210101 123210121 
123210123 123212101 123212121 123212123 123212321 123212323 123212343 123212345 123232101 
123232121 123232123 123232321 123232323 123232343 123232345 123234321 123234323 123234343 
123234345 123234543 123234545 123234565 123234567 123432101 123432121 123432123 123432321 
123432323 123432343 123432345 123434321 123434323 123434343 123434345 123434543 123434545 
123434565 123434567 123454321 123454323 123454343 123454345 123454543 123454545 123454565 
123454567 123456543 123456545 123456565 123456567 123456765 123456767 123456787 123456789 

Phix

Simple string based approach, very fast, manages stretch goal and much further in the blink of an eye. <lang Phix>constant aleph = "0123456789ABCDEF"

function efill(string s, integer ch, i)

   -- min-fill, like 10101 or 54321 or 32101
   s[i] = ch
   for j=i+1 to length(s) do
       ch = iff(ch>='1'?iff(ch='A'?'9':ch-1):'1')
       s[j] = ch
   end for
   return s

end function

function esthetic(string s, integer base = 10)

   -- generate the next esthetic number after s
   -- (nb unpredictable results if s is not esthetic, or "")
   for i=length(s) to 1 by -1 do
       integer ch = s[i], cp = iff(i>1?s[i-1]:'0')
       if ch<cp and cp<aleph[base] then
           return efill(s,aleph[find(ch,aleph)+2],i)
       elsif i=1 and ch<aleph[base] then
           return efill(s,iff(ch='9'?'A':ch+1),i)
       end if
   end for
   return efill("1"&s,'1',1)

end function

string s sequence res for base=2 to 16 do

   integer hi = base*6,
           lo = base*4
   {s,res} = {"",{}}
   for i=1 to hi do
       s = esthetic(s, base)
       if i>=lo then
           res = append(res,s)
       end if
   end for
   res = join(shorten(res,"numbers",4))
   printf(1,"Base %d esthetic numbers[%d..%d]: %s\n",{base,lo,hi,res})

end for

{s,res} = {efill("1000",'1',1),{}} while length(s)=4 do

   res = append(res,s)
   s = esthetic(s)

end while res = {join(shorten(res,"numbers",5))} printf(1,"\nBase 10 esthetic numbers between 1,000 and 9,999: %s\n\n",res)

function comma(string s)

   for i=length(s)-2 to 2 by -3 do
       s[i..i-1] = ","
   end for
   return s

end function

for k=7 to 19 by 3 do

   string f = "10"&repeat('0',k),
          t = "13"&repeat('0',k)
   {s,res} = {efill(f,'1',1),{}}
   while s<t do
       res = append(res,s)
       s = esthetic(s)
   end while
   res = join(shorten(res,"numbers",1))
   printf(1,"Base 10 esthetic numbers between %s and %s: %s\n",
            {comma(f),comma(t),res})

end for</lang>

Output:
Base 2 esthetic numbers[8..12]: 10101010 101010101 1010101010 10101010101 101010101010
Base 3 esthetic numbers[12..18]: 1210 1212 2101 2121 10101 10121 12101
Base 4 esthetic numbers[16..24]: 323 1010 1012 1210 1212 1232 2101 2121 2123
Base 5 esthetic numbers[20..30]: 323 343 432 434 ... 1212 1232 1234 2101  (11 numbers)
Base 6 esthetic numbers[24..36]: 343 345 432 434 ... 1210 1212 1232 1234  (13 numbers)
Base 7 esthetic numbers[28..42]: 345 432 434 454 ... 1012 1210 1212 1232  (15 numbers)
Base 8 esthetic numbers[32..48]: 432 434 454 456 ... 1010 1012 1210 1212  (17 numbers)
Base 9 esthetic numbers[36..54]: 434 454 456 543 ... 878 1010 1012 1210  (19 numbers)
Base 10 esthetic numbers[40..60]: 454 456 543 545 ... 987 989 1010 1012  (21 numbers)
Base 11 esthetic numbers[44..66]: 456 543 545 565 ... 9A9 A98 A9A 1010  (23 numbers)
Base 12 esthetic numbers[48..72]: 543 545 565 567 ... A9A ABA BA9 BAB  (25 numbers)
Base 13 esthetic numbers[52..78]: 545 565 567 654 ... BA9 BAB BCB CBA  (27 numbers)
Base 14 esthetic numbers[56..84]: 565 567 654 656 ... BCD CBA CBC CDC  (29 numbers)
Base 15 esthetic numbers[60..90]: 567 654 656 676 ... CDC CDE DCB DCD  (31 numbers)
Base 16 esthetic numbers[64..96]: 654 656 676 678 ... DCD DED DEF EDC  (33 numbers)

Base 10 esthetic numbers between 1,000 and 9,999: 1010 1012 1210 1212 1232 ... 8987 8989 9876 9878 9898  (61 numbers)

Base 10 esthetic numbers between 100,000,000 and 130,000,000: 101010101 ... 123456789  (126 numbers)
Base 10 esthetic numbers between 100,000,000,000 and 130,000,000,000: 101010101010 ... 123456789898  (911 numbers)
Base 10 esthetic numbers between 100,000,000,000,000 and 130,000,000,000,000: 101010101010101 ... 123456789898989  (6,225 numbers)
Base 10 esthetic numbers between 100,000,000,000,000,000 and 130,000,000,000,000,000: 101010101010101010 ... 123456789898989898  (44,744 numbers)
Base 10 esthetic numbers between 100,000,000,000,000,000,000 and 130,000,000,000,000,000,000: 101010101010101010101 ... 123456789898989898989  (312,019 numbers)

Raku

Works with: Rakudo version 2020.02

<lang perl6>use Lingua::EN::Numbers;

sub esthetic($base = 10) {

   my @s = ^$base .map: -> \s {
       ((s - 1).base($base) if s > 0), ((s + 1).base($base) if s < $base - 1)
   }
   flat [ (1 .. $base - 1)».base($base) ],
   { [ flat .map: { $_ xx * Z~ flat @s[.comb.tail.parse-base($base)] } ] } … *

}

for 2 .. 16 -> $b {

   put "\n{(4 × $b).&ordinal-digit} through {(6 × $b).&ordinal-digit} esthetic numbers in base $b";
   put esthetic($b)[(4 × $b - 1) .. (6 × $b - 1)]».fmt('%3s').batch(16).join: "\n"

}

my @e10 = esthetic; put "\nBase 10 esthetic numbers between 1,000 and 9,999:"; put @e10.&between(1000, 9999).batch(20).join: "\n";

put "\nBase 10 esthetic numbers between {1e8.Int.&comma} and {1.3e8.Int.&comma}:"; put @e10.&between(1e8.Int, 1.3e8.Int).batch(9).join: "\n";

sub between (@array, Int $lo, Int $hi) {

   my $top = @array.first: * > $hi, :k;
   @array[^$top].grep: * > $lo

}</lang>

Output:
8th through 12th esthetic numbers in base 2
10101010 101010101 1010101010 10101010101 101010101010

12th through 18th esthetic numbers in base 3
1210 1212 2101 2121 10101 10121 12101

16th through 24th esthetic numbers in base 4
323 1010 1012 1210 1212 1232 2101 2121 2123

20th through 30th esthetic numbers in base 5
323 343 432 434 1010 1012 1210 1212 1232 1234 2101

24th through 36th esthetic numbers in base 6
343 345 432 434 454 543 545 1010 1012 1210 1212 1232 1234

28th through 42nd esthetic numbers in base 7
345 432 434 454 456 543 545 565 654 656 1010 1012 1210 1212 1232

32nd through 48th esthetic numbers in base 8
432 434 454 456 543 545 565 567 654 656 676 765 767 1010 1012 1210
1212

36th through 54th esthetic numbers in base 9
434 454 456 543 545 565 567 654 656 676 678 765 767 787 876 878
1010 1012 1210

40th through 60th esthetic numbers in base 10
454 456 543 545 565 567 654 656 676 678 765 767 787 789 876 878
898 987 989 1010 1012

44th through 66th esthetic numbers in base 11
456 543 545 565 567 654 656 676 678 765 767 787 789 876 878 898
89A 987 989 9A9 A98 A9A 1010

48th through 72nd esthetic numbers in base 12
543 545 565 567 654 656 676 678 765 767 787 789 876 878 898 89A
987 989 9A9 9AB A98 A9A ABA BA9 BAB

52nd through 78th esthetic numbers in base 13
545 565 567 654 656 676 678 765 767 787 789 876 878 898 89A 987
989 9A9 9AB A98 A9A ABA ABC BA9 BAB BCB CBA

56th through 84th esthetic numbers in base 14
565 567 654 656 676 678 765 767 787 789 876 878 898 89A 987 989
9A9 9AB A98 A9A ABA ABC BA9 BAB BCB BCD CBA CBC CDC

60th through 90th esthetic numbers in base 15
567 654 656 676 678 765 767 787 789 876 878 898 89A 987 989 9A9
9AB A98 A9A ABA ABC BA9 BAB BCB BCD CBA CBC CDC CDE DCB DCD

64th through 96th esthetic numbers in base 16
654 656 676 678 765 767 787 789 876 878 898 89A 987 989 9A9 9AB
A98 A9A ABA ABC BA9 BAB BCB BCD CBA CBC CDC CDE DCB DCD DED DEF
EDC

Base 10 esthetic numbers between 1,000 and 9,999:
1010 1012 1210 1212 1232 1234 2101 2121 2123 2321 2323 2343 2345 3210 3212 3232 3234 3432 3434 3454
3456 4321 4323 4343 4345 4543 4545 4565 4567 5432 5434 5454 5456 5654 5656 5676 5678 6543 6545 6565
6567 6765 6767 6787 6789 7654 7656 7676 7678 7876 7878 7898 8765 8767 8787 8789 8987 8989 9876 9878
9898

Base 10 esthetic numbers between 100,000,000 and 130,000,000:
101010101 101010121 101010123 101012101 101012121 101012123 101012321 101012323 101012343
101012345 101210101 101210121 101210123 101212101 101212121 101212123 101212321 101212323
101212343 101212345 101232101 101232121 101232123 101232321 101232323 101232343 101232345
101234321 101234323 101234343 101234345 101234543 101234545 101234565 101234567 121010101
121010121 121010123 121012101 121012121 121012123 121012321 121012323 121012343 121012345
121210101 121210121 121210123 121212101 121212121 121212123 121212321 121212323 121212343
121212345 121232101 121232121 121232123 121232321 121232323 121232343 121232345 121234321
121234323 121234343 121234345 121234543 121234545 121234565 121234567 123210101 123210121
123210123 123212101 123212121 123212123 123212321 123212323 123212343 123212345 123232101
123232121 123232123 123232321 123232323 123232343 123232345 123234321 123234323 123234343
123234345 123234543 123234545 123234565 123234567 123432101 123432121 123432123 123432321
123432323 123432343 123432345 123434321 123434323 123434343 123434345 123434543 123434545
123434565 123434567 123454321 123454323 123454343 123454345 123454543 123454545 123454565
123454567 123456543 123456545 123456565 123456567 123456765 123456767 123456787 123456789