Shape-Machine: Difference between revisions
Content added Content deleted
No edit summary |
(Added XPL0 example.) |
||
Line 57: | Line 57: | ||
<pre style="font-family: consolas, inconsolata, monospace; line-height: normal;"> |
<pre style="font-family: consolas, inconsolata, monospace; line-height: normal;"> |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
{{trans|Python}} |
|||
<syntaxhighlight lang "XPL0">real A; |
|||
[A:= RlIn(0); |
|||
while true do |
|||
[A:= A+3.; |
|||
A:= A*0.86; |
|||
RlOut(0, A); |
|||
]; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
123 |
|||
108.36000 95.76960 84.94186 75.63000 67.62180 60.73475 54.81188 49.71822 |
|||
45.33767 41.57039 38.33054 35.54426 33.14807 31.08734 29.31511 27.79099 |
|||
26.48026 25.35302 24.38360 23.54989 22.83291 22.21630 21.68602 21.22998 |
|||
20.83778 20.50049 20.21042 19.96096 19.74643 19.56193 19.40326 19.26680 |
|||
19.14945 19.04853 18.96173 18.88709 18.82290 18.76769 18.72022 18.67939 |
|||
18.64427 18.61407 18.58810 18.56577 18.54656 18.53004 18.51584 18.50362 |
|||
18.49311 18.48408 18.47631 18.46962 18.46388 18.45893 18.45468 18.45103 |
|||
18.44788 18.44518 18.44285 18.44085 18.43914 18.43766 18.43638 18.43529 |
|||
18.43435 18.43354 18.43285 18.43225 18.43173 18.43129 18.43091 18.43058 |
|||
18.43030 18.43006 18.42985 18.42967 18.42952 18.42938 18.42927 18.42917 |
|||
18.42909 18.42902 18.42895 18.42890 18.42885 18.42881 18.42878 18.42875 |
|||
18.42873 18.42870 18.42869 18.42867 18.42866 18.42864 18.42863 18.42863 |
|||
18.42862 18.42861 18.42861 18.42860 18.42860 18.42859 18.42859 18.42859 |
|||
18.42859 18.42858 18.42858 18.42858 18.42858 18.42858 18.42858 18.42858 |
|||
18.42858 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 |
|||
18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 |
|||
18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 |
|||
</pre> |
Revision as of 20:27, 5 July 2024
Shape-Machine 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.
Task
- Get user input and store in a variable/stack
- Add 3 to the input and multiply it by 0.86 and then output it
- Now repeat the previous step
- And after the number stops doing the second step you can halt the loop and count how many times did the operation happened (optional)
See Also
Python
a=int(input()) while True: a += 3 a *= 0.86 print(a)
Raku
my $input = (+prompt()).FatRat;
my $previous = 0.FatRat;
my $count;
my $places = 36;
loop {
$input += 3;
$input ×= .86;
last if $previous.substr(0,$places) eq $input.substr(0,$places);
++$count;
say ($previous = $input).substr(0,$places);
}
say "$count repetitions";
- Output with a 4 fed in at the prompt:
4 6.02 7.7572 9.251192 10.53602512 11.6409816032 12.591244178752 13.40846999372672 14.1112841946049792 14.715704407360282112 15.23550579032984261632 15.6825349796836646500352 16.066980082527951599030272 ... many, many lines omitted ... 18.428571428571428571428571428571416 18.428571428571428571428571428571418 18.428571428571428571428571428571419 18.428571428571428571428571428571420 18.428571428571428571428571428571421 18.428571428571428571428571428571422 18.428571428571428571428571428571423 18.428571428571428571428571428571424 512 repetitions
XPL0
real A;
[A:= RlIn(0);
while true do
[A:= A+3.;
A:= A*0.86;
RlOut(0, A);
];
]
- Output:
123 108.36000 95.76960 84.94186 75.63000 67.62180 60.73475 54.81188 49.71822 45.33767 41.57039 38.33054 35.54426 33.14807 31.08734 29.31511 27.79099 26.48026 25.35302 24.38360 23.54989 22.83291 22.21630 21.68602 21.22998 20.83778 20.50049 20.21042 19.96096 19.74643 19.56193 19.40326 19.26680 19.14945 19.04853 18.96173 18.88709 18.82290 18.76769 18.72022 18.67939 18.64427 18.61407 18.58810 18.56577 18.54656 18.53004 18.51584 18.50362 18.49311 18.48408 18.47631 18.46962 18.46388 18.45893 18.45468 18.45103 18.44788 18.44518 18.44285 18.44085 18.43914 18.43766 18.43638 18.43529 18.43435 18.43354 18.43285 18.43225 18.43173 18.43129 18.43091 18.43058 18.43030 18.43006 18.42985 18.42967 18.42952 18.42938 18.42927 18.42917 18.42909 18.42902 18.42895 18.42890 18.42885 18.42881 18.42878 18.42875 18.42873 18.42870 18.42869 18.42867 18.42866 18.42864 18.42863 18.42863 18.42862 18.42861 18.42861 18.42860 18.42860 18.42859 18.42859 18.42859 18.42859 18.42858 18.42858 18.42858 18.42858 18.42858 18.42858 18.42858 18.42858 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857 18.42857