Numbers with equal rises and falls: Difference between revisions
m
→{{header|EasyLang}}
(Added XPL0 example.) |
|||
(13 intermediate revisions by 10 users not shown) | |||
Line 31:
{{trans|Python}}
<
‘Check whether a number belongs to sequence A296712.’
V height = 0
Line 58:
L 0 .< 10'000'000 - 200 - 1
nextNum()
print(‘The 10,000,000th number is: ’nextNum())</
{{out}}
Line 69:
=={{header|8080 Assembly}}==
<
putch: equ 2
org 100h
Line 153:
num: db '0 $'
;;; 24-bit counter to keep track of ten million
ctr: db 80h,96h,98h ; 1e7 = 989680h</
{{out}}
Line 164:
=={{header|8086 Assembly}}==
<
cpu 8086
bits 16
Line 241:
;;; Current number, stored as ASCII
db 0,0,0,0,0,0,0,0
num: db '0 $'</
{{out}}
Line 251:
=={{header|Ada}}==
<
with Ada.Integer_Text_Io;
Line 294:
Value := Value + 1;
end loop;
end Equal_Rise_Fall;</
{{out}}
<pre>
Line 312:
=={{header|ALGOL 68}}==
{{trans|Wren}}... with a single counter for rises and falls.
<
# returns TRUE if the number of digits in n followed by a higher digit (rises) #
# equals the number of digits followed by a lower digit (falls) #
Line 349:
OD
END
</syntaxhighlight>
{{out}}
<pre>
Line 370:
{{works with|Dyalog APL}}
<
⍝ Determine if a number is in the sequence
inSeq←0=(+/2(<->)/10(⊥⍣¯1)⊢)
Line 385:
⍞←'The 10,000,000th number is: '
⎕←1e7{⍺=0:⍵-1 ⋄ (⍺-inSeq ⍵)∇ ⍵+1}1
}</
{{out}}
Line 410:
=={{header|AutoHotkey}}==
<
count := 0, result1 := result1 := ""
loop{
Line 445:
if (fall = rise)
return 1
}</
{{out}}
<pre>The first 200 numbers in the sequence:
Line 462:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f NUMBERS_WITH_EQUAL_RISES_AND_FALLS.AWK
# converted from Go
Line 503:
return(rises == falls)
}
</syntaxhighlight>
{{out}}
<pre>
Line 521:
</pre>
=={{header|
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">c = 0
i = 1
while c < 10000001
if eqrf(i) then
c += 1
if c <= 200 then print i;" ";
if c = 10000000 then print : print i
end if
i += 1
end while
end
function eqrf(n)
sn$ = string(n)
q = 0
for i = 2 to length(sn$)
if asc(mid(sn$,i,1)) > asc(mid(sn$,i-1,1)) then
q += 1
else
if asc(mid(sn$,i,1)) < asc(mid(sn$,i-1,1)) then
q -= 1
end if
end if
next i
if q = 0 then return true else return false
end function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">function eqrf( n as uinteger ) as boolean
dim as string sn = str(n)
dim as integer q = 0
for i as uinteger = 2 to len(sn)
if asc(mid(sn,i,1)) > asc(mid(sn,i-1,1)) then
q += 1
elseif asc(mid(sn,i,1)) < asc(mid(sn,i-1,1)) then
q -= 1
end if
next i
if q = 0 then return true else return false
end function
dim as uinteger c = 0, i = 1
while c < 10000001
if eqrf(i) then
c += 1
if c <= 200 then print i;" ";
if c = 10000000 then print : print i
end if
i += 1
wend</syntaxhighlight>
{{out}}
<pre>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 153 154 160 161 162 163 164 165 170 171 172 173 174 175 176 180 181 182 183 184 185 186 187 190 191 192 193 194 195 196 197 198 201 202 203 204 205 206 207 208 209 212 213 214 215 216 217 218 219 222 230 231 232 240 241 242 243 250 251 252 253 254 260 261 262 263 264 265 270 271 272 273 274 275 276 280 281 282 283 284 285 286 287 290 291 292 293 294 295 296 297 298 301 302 303 304 305 306 307 308 309 312 313 314 315 316 317 318 319 323 324 325 326 327 328 329 333 340 341 342 343 350 351 352 353 354 360 361 362 363 364 365 370 371 372 373 374 375 376 380 381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404
41909002</pre>
==={{header|Gambas}}===
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim c As Integer = 0, i As Integer = 1
While c < 10000001
If eqrf(i) Then
c += 1
If c <= 200 Then Print " "; i;
If c = 10000000 Then Print Chr(10); i
End If
i += 1
Wend
End
Function eqrf(n As Integer) As Boolean
Dim sn As String = Str(n)
Dim q As Integer = 0, i As Integer
For i = 2 To Len(sn)
If Asc(Mid(sn, i, 1)) > Asc(Mid(sn, i - 1, 1)) Then
q += 1
Else If Asc(Mid(sn, i, 1)) < Asc(Mid(sn, i - 1, 1)) Then
q -= 1
End If
Next
If q = 0 Then Return True Else Return False
End Function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="PureBasic">Procedure.b eqrf(n.i)
sn.s = Str(n)
q.i = 0
For i.i = 2 To Len(sn)
If Asc(Mid(sn, i, 1)) > Asc(Mid(sn, i - 1, 1)):
q + 1
Else
If Asc(Mid(sn, i, 1)) < Asc(Mid(sn, i - 1, 1)):
q - 1
EndIf
EndIf
Next
If q = 0:
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
OpenConsole()
c.i = 0
i.i = 1
While c < 10000001
If eqrf(i):
c + 1
If c <= 200:
Print(" " + Str(i))
EndIf
If c = 10000000:
PrintN(#CRLF$ + Str(i))
EndIf
EndIf
i + 1
Wend
Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>
/* Check whether a number has an equal amount of rises
Line 561 ⟶ 696:
return 0;
}</
{{out}}
Line 571 ⟶ 706:
=={{header|C++}}==
<
#include <iostream>
Line 600 ⟶ 735:
}
std::cout << "\nThe " << limit2 << "th number in the sequence is " << n << ".\n";
}</
{{out}}
Line 620 ⟶ 755:
=={{header|CLU}}==
<
rises_falls = proc (n: int) returns (int,int)
rises: int := 0
Line 663 ⟶ 798:
end
end
end start_up</
{{out}}
<pre> 1 2 3 4 5 6 7 8 9 11
Line 689 ⟶ 824:
=={{header|Cowgol}}==
<
# return the change in height of a number
Line 737 ⟶ 872:
print("The 10,000,000th number is: ");
print_i32(number);
print_nl();</
{{out}}
Line 765 ⟶ 900:
The 10,000,000th number is: 41909002
</pre>
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
procedure GetDigits(N: integer; var IA: TIntegerDynArray);
{Get an array of the integers in a number}
var T: integer;
begin
SetLength(IA,0);
repeat
begin
T:=N mod 10;
N:=N div 10;
SetLength(IA,Length(IA)+1);
IA[High(IA)]:=T;
end
until N<1;
end;
function HasEqualRiseFall(N: integer): boolean;
{Count rises and falls in numbers left to Right}
var I: integer;
var IA: TIntegerDynArray;
var Rise,Fall: integer;
begin
Rise:=0; Fall:=0;
GetDigits(N,IA);
for I:=High(IA) downto 1 do
if IA[I-1]>IA[I] then Inc(Rise)
else if IA[I-1]<IA[I] then Inc(Fall);
Result:=Rise=Fall;
end;
procedure ShowEqualRiseFall(Memo: TMemo);
var I,Cnt: integer;
var S: string;
begin
Cnt:=0;
S:='';
for I:=1 to High(integer) do
if HasEqualRiseFall(I) then
begin
Inc(Cnt);
S:=S+Format('%4.0d', [I]);
if (Cnt mod 20)=0 then S:=S+CRLF;
if Cnt=200 then break;
end;
Memo.Text:=S;
Memo.Lines.Add('Count = '+IntToStr(Cnt));
for I:=1 to High(integer) do
if HasEqualRiseFall(I) then
begin
Inc(Cnt);
if Cnt>=10000000 then
begin
Memo.Lines.Add('10-Million: '+IntToStr(I));
break;
end;
end;
end;
</syntaxhighlight>
{{out}}
<pre>
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
153 154 160 161 162 163 164 165 170 171 172 173 174 175 176 180 181 182 183 184
185 186 187 190 191 192 193 194 195 196 197 198 201 202 203 204 205 206 207 208
209 212 213 214 215 216 217 218 219 222 230 231 232 240 241 242 243 250 251 252
253 254 260 261 262 263 264 265 270 271 272 273 274 275 276 280 281 282 283 284
285 286 287 290 291 292 293 294 295 296 297 298 301 302 303 304 305 306 307 308
309 312 313 314 315 316 317 318 319 323 324 325 326 327 328 329 333 340 341 342
343 350 351 352 353 354 360 361 362 363 364 365 370 371 372 373 374 375 376 380
381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404
Count = 200
10-Million: 41907794
Elapsed Time: 28.140 Sec.
</pre>
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight>
fastfunc risefall n .
if n < 10
return 1
.
prev = -1
while n > 0
d = n mod 10
if prev >= 0
if d < prev
rises += 1
elif d > prev
falls += 1
.
.
prev = d
n = n div 10
.
if rises = falls
return 1
.
return 0
.
numfmt 0 4
n = 1
repeat
if risefall n = 1
cnt += 1
if cnt <= 200
write n
if cnt mod 10 = 0
print ""
.
.
.
until cnt = 1e7
n += 1
.
print ""
print n
</syntaxhighlight>
=={{header|F_Sharp|F#}}==
<
// A296712. Nigel Galloway: October 9th., 2020
let fN g=let rec fN Ψ n g=match n,Ψ with (0,0)->true |(0,_)->false |_->let i=n%10 in fN (Ψ + (compare i g)) (n/10) i in fN 0 g (g%10)
Line 773 ⟶ 1,041:
A296712|>Seq.take 200|>Seq.iter(printf "%d "); printfn"\n"
[999999;9999999;99999999]|>List.iter(fun n->printfn "The %dth element is %d" (n+1) (Seq.item n A296712))
</syntaxhighlight>
{{out}}
<pre>
Line 785 ⟶ 1,053:
=={{header|Factor}}==
{{works with|Factor|0.99 2020-08-14}}
<
prettyprint tools.memory.private ;
Line 800 ⟶ 1,068:
"The 10 millionth number in OEIS:A296712 is " write
9,999,999 OEIS:A296712 lnth commas print</
{{out}}
<pre>
Line 820 ⟶ 1,088:
=={{header|Forth}}==
<
0 swap \ height
10 /mod \ digit and rest of number
Line 855 ⟶ 1,123:
." The first 200 numbers are: " two-hundred cr cr
." The 10,000,000th number is: " ten-million . cr
bye</
{{out}}
Line 866 ⟶ 1,134:
=={{header|Fortran}}==
<
INTEGER IDX, NUM, I
* Index and number start out at zero
Line 917 ⟶ 1,185:
IN SEQ = HEIGHT.EQ.0
RETURN
END </
{{out}}
Line 935 ⟶ 1,203:
The 10,000,000th number is: 41909002
</pre>
=={{header|Go}}==
{{trans|Wren}}
<
import "fmt"
Line 1,011 ⟶ 1,252:
n++
}
}</
{{out}}
Line 1,032 ⟶ 1,273:
=={{header|Haskell}}==
<
pairs :: [a] -> [(a,a)]
Line 1,053 ⟶ 1,294:
putStr "The 10,000,000th number is: "
putStrLn $ show $ a296712 !! 9999999
</syntaxhighlight>
{{out}}
Line 1,062 ⟶ 1,303:
The 10,000,000th number is: 41909002
</pre>
=={{header|J}}==
<syntaxhighlight lang="j">NB. This would have been shorter but memory constraints forced me to test candidates
NB. in batches rather than all at once (iPads are amazing but not supercomputers...)
gennumberblocks =: 3 : 0
NB. y Block index. Each block is at most 100000 numbers
NB. Return one or more boxed blocks of numbers, segregated by digit count
(<. 10 ^. n) </. n =. (y * 100000) + >: i.100000
)
testblock =: 3 : 0
NB. y A block of numbers all with the same digit count
NB. Return those that pass the test
y #~ ((+/"1) 2 </\"1 f) = (+/"1) 2 >/\"1 "."1"0 ": ,. y
)
pow =: 3 : 0
NB. Generate and test one or more blocks of numbers and add the results to the
NB. running list of answers
'nextblockindex answers' =. y
(>: nextblockindex) ; answers , ; testblock &. > gennumberblocks nextblockindex
)
go =: 3 : 0
result =: pow ^: ((1e7&>)@#@(1&{::)) ^:_ (0 ; '')
'The first 200 numbers are:' (1!:2) 2
(10 20 $ 200 {. 1 {:: result) (1!:2) 2
'The 10,000,000th number is: ' , ": 9999999 { 1 {:: result
)</syntaxhighlight>
{{out}}
<pre>go ''
The first 200 numbers are:
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
153 154 160 161 162 163 164 165 170 171 172 173 174 175 176 180 181 182 183 184
185 186 187 190 191 192 193 194 195 196 197 198 201 202 203 204 205 206 207 208
209 212 213 214 215 216 217 218 219 222 230 231 232 240 241 242 243 250 251 252
253 254 260 261 262 263 264 265 270 271 272 273 274 275 276 280 281 282 283 284
285 286 287 290 291 292 293 294 295 296 297 298 301 302 303 304 305 306 307 308
309 312 313 314 315 316 317 318 319 323 324 325 326 327 328 329 333 340 341 342
343 350 351 352 353 354 360 361 362 363 364 365 370 371 372 373 374 375 376 380
381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404
The 10,000,000th number is: 41909002 </pre>
=={{header|Java}}==
<
public static void main(String[] args) {
final int limit1 = 200;
Line 1,092 ⟶ 1,380:
return total == 0;
}
}</
{{out}}
Line 1,117 ⟶ 1,405:
(*) gojq requires a very large amount of memory for computing the 10 millionth number in the sequence.
<
. as $n
| if . < 10 then true
Line 1,150 ⟶ 1,438:
"\nThe 10 millionth number in the sequence is \(
nth(1e7 - 1; A296712))"</
{{out}}
<pre>
Line 1,161 ⟶ 1,449:
=={{header|Julia}}==
<
function rises_and_falls(n)
Line 1,196 ⟶ 1,484:
genA296712(200, 10_000_000)
</
<pre>
1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 101 102
Line 1,214 ⟶ 1,502:
=={{header|MAD}}==
<
VECTOR VALUES FMT = $I8,1H:,I9*$
Line 1,241 ⟶ 1,529:
PRINT FORMAT FMT, I, J
END OF PROGRAM</
{{out}}
Line 1,448 ⟶ 1,736:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
EqualRisesAndFallsQ[n_Integer] := Total[Sign[Differences[IntegerDigits[n]]]] == 0
Take[Select[Range[1000], EqualRisesAndFallsQ], 200]
Line 1,460 ⟶ 1,748:
,
{i, 50 10^6}
]</
{{out}}
<pre>{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,153,154,160,161,162,163,164,165,170,171,172,173,174,175,176,180,181,182,183,184,185,186,187,190,191,192,193,194,195,196,197,198,201,202,203,204,205,206,207,208,209,212,213,214,215,216,217,218,219,222,230,231,232,240,241,242,243,250,251,252,253,254,260,261,262,263,264,265,270,271,272,273,274,275,276,280,281,282,283,284,285,286,287,290,291,292,293,294,295,296,297,298,301,302,303,304,305,306,307,308,309,312,313,314,315,316,317,318,319,323,324,325,326,327,328,329,333,340,341,342,343,350,351,352,353,354,360,361,362,363,364,365,370,371,372,373,374,375,376,380,381,382,383,384,385,386,387,390,391,392,393,394,395,396,397,398,401,402,403,404}
Line 1,466 ⟶ 1,754:
=={{header|Nim}}==
<
func insequence(n: Positive): bool =
Line 1,498 ⟶ 1,786:
elif pos == 10_000_000:
echo "\nTen millionth number in the sequence: ", n
break</
{{out}}
Line 1,516 ⟶ 1,804:
=={{header|Perl}}==
<
use strict;
Line 1,544 ⟶ 1,832:
rf(++$n) or $count++;
}
print "\n10,000,000th number: $n\n";</
{{out}}
<pre>
Line 1,565 ⟶ 1,853:
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">t1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()+</span><span style="color: #000000;">1</span>
<span style="color: #004080;">integer</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: #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 200 numbers are:\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</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;">rmf</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">l</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;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</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: #008080;">while</span> <span style="color: #000000;">r</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">rmf</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">compare</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">p</span>
<span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">/</span><span style="color: #000000;">10</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;">rmf</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</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;">200</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;">"%3d "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</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;">20</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</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;">"\n"</span><span style="color: #0000FF;">)</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: #008080;">if</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">1e7</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</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: #008080;">exit</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()></span><span style="color: #000000;">t1</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%,d:%,d\r"</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: #000000;">t1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()+</span><span style="color: #000000;">1</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: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,617 ⟶ 1,908:
=={{header|Python}}==
<
def riseEqFall(num):
Line 1,650 ⟶ 1,941:
# It is necessary to subtract 200 from the index, because 200 numbers
# have already been consumed.
</syntaxhighlight>
{{out}}
Line 1,659 ⟶ 1,950:
</pre>
=={{header|Quackery}}==
<syntaxhighlight lang="Quackery"> [ [] swap
[ 10 /mod
rot join swap
dup 0 = until ]
drop ] is digits ( n --> [ )
[ stack ] is rises
[ stack ] is falls
[ 0 rises put
0 falls put
digits
behead swap witheach
[ tuck 2dup < iff
[ 1 rises tally
2drop ] done
> if
[ 1 falls tally ] ]
drop
rises take
falls take = ] is equal ( n --> b )
[] 0
[ 1+ dup equal if
[ tuck join swap ]
over size 200 = until ]
drop
echo
cr cr
0 0
[ 1+ dup equal if
[ dip 1+ ]
over 10000000 = until ]
nip
echo</syntaxhighlight>
{{out}}
<pre>[ 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 153 154 160 161 162 163 164 165 170 171 172 173 174 175 176 180 181 182 183 184 185 186 187 190 191 192 193 194 195 196 197 198 201 202 203 204 205 206 207 208 209 212 213 214 215 216 217 218 219 222 230 231 232 240 241 242 243 250 251 252 253 254 260 261 262 263 264 265 270 271 272 273 274 275 276 280 281 282 283 284 285 286 287 290 291 292 293 294 295 296 297 298 301 302 303 304 305 306 307 308 309 312 313 314 315 316 317 318 319 323 324 325 326 327 328 329 333 340 341 342 343 350 351 352 353 354 360 361 362 363 364 365 370 371 372 373 374 375 376 380 381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404 ]
41909002</pre>
=={{header|Raku}}==
{{works with|Rakudo|2020.09}}
<syntaxhighlight lang="raku"
use Base::Any;
Line 1,718 ⟶ 2,052:
put "Base {$base.fmt(<%2d>)} (https://oeis.org/A$oeis): ",
$upto.map({rf(+$base, Any, &infix:«<»)[.exp(10) - 1].&to-base($base)}).join: ', '
}</
{{out}}
<pre>Rise = Fall:
Line 1,795 ⟶ 2,129:
To do the heavy lifting, this REXX program constructs a table of every two-digit sequence which indicates a
<br>'''rise''' (+1), '''fall''' (-1), or '''neither''' (0).
<
parse arg n . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 200 /*Not specified? Then use the default.*/
Line 1,829 ⟶ 2,163:
end /*o*/ /* [↑] display 20 numbers to a line.*/
if _\=='' then say substr(_, 2); return /*handle any residual numbers in list. */</
{{out|output|text= when using the default input:}}
<pre>
Line 1,850 ⟶ 2,184:
</pre>
=={{header|RPL}}==
≪ '''IF''' DUP 9 ≤ '''THEN''' SIGN
'''ELSE''' →STR → num
≪ 0 num 1 1 SUB NUM
2 num SIZE '''FOR''' j
num j DUP SUB NUM SWAP OVER - SIGN ROT + SWAP '''NEXT'''
DROP NOT
≫ '''END'''
≫ ''''RNF'''' STO ''( n -- boolean )''
≪ → test n
≪ { } 1 9 CF '''WHILE''' 9 FC? '''REPEAT'''
'''IF''' DUP test EVAL '''THEN''' SWAP OVER + SWAP '''IF''' OVER SIZE n ≥ '''THEN''' 9 SF '''END END'''
1 +
'''END''' DROP
≫ ≫ ''''TBOOL'''' STO ''( 'FUNC' n -- { first_n_true_integers } )''
'RNF' 200 '''TBOOL'''
{{out}}
<pre>
1: { 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 153 154 160 161 162 163 164 165 170 171 172 173 174 175 176 180 181 182 183 184 185 186 187 190 191 192 193 194 195 196 197 198 201 202 203 204 205 206 207 208 209 212 213 214 215 216 217 218 219 222 230 231 232 240 241 242 243 250 251 252 253 254 260 261 262 263 264 265 270 271 272 273 274 275 276 280 281 282 283 284 285 286 287 290 291 292 293 294 295 296 297 298 301 302 303 304 305 306 307 308 309 312 313 314 315 316 317 318 319 323 324 325 326 327 328 329 333 340 341 342 343 350 351 352 353 354 360 361 362 363 364 365 370 371 372 373 374 375 376 380 381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404 }
</pre>
Due to emulator’s watchdog timer, the ten millionth number is out of reach.
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">class Integer
def eq_rise_fall? = digits.each_cons(2).sum{|a,b| a <=> b} == 0
end
puts (1..).lazy.select(&:eq_rise_fall?).take(200).force.join(" ")
n = 10_000_000
res = (1..).lazy.select(&:eq_rise_fall?).take(n).drop(n-1).first
puts "The #{n}th number in the sequence is #{res}."
</syntaxhighlight>
{{out}}
<pre>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 153 154 160 161 162 163 164 165 170 171 172 173 174 175 176 180 181 182 183 184 185 186 187 190 191 192 193 194 195 196 197 198 201 202 203 204 205 206 207 208 209 212 213 214 215 216 217 218 219 222 230 231 232 240 241 242 243 250 251 252 253 254 260 261 262 263 264 265 270 271 272 273 274 275 276 280 281 282 283 284 285 286 287 290 291 292 293 294 295 296 297 298 301 302 303 304 305 306 307 308 309 312 313 314 315 316 317 318 319 323 324 325 326 327 328 329 333 340 341 342 343 350 351 352 353 354 360 361 362 363 364 365 370 371 372 373 374 375 376 380 381 382 383 384 385 386 387 390 391 392 393 394 395 396 397 398 401 402 403 404
The 10000000th number in the sequence is 41909002.
</pre>
=={{header|Sidef}}==
<
var diffs = arr.map_cons(2, {|a,b| a - b })
diffs.count { .is_pos } == diffs.count { .is_neg }
Line 1,868 ⟶ 2,241:
say "\nThe #{n.commify}-th term (base #{base}): #{
n.th { isok(.digits(base)) && .is_pos }.commify}"
}</
{{out}}
<pre>
Line 1,887 ⟶ 2,260:
=={{header|Swift}}==
<
func equalRisesAndFalls(_ n: Int) -> Bool {
Line 1,920 ⟶ 2,293:
}
}
print("\nThe \(limit2)th number in the sequence is \(n).")</
{{out}}
Line 1,941 ⟶ 2,314:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
var risesEqualsFalls = Fn.new { |n|
Line 1,979 ⟶ 2,352:
}
n = n + 1
}</
{{out}}
Line 1,999 ⟶ 2,372:
=={{header|XPL0}}==
<
int N, R, F, D, D0;
[R:= 0; F:= 0;
Line 2,032 ⟶ 2,405:
N:= N+1;
];
]</
{{out}}
|