Numbers with equal rises and falls: Difference between revisions

→‎{{header|Raku}}: Generalize further
(Add a related task)
(→‎{{header|Raku}}: Generalize further)
Line 786:
use Base::Any;
 
sub rf (int $base = 10, $batch = Any, &op = &infix:<==>) {
my %batch = batch => $batch if $batch;
lazy flat (1 ..^ $base, ($base .. ∞).hyper(|%batch).map: {
my int ($this, $last) = $_, $_ % $base;
my int ($rise, $fall) = 0, 0;
Line 798:
$last = $rem
}
next unless &op($rise ==, $fall);
$_
}
}
 
# The task
my $upto = 200;
put "FirstRise = Fall:\nFirst {$upto.&cardinal} (base 10):";
.put for rf[^$upto]».fmt("%3d").batch(20);
 
$upto = 10_000_000;
put "\nThe {$upto.&commaordinal}th (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 = ^65;
for 2, 'A005408',
putmy $which = "\n{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$base, $oeis 'A296706',{
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$base, 'A296759',$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 {
put "Base {$base.fmt(<%2d>)} (OEIShttps://oeis.org/A$oeis): ",
$upto.map({rf(+$base, 5000Any, &infix:«<»)[.exp(10) - 1].&to-base($base)}).join: ', '
}</lang>
{{out}}
<pre>FirstRise 200= (base 10)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
103 104 105 106 107 108 109 111 120 121 130 131 132 140 141 142 143 150 151 152
Line 846 ⟶ 853:
381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404
 
The 10,000,000thten 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 (OEIShttps://oeis.org/A296765): 1, A, ff, 1f2, 63Q, g5D</pre>
 
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
 
Rise < Fall: First, tenth, one hundredth, one thousandth, ten thousandth, one hundred 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 34 (OEIShttps:A296691//oeis.org/A296696): 110, 201210, 221123330, 10101111231210, 1100022001, 11201022001013132000
Base 45 (OEIShttps:A296694//oeis.org/A296699): 110, 11143, 33332420, 22101243033, 13002120, 10230320032030042
Base 56 (OEIShttps:A296697//oeis.org/A296702): 110, 10243, 14411540, 4001125543, 1431201, 40142240403531
Base 67 (OEIShttps:A296700//oeis.org/A296705): 110, 5543, 5121010, 2042410051, 400402, 10405133206260
Base 78 (OEIShttps:A296703//oeis.org/A296708): 110, 4443, 365660, 126205732, 155554, 252521575051
Base 89 (OEIShttps:A296706//oeis.org/A296711): 110, 3343, 316643, 74665010, 60404, 133662160873
Base 910 (OEIShttps:A296709//oeis.org/A296714): 1, 2210, 27543, 5113621, 402174120, 66583644100
Base 1011 (OEIShttps:A296712//oeis.org/A296746): 1, 1110, 25243, 3396544, 292013243, 39332931160
Base 1112 (OEIShttps:A296744//oeis.org/A296749): 110, A43, 216520, 22402A71, 21718, 21778518321
Base 1213 (OEIShttps:A296747//oeis.org/A296752): 110, A43, 201422, 10AA2164, 19723, B3025B624
Base 1314 (OEIShttps:A296750//oeis.org/A296755): 110, A43, 1B8310, A0A1CA3, 172A7, 823C8A506
Base 1415 (OEIShttps:A296753//oeis.org/A296758): 110, A43, 1B5E8, 8B91A20, 14B81, 6476D9518
Base 1516 (OEIShttps:A296756//oeis.org/A296761): 110, A43, 1B2E8, 7D410D0, 11BBA, 51013860D
Base 1620 (OEIShttps:A296759//oeis.org/A296764): 110, A43, 1A9E8, 716G33, 10424, 41E9D5F43
Base 2060 (OEIShttps:A296762//oeis.org/A296767): 110, A43, 196E8, 523j9, 8011, 24HE2ZUT</pre>
Base 60 (OEIS:A296765): 1, A, ff, 1f2, 63Q, g5D</pre>
 
=={{header|REXX}}==
10,327

edits