Numbers with equal rises and falls: Difference between revisions

Content added Content deleted
(Add a related task)
(→‎{{header|Raku}}: Generalize further)
Line 786: Line 786:
use Base::Any;
use Base::Any;


sub rf (int $base = 10, $batch = Any) {
sub rf (int $base = 10, $batch = Any, &op = &infix:<==>) {
my %batch = batch => $batch if $batch;
my %batch = batch => $batch if $batch;
lazy flat 1 ..^ $base, ($base .. ∞).hyper(|%batch).map: {
flat (1 .. ∞).hyper(|%batch).map: {
my int ($this, $last) = $_, $_ % $base;
my int ($this, $last) = $_, $_ % $base;
my int ($rise, $fall) = 0, 0;
my int ($rise, $fall) = 0, 0;
Line 798: Line 798:
$last = $rem
$last = $rem
}
}
next unless $rise == $fall;
next unless &op($rise, $fall);
$_
$_
}
}
}
}


# The task
my $upto = 200;
my $upto = 200;
put "First $upto (base 10):";
put "Rise = Fall:\nFirst {$upto.&cardinal} (base 10):";
.put for rf[^$upto]».fmt("%3d").batch(20);
.put for rf[^$upto]».fmt("%3d").batch(20);


$upto = 10_000_000;
$upto = 10_000_000;
put "\nThe {$upto.&comma}th (base 10): ", comma rf(10, 65536)[$upto - 1];
put "\nThe {$upto.&ordinal} (base 10): ", comma rf(10, 65536)[$upto - 1];


# Other bases and comparisons
$upto = ^6;
put "\n\nGeneralized for other bases and other comparisons:";
put "\n{tc $upto.map({.exp(10).&ordinal}).join: ', '}, values in some other bases:";
$upto = ^5;
for 2, 'A005408',
my $which = "{tc $upto.map({.exp(10).&ordinal}).join: ', '}, values in some other bases:";
3, 'A296691',

4, 'A296694',
put "\nRise = Fall: $which";
5, 'A296697',
for <3 296691 4 296694 5 296697 6 296700 7 296703 8 296706 9 296709 10 296712
6, 'A296700',
11 296744 12 296747 13 296750 14 296753 15 296756 16 296759 20 296762 60 296765>
7, 'A296703',
8, 'A296706',
-> $base, $oeis {
put "Base {$base.fmt(<%2d>)} (https://oeis.org/A$oeis): ",
9, 'A296709',
$upto.map({rf(+$base, Any)[.exp(10) - 1].&to-base($base)}).join: ', '
10, 'A296712',
}
11, 'A296744',

12, 'A296747',
put "\nRise > Fall: $which";
13, 'A296750',
for <3 296692 4 296695 5 296698 6 296701 7 296704 8 296707 9 296710 10 296713
14, 'A296753',
11 296745 12 296748 13 296751 14 296754 15 296757 16 296760 20 296763 60 296766>
15, 'A296756',
16, 'A296759',
-> $base, $oeis {
put "Base {$base.fmt(<%2d>)} (https://oeis.org/A$oeis): ",
20, 'A296762',
$upto.map({rf(+$base, Any, &infix:«>»)[.exp(10) - 1].&to-base($base)}).join: ', '
60, 'A296765'
}

put "\nRise < Fall: $which";
for <3 296693 4 296696 5 296699 6 296702 7 296705 8 296708 9 296711 10 296714
11 296746 12 296749 13 296752 14 296755 15 296758 16 296761 20 296764 60 296767>
-> $base, $oeis {
-> $base, $oeis {
put "Base {$base.fmt(<%2d>)} (OEIS:$oeis): ",
put "Base {$base.fmt(<%2d>)} (https://oeis.org/A$oeis): ",
$upto.map({rf($base, 5000)[.exp(10) - 1].&to-base($base)}).join: ', '
$upto.map({rf(+$base, Any, &infix:«<»)[.exp(10) - 1].&to-base($base)}).join: ', '
}</lang>
}</lang>
{{out}}
{{out}}
<pre>First 200 (base 10):
<pre>Rise = Fall:
First two hundred (base 10):
1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 101 102
1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 101 102
103 104 105 106 107 108 109 111 120 121 130 131 132 140 141 142 143 150 151 152
103 104 105 106 107 108 109 111 120 121 130 131 132 140 141 142 143 150 151 152
Line 846: Line 853:
381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404
381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404


The 10,000,000th (base 10): 41,909,002
The ten millionth (base 10): 41,909,002


Generalized for other bases and other comparisons:

