Show the (decimal) value of a number of 1s appended with a 3, then squared: Difference between revisions
Show the (decimal) value of a number of 1s appended with a 3, then squared (view source)
Revision as of 14:49, 28 August 2022
, 1 year agosyntax highlighting fixup automation
Drkameleon (talk | contribs) (Added Arturo implementation) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 9:
{{trans|Python}}
<
{{out}}
Line 24:
=={{header|Ada}}==
<
with Ada.Numerics.Big_Numbers.Big_Integers;
Line 44:
Root := @ + 10**(N + 1);
end loop;
end Ones_Plus_Three;</
{{out}}
<pre> 3 9
Line 58:
=={{header|ALGOL 68}}==
Assuming LONG INT is large enough (as in e.g. ALGOL 68G).
<
LONG INT n := 0;
FOR i TO 8 DO
Line 65:
n *:= 10 +:= 1
OD
END</
{{out}}
<pre>
Line 80:
Alternative version that shows the values for higher numbers of ones.
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
<
PR precision 250 PR
LONG LONG INT n := 0;
Line 101:
n *:= 10 +:= 1
OD
END</
{{out}}
Line 137:
=={{header|Arturo}}==
<
num: to :integer(repeat "1" x) ++ "3"
print [num num^2]
]</
{{out}}
Line 154:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f SHOW_THE_DECIMAL_VALUE_OF_A_NUMBER_OF_1S_APPENDED_WITH_A_3_THEN_SQUARED.AWK
# converted from FreeBASIC
Line 170:
return(t+3)
}
</syntaxhighlight>
{{out}}
<pre>
Line 184:
=={{header|C}}==
<
#include <stdint.h>
Line 200:
}
return 0;
}</
{{out}}
Line 216:
{{libheader|System.Numerics}}
For 0 <= n < 22
<
class Program { static void Main(string[] args) {
for (BI x = 3; BI.Log10(x) < 22; x = (x - 2) * 10 + 3)
Console.WriteLine("{1,43} {0,-20}", x, x * x); } }</
{{out}}
<pre> 9 3
Line 245:
=={{header|CLU}}==
<
r: int := 0
for i: int in int$from_to(1, n) do
Line 265:
stream$putl(po, "")
end
end start_up</
{{out}}
<pre> 3^2 = 9
Line 277:
=={{header|COBOL}}==
<
PROGRAM-ID. ONES-THREE-SQUARED.
Line 308:
ADD-ONE.
MULTIPLY 10 BY ONES-3.
ADD 1 TO ONES-3.</
{{out}}
<pre> 3^2 = 9
Line 320:
=={{header|F_Sharp|F#}}==
<
[3L;13L;113L;1113L;11113L;111113L;1111113L;11111113L;111111113L]|>List.iter(fun n->printfn "%10d->%d" n (n*n))
</syntaxhighlight>
{{out}}
<pre>
Line 339:
<big>{{math|a(<var>n</var>) = ((10<sup><var>n</var>+1</sup> - 1) / 9 + 2)<sup>2</sup> }}</big>
{{works with|Factor|0.99 2021-02-05}}
<
: a ( n -- e m ) 1 + 10^ 1 - 9 / 2 + dup sq ;
8 [ a swap pprint bl . ] each-integer</
{{out}}
<pre>
Line 357:
=={{header|Fermat}}==
<
for i=0 to 7 do !Make13(i);!' ';!Make13(i)^2;!!'' od</
{{out}}
<pre>
Line 372:
=={{header|FreeBASIC}}==
<
dim as uinteger t = 0
while n
Line 386:
m = make13(n)^2
print make13(n), m
next n</
{{out}}
<pre>
Line 400:
=={{header|Forth}}==
<
0 swap
begin dup while
Line 420:
8 show-upto
bye</
{{out}}
Line 435:
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 453:
a(n)
}
}</
{{out}}
Line 468:
=={{header|Haskell}}==
<
onesPlusThree :: [Integer]
Line 481:
main =
(putStr . unlines . take 8) $
format <$> onesPlusThree</
{{out}}
Line 498:
For large values of n, the unbounded-precision integer arithmetic of gojq will ensure accuracy.
<syntaxhighlight lang="jq">
# For gojq
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
Line 508:
(range(0;8) as $n
| ((("1"*$n) + "3") | tonumber) as $number
| ($n|lpad(3)) + ($number|lpad(10)) + ($number|power(2)|lpad(20)) )</
{{out}}
<pre>
Line 524:
Encoding "123456790" as "A", "987654320" as Z", and lastly "9876" as "N":
<
| ((("1"*$n) + "3") | tonumber) as $number
| ($n|lpad(4)) + " "
+ ($number|power(2)|tostring| gsub("123456790";"A") | gsub("987654320";"Z") | gsub("9876";"N") | lpad(40))
</syntaxhighlight>
{{out}}
<pre>
Line 540:
=={{header|Julia}}==
<
for n in 0:7
println(rpad(n, 14), rpad((big"10"^(n+1) - 1) ÷ 9 + 2, 19), ((big"10"^(n+1) - 1) ÷ 9 + 2)^2)
end
</
<pre>
n (10^(n+1) - 1) ÷ 9 + 2) squared
Line 557:
</pre>
=={{header|MAD}}==
<
VECTOR VALUES FMT = $I8,7H **2 = ,I15*$
THROUGH LOOP, FOR I=0, 1, I.G.7
Line 565:
N = N*10 + 3
LOOP PRINT FORMAT FMT,N,N*N
END OF PROGRAM</
{{out}}
<pre> 3**2 = 9
Line 577:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
Table[FromDigits[PadLeft[{3}, n, 1]], {n, 9}] // TableForm</
{{out}}<pre>
Line 593:
=={{header|Nim}}==
<
iterator genNumbers(maxOnes: Natural): int =
Line 603:
for i in genNumbers(7):
echo &"{i:8} {i*i:18}"</
{{out}}
Line 617:
=={{header|Plain English}}==
Only 5 entries are shown due to Plain English's 32-bit signed integers.
<
Start up.
Put 0 into a counter.
Line 633:
Repeat.
Wait for the escape key.
Shut down.</
{{out}}
<pre>
Line 646:
===One Liner===
The most Pythonic way.............
<syntaxhighlight lang="python">
[print("( " + "1"*i + "3 ) ^ 2 = " + str(int("1"*i + "3")**2)) for i in range(0,8)]
</syntaxhighlight>
{{out}}
<pre>
Line 662:
===Procedural===
{{trans|FreeBASIC}}
<
def make13(n):
Line 673:
for n in range(0,7):
m = make13(n)**2
print("{:d}\t\t{:d}".format(make13(n),m))</
===Functional===
Taking the first n terms from an infinite series:
<
from itertools import islice
Line 764:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre> 3^2 = 9
Line 776:
=={{header|Quackery}}==
<
char 3 join
$->n drop ] is 1's+3 ( n -> n )
Line 784:
dup echo
say " --> "
dup * echo cr ]</
{{out}}
Line 798:
=={{header|PARI/GP}}==
<
for(i=0,7,print(Make13(i)," ",Make13(i)^2))</
{{out}}
<pre>3 9
Line 813:
==={{header|Free Pascal}}===
like [[Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared#Phix|Phix]] using string
<
program OnesAppend3AndSquare;
const
Line 893:
writeln(s:2*MAX+2);
end;
end.</
{{out|@TIO.RUN}}
<pre>
Line 912:
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared
Line 922:
my $number = 1 x $_ . 3;
print "$number ", $number ** 2, "\n";
}</
{{out}}
<pre>
Line 937:
=={{header|Phix}}==
Perfect opportunity for a little string math, why not...
<!--<
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">37</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'3'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)&</span><span style="color: #008000;">'9'</span>
Line 951:
<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;">"%38s %75s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'1'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)&</span><span style="color: #008000;">'3'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 997:
In an attempt to stave of terminal ennui, Find the first 8 where a(n) is semiprime.
<syntaxhighlight lang="raku"
{{out}}
<pre>3, 9
Line 1,010:
=={{header|REXX}}==
A little extra code was added to pre-compute the biggest number to find the widths for output alignment.
<
numeric digits 1000 /*be able to handle huge numbers. */
parse arg n . /*obtain optional argument from the CL.*/
Line 1,023:
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</
{{out|output|text= when using the input of: <tt> 37 </tt>}}
Line 1,069:
=={{header|Ring}}==
<
load "stdlib.ring"
Line 1,094:
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 1,110:
=={{header|Seed7}}==
<
const proc: main is func
Line 1,121:
writeln(a <& " " <& a * a);
end for;
end func;</
{{out}}
<pre>
Line 1,135:
=={{header|Sidef}}==
<
var k = ((10**(n+1) - 1)/9 + 2)
say [k, k**2]
}</
{{out}}
<pre>
Line 1,153:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
var a = Fn.new { |n|
Line 1,161:
}
for (n in 0..7) a.call(n)</
{{out}}
Line 1,177:
=={{header|XPL0}}==
Only 32-bit integers are available, but the standard 64-bit floating point (real) provides 15 decimal digits.
<
real X;
[Format(16, 0);
Line 1,189:
CrLf(0);
];
]</
{{out}}
|