Floyd's triangle: Difference between revisions

(Floyd's triangle en QBasic and Yabasic)
Line 1,637:
 
=={{header|Batch File}}==
{{trans|QBasic}}
{{incorrect|Batch File|The last line should only have one space between values}}
<lang dos>:: Floyd's triangle Task from Rosetta Code
<lang dos>
:: Batch File Implementation
 
@echo off
rem main thing
 
call:floyd 5
echo.
call:floyd 14
pause>nul
exit /b
 
:floyd
setlocal enabledelayedexpansion
call :floydtriangle 5
set iterations=%1
echo.(
set startn=1
call :floydtriangle 14
set endn=1
exit /b 0
 
:floydtriangle
for /l %%i in (1,1,%iterations%) do (
set startn"fila=%1"
for /l %%j in (!startn!,1,!endn!) do (
for /l %%ic in (1,1,%iterationsfila%) do (
set lastnum=%%j
set /a startn"lastRowNum=%%jc+fila*(fila-1)/2"
rem count number of digits of whole number trick
)
rem source: https://stackoverflow.com/a/45472269
set /a endn=!startn!+%%i
set /a "Log=1!lastRowNum:~1!-!lastRowNum:~1!-0"
set /a startn="numColum[%%jc]=!Log:0=+1!"
)
echo(Output for %fila%
 
set "linethisNum=1"
call:getlength %startn%
for /l %%ir in (1,1,%iterationsfila%) do (
set digits=%errorlevel%
set lastnum"printLine=%%j"
 
for /l %%jc in (!startn!1,1,!endn!%%r) do (
set startn=1
rem count number of digits of whole number trick
set endn=1
set /a "Log=1!thisNum:~1!-!thisNum:~1!-0"
 
set /a "thisNumColum=!Log:0=+1!"
for /l %%i in (1,1,%iterations%) do (
rem handle spacing
set "line="
set "space= "
for /l %%j in (!startn!,1,!endn!) do (
set /a "spaceextra=!numColum[%%c]!-!thisNumColum!"
for /l %%s in (1,1,!extra!) do set "space=!space! "
call:getlength %%j
rem append current number to printLine
set /a sparespace=%digits%-!errorlevel!
for /l %%k in (0,1,!sparespace!) do set "spaceprintLine=!printLine!!space! !thisNum!"
set /a "thisNum=!thisNum!+1"
)
set line=!line!!space!%%j
echo(!printLine!
set /a startn=%%j+1
)
echo !line!
set /a endn=!startn!+%%i
)
goto :EOF</lang>
exit /b
 
:getlength
setlocal enabledelayedexpansion
set offset=0
set string=%1
:floydloop
if "!string:~%offset%,1!"=="" endlocal && exit /b %offset%
set /a offset+=1
goto floydloop
</lang>
{{out}}
<pre>Output for 5
1
2 3
Line 1,700 ⟶ 1,685:
11 12 13 14 15
 
Output for 14
1
2 31
2 4 5 63
4 7 5 8 9 106
117 128 139 14 1510
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
56 57 6758 59 6860 61 6962 63 70 64 71 65 72 73 74 75 76 77 7866
67 68 7969 70 8071 72 8173 74 82 75 83 76 84 77 85 86 87 88 89 90 9178
79 80 9281 82 9383 84 9485 86 95 87 96 88 97 89 98 90 99 100 101 102 103 104 10591
92 93 94 95 96 97 98 99 100 101 102 103 104 105</pre>
</pre>
 
=={{header|BCPL}}==
535

edits