Rise = Fall: First, tenth, one hundredth, one thousandth, ten thousandth, values in some other bases:
Base 3 (https://oeis.org/A296691): 1, 201, 22112, 10101111, 1100022001
Base 4 (https://oeis.org/A296694): 1, 111, 3333, 221012, 13002120
Base 5 (https://oeis.org/A296697): 1, 102, 1441, 40011, 1431201
Base 6 (https://oeis.org/A296700): 1, 55, 512, 20424, 400402
Base 7 (https://oeis.org/A296703): 1, 44, 365, 12620, 155554
Base 8 (https://oeis.org/A296706): 1, 33, 316, 7466, 60404
Base 9 (https://oeis.org/A296709): 1, 22, 275, 5113, 40217
Base 10 (https://oeis.org/A296712): 1, 11, 252, 3396, 29201
Base 11 (https://oeis.org/A296744): 1, A, 216, 2240, 21718
Base 12 (https://oeis.org/A296747): 1, A, 201, 10AA, 19723
Base 13 (https://oeis.org/A296750): 1, A, 1B8, A0A, 172A7
Base 14 (https://oeis.org/A296753): 1, A, 1B5, 8B9, 14B81
Base 15 (https://oeis.org/A296756): 1, A, 1B2, 7D4, 11BBA
Base 16 (https://oeis.org/A296759): 1, A, 1A9, 716, 10424
Base 20 (https://oeis.org/A296762): 1, A, 196, 523, 8011
Base 60 (https://oeis.org/A296765): 1, A, ff, 1f2, 63Q

Rise > Fall: First, tenth, one hundredth, one thousandth, ten thousandth, values in some other bases:
Base 3 (https://oeis.org/A296692): 12, 1222, 122202, 12222001, 2001200001
Base 4 (https://oeis.org/A296695): 12, 233, 12113, 1003012, 13131333
Base 5 (https://oeis.org/A296698): 12, 122, 2302, 112013, 1342223
Base 6 (https://oeis.org/A296701): 12, 45, 1305, 20233, 333134
Base 7 (https://oeis.org/A296704): 12, 34, 1166, 11612, 140045
Base 8 (https://oeis.org/A296707): 12, 26, 1013, 4557, 106756
Base 9 (https://oeis.org/A296710): 12, 25, 348, 2808, 36781
Base 10 (https://oeis.org/A296713): 12, 24, 249, 2345, 23678
Base 11 (https://oeis.org/A296745): 12, 23, 223, 1836, 15806
Base 12 (https://oeis.org/A296748): 12, 1B, 166, 1623, 12534
Base 13 (https://oeis.org/A296751): 12, 1B, 145, 149B, A069
Base 14 (https://oeis.org/A296754): 12, 1B, 12B, 1393, 6BC9
Base 15 (https://oeis.org/A296757): 12, 1B, 11A, 12B7, 568E
Base 16 (https://oeis.org/A296760): 12, 1B, CD, 1206, 466A
Base 20 (https://oeis.org/A296763): 12, 1B, 7E, 6BF, 2857
Base 60 (https://oeis.org/A296766): 12, 1B, 2i, Lp, 66U


First, tenth, one hundredth, one thousandth, ten thousandth, one hundred thousandth, values in some other bases:
Rise < Fall: First, tenth, one hundredth, one thousandth, ten thousandth, values in some other bases:
Base 3 (https://oeis.org/A296693): 10, 221, 22220, 10021001, 1012110000
Base 2 (OEIS:A005408): 1, 10011, 11000111, 11111001111, 100111000011111, 110000110100111111
Base 3 (OEIS:A296691): 1, 201, 22112, 10101111, 1100022001, 112010220010
Base 4 (https://oeis.org/A296696): 10, 210, 3330, 231210, 13132000
Base 4 (OEIS:A296694): 1, 111, 3333, 221012, 13002120, 1023032003
Base 5 (https://oeis.org/A296699): 10, 43, 2420, 43033, 2030042
Base 5 (OEIS:A296697): 1, 102, 1441, 40011, 1431201, 40142240
Base 6 (https://oeis.org/A296702): 10, 43, 1540, 25543, 403531
Base 6 (OEIS:A296700): 1, 55, 512, 20424, 400402, 10405133
Base 7 (https://oeis.org/A296705): 10, 43, 1010, 10051, 206260
Base 7 (OEIS:A296703): 1, 44, 365, 12620, 155554, 2525215
Base 8 (https://oeis.org/A296708): 10, 43, 660, 5732, 75051
Base 8 (OEIS:A296706): 1, 33, 316, 7466, 60404, 1336621
Base 9 (https://oeis.org/A296711): 10, 43, 643, 5010, 60873
Base 9 (OEIS:A296709): 1, 22, 275, 5113, 40217, 665836
Base 10 (https://oeis.org/A296714): 10, 43, 621, 4120, 44100
Base 10 (OEIS:A296712): 1, 11, 252, 3396, 29201, 393329
Base 11 (https://oeis.org/A296746): 10, 43, 544, 3243, 31160
Base 11 (OEIS:A296744): 1, A, 216, 2240, 21718, 217785
Base 12 (https://oeis.org/A296749): 10, 43, 520, 2A71, 18321
Base 12 (OEIS:A296747): 1, A, 201, 10AA, 19723, B3025
Base 13 (https://oeis.org/A296752): 10, 43, 422, 2164, B624
Base 13 (OEIS:A296750): 1, A, 1B8, A0A, 172A7, 823C8
Base 14 (https://oeis.org/A296755): 10, 43, 310, 1CA3, A506
Base 14 (OEIS:A296753): 1, A, 1B5, 8B9, 14B81, 6476D
Base 15 (https://oeis.org/A296758): 10, 43, E8, 1A20, 9518
Base 15 (OEIS:A296756): 1, A, 1B2, 7D4, 11BBA, 51013
Base 16 (https://oeis.org/A296761): 10, 43, E8, 10D0, 860D
Base 16 (OEIS:A296759): 1, A, 1A9, 716, 10424, 41E9D
Base 20 (https://oeis.org/A296764): 10, 43, E8, G33, 5F43
Base 20 (OEIS:A296762): 1, A, 196, 523, 8011, 24HE2
Base 60 (https://oeis.org/A296767): 10, 43, E8, j9, ZUT</pre>
Base 60 (OEIS:A296765): 1, A, ff, 1f2, 63Q, g5D</pre>


=={{header|REXX}}==
=={{header|REXX}}==