Show the (decimal) value of a number of 1s appended with a 3, then squared: Difference between revisions

m
(Add COBOL)
m (→‎{{header|Wren}}: Minor tidy)
 
(21 intermediate revisions by 11 users not shown)
Line 2:
 
;Task:
Show here (on this page) the decimal numbers formed by:
:: <big><big>(</big></big>'''n''' &nbsp; '''1''''s &nbsp; appended by the digit &nbsp; '''3'''<big><big>)</big></big> &nbsp; and then square the result, &nbsp; &nbsp; where &nbsp; <big> '''0 &nbsp; <= &nbsp; n &nbsp; < &nbsp; 8''' </big>
 
<br><br>
;See also
;* [[oeis:A151997]]
 
 
=={{header|11l}}==
{{trans|Python}}
<syntaxhighlight lang="11l">L(i) 0..7 {print(‘( ’(‘1’ * i)‘3 ) ^ 2 = ’(Int64((‘1’ * i)‘3’) ^ 2))}</syntaxhighlight>
 
<lang 11l>L(i) 0..7 {print(‘( ’(‘1’ * i)‘3 ) ^ 2 = ’(Int64((‘1’ * i)‘3’) ^ 2))}</lang>
 
{{out}}
Line 24 ⟶ 26:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io;
with Ada.Numerics.Big_Numbers.Big_Integers;
 
Line 44 ⟶ 46:
Root := @ + 10**(N + 1);
end loop;
end Ones_Plus_Three;</langsyntaxhighlight>
{{out}}
<pre> 3 9
Line 58 ⟶ 60:
=={{header|ALGOL 68}}==
Assuming LONG INT is large enough (as in e.g. ALGOL 68G).
<langsyntaxhighlight lang="algol68">BEGIN
LONG INT n := 0;
FOR i TO 8 DO
Line 65 ⟶ 67:
n *:= 10 +:= 1
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 80 ⟶ 82:
Alternative version that shows the values for higher numbers of ones.
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
<langsyntaxhighlight lang="algol68">BEGIN
PR precision 250 PR
LONG LONG INT n := 0;
Line 89 ⟶ 91:
INT pos := 0;
STRING pattern := "123456790";
INT p len := ( UPB pattern - LWB pattern ) + 1;
WHILE string in string( pattern, pos, v ) DO
v := v[ 1 : pos - 1 ] + "A" + v[ pos + p len : ]
Line 101 ⟶ 103:
n *:= 10 +:= 1
OD
END</langsyntaxhighlight>
 
{{out}}
Line 135 ⟶ 137:
111 AAAAAAAAAAAA12387654320ZZZZZZZZZZZ98769
</pre>
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">loop 0..7 'x [
num: to :integer(repeat "1" x) ++ "3"
print [num num^2]
]</syntaxhighlight>
 
{{out}}
<pre>3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SHOW_THE_DECIMAL_VALUE_OF_A_NUMBER_OF_1S_APPENDED_WITH_A_3_THEN_SQUARED.AWK
# converted from FreeBASIC
BEGIN {
form (i=0; i<=7; i++) {2
for (n m= 0; n != make13(i8; ++n) {
printf("%1d %9s^2 %'20d\n",i,m, = m *m) 10 - 17
printf "%u %9u^2 %'20u\n", n, m, m * m
}
exit(0)
}
</syntaxhighlight>
function make13(n, t) {
while (n--) {
t = 10 * (t+1)
}
return(t+3)
}
</lang>
{{out}}
<pre>
Line 164 ⟶ 175:
7 11111113^2 123,456,832,098,769
</pre>
 
=={{header|bc}}==
<syntaxhighlight lang="bc">x = 2
for (n = 0; n != 8; ++n) {
x = x * 10 - 17
x
" -> "
x * x
}</syntaxhighlight>
{{out}}
<pre>
3
-> 9
13
-> 169
113
-> 12769
1113
-> 1238769
11113
-> 123498769
111113
-> 12346098769
1111113
-> 1234572098769
11111113
-> 123456832098769
</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">≍˘⟜(ט) 2(¯17+×)` 8⥊10</syntaxhighlight>
{{out}}
<pre>┌─
╵ 3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
┘</pre>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdint.h>
 
Line 182 ⟶ 235:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
 
<pre> 3^2 = 9
13^2 = 169
Line 198 ⟶ 249:
{{libheader|System.Numerics}}
For 0 <= n < 22
<langsyntaxhighlight lang="csharp">using System; using BI = System.Numerics.BigInteger;
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); } }</langsyntaxhighlight>
{{out}}
<pre> 9 3
Line 227 ⟶ 278:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">ones_plus_three = proc (n: int) returns (int)
r: int := 0
for i: int in int$from_to(1, n) do
Line 247 ⟶ 298:
stream$putl(po, "")
end
end start_up</langsyntaxhighlight>
{{out}}
<pre> 3^2 = 9
Line 259 ⟶ 310:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. ONES-THREE-SQUARED.
 
Line 290 ⟶ 341:
ADD-ONE.
MULTIPLY 10 BY ONES-3.
ADD 1 TO ONES-3.</langsyntaxhighlight>
{{out}}
<pre> 3^2 = 9
Line 300 ⟶ 351:
1111113^2 = 1234572098769
11111113^2 = 123456832098769</pre>
 
=={{header|dc}}==
<syntaxhighlight lang="dc">2[10*17-p[ -> ]Pdd*pZ15>l]dslx</syntaxhighlight>
{{out}}
<pre>
3
-> 9
13
-> 169
113
-> 12769
1113
-> 1238769
11113
-> 123498769
111113
-> 12346098769
1111113
-> 1234572098769
11111113
-> 123456832098769
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
procedure OnesPlusThree(Memo: TMemo);
{Create pattern: 3, 13, 113, 1113, and square}
var NS: string;
var I: integer;
var NV: int64;
begin
{Start with 3 in number string}
NS:='3';
for I:=1 to 7 do
begin
{Convert to a number}
NV:=StrToInt(NS);
Memo.Lines.Add(Format('%2D - %10d^2 =%18.0n',[I,NV,NV*NV+0.0]));
{Add a "1" to the number string}
NS:='1'+NS;
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
1 - 3^2 = 9
2 - 13^2 = 169
3 - 113^2 = 12,769
4 - 1113^2 = 1,238,769
5 - 11113^2 = 123,498,769
6 - 111113^2 = 12,346,098,769
7 - 1111113^2 = 1,234,572,098,769
Elapsed Time: 8.668 ms.
 
</pre>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
[3L;13L;113L;1113L;11113L;111113L;1111113L;11111113L;111111113L]|>List.iter(fun n->printfn "%10d->%d" n (n*n))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 321 ⟶ 430:
<big>{{math|a(<var>n</var>) &#61; ((10<sup><var>n</var>+1</sup> - 1) / 9 + 2)<sup>2</sup> }}</big>
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: io kernel math math.functions prettyprint ;
 
: a ( n -- e m ) 1 + 10^ 1 - 9 / 2 + dup sq ;
 
8 [ a swap pprint bl . ] each-integer</langsyntaxhighlight>
{{out}}
<pre>
Line 339 ⟶ 448:
 
=={{header|Fermat}}==
<langsyntaxhighlight lang="fermat">Func Make13(n) = m:=0; while n>0 do m:=10*(m+1);n:=n-1; od; m:=3+m; m.
for i=0 to 7 do !Make13(i);!' ';!Make13(i)^2;!!'' od</langsyntaxhighlight>
{{out}}
<pre>
Line 351 ⟶ 460:
1111113 1234572098769
11111113 123456832098769
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>function make13(n as uinteger) as uinteger
dim as uinteger t = 0
while n
t = 10*(t+1)
n-=1
wend
return t+3
end function
 
dim as ulongint m
 
for n as uinteger = 0 to 7
m = make13(n)^2
print make13(n), m
next n</lang>
{{out}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
</pre>
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: 1s+3
0 swap
begin dup while
Line 393 ⟶ 474:
: show dup . ." ^2 = " sqr . cr ;
 
: show-upto
0 swap
begin over over < while
Line 402 ⟶ 483:
 
8 show-upto
bye</langsyntaxhighlight>
 
{{out}}
 
<pre>3 ^2 = 9
13 ^2 = 169
Line 414 ⟶ 494:
1111113 ^2 = 1234572098769
11111113 ^2 = 123456832098769</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">function make13(n as uinteger) as uinteger
dim as uinteger t = 0
while n
t = 10*(t+1)
n-=1
wend
return t+3
end function
 
dim as ulongint m
 
for n as uinteger = 0 to 7
m = make13(n)^2
print make13(n), m
next n</syntaxhighlight>
{{out}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
</pre>
 
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 435 ⟶ 543:
a(n)
}
}</langsyntaxhighlight>
 
{{out}}
Line 450 ⟶ 558:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Text.Printf (printf)
 
onesPlusThree :: [Integer]
Line 463 ⟶ 571:
main =
(putStr . unlines . take 8) $
format <$> onesPlusThree</langsyntaxhighlight>
{{out}}
 
<pre> 3^2 = 9
13^2 = 169
Line 474 ⟶ 581:
1111113^2 = 1234572098769
11111113^2 = 123456832098769</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j"> (,. *:) (9 %~ 17 + 10x ^ >:) i. 8
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769</syntaxhighlight>
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">
'use strict'
let n = 0
for( let i = 1; i < 8; i ++ )
{
let n3 = ( n * 10 ) + 3
console.log( n3 + " " + ( n3 * n3 ) )
n *= 10
n += 1
}
</syntaxhighlight>
{{out}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
</pre>
 
=={{header|jq}}==
Line 480 ⟶ 621:
 
For large values of n, the unbounded-precision integer arithmetic of gojq will ensure accuracy.
<syntaxhighlight lang="jq">
<lang jq>
# For gojq
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
Line 490 ⟶ 631:
(range(0;8) as $n
| ((("1"*$n) + "3") | tonumber) as $number
| ($n|lpad(3)) + ($number|lpad(10)) + ($number|power(2)|lpad(20)) )</langsyntaxhighlight>
{{out}}
<pre>
Line 505 ⟶ 646:
'''For 100 <= n <= 105'''
 
Encoding "123456790" as "A", "987654320" as Z", and lastly "9876" as "N":
<langsyntaxhighlight lang="jq">range(100; 106) 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>
</lang>
{{out}}
<pre>
Line 522 ⟶ 663:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">println("n (10^(n+1) - 1) ÷ 9 + 2) squared")
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
</langsyntaxhighlight>{{out}}
<pre>
n (10^(n+1) - 1) ÷ 9 + 2) squared
Line 538 ⟶ 679:
7 11111113 123456832098769
</pre>
 
=={{header|K}}==
<syntaxhighlight lang="k">{x,'x*x}2(-17+*)\8#10</syntaxhighlight>
{{out}}
<pre>(3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769)</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">
do
local n = 0
for i = 1,8 do
local n3 = ( n * 10 ) + 3
io.write( n3, " ", n3 * n3, "\n" )
n = ( n * 10 ) + 1
end
end</syntaxhighlight>
{{out}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
</pre>
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
VECTOR VALUES FMT = $I8,7H **2 = ,I15*$
THROUGH LOOP, FOR I=0, 1, I.G.7
Line 547 ⟶ 723:
N = N*10 + 3
LOOP PRINT FORMAT FMT,N,N*N
END OF PROGRAM</langsyntaxhighlight>
{{out}}
<pre> 3**2 = 9
Line 558 ⟶ 734:
11111113**2 = 123456832098769</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">{#, #^2} & /@
Table[FromDigits[PadLeft[{3}, n, 1]], {n, 9}] // TableForm</langsyntaxhighlight>
 
{{out}}<pre>
Line 575 ⟶ 751:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strformat
 
iterator genNumbers(maxOnes: Natural): int =
Line 585 ⟶ 761:
 
for i in genNumbers(7):
echo &"{i:8} {i*i:18}"</langsyntaxhighlight>
 
{{out}}
Line 596 ⟶ 772:
1111113 1234572098769
11111113 123456832098769</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let make13 n =
truncate (10. ** float n) / 9 * 10 + 3
 
let () =
for n = 0 to 7 do
let x = make13 n in Printf.printf "%9u%16u\n" x (x * x)
done</syntaxhighlight>
{{out}}
<pre> 3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769</pre>
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="parigp">Make13(n)=m=0;while(n>0,m=10*(m+1);n=n-1);m=3+m;return(m)
for(i=0,7,print(Make13(i)," ",Make13(i)^2))</syntaxhighlight>
{{out}}
<pre>3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
</pre>
 
=={{header|Pascal}}==
==={{header|Free Pascal}}===
like [[Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared#Phix|Phix]] using byte, and convert than to ASCII.
Because the values are calculated one by one, one can use addition to get rid of calculating squares, by using binomial formula.
The best is shown in [[Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared#ALGOL_68|Algol_68]] that it ends in a cyclic pattern of lenght 9.
<syntaxhighlight lang="pascal">{
10^pot+k -> prepend a 1 1113-> 11113
(10^pot+k)^2 = 10^(2*pot)+ 2*10^pot*k + k^2
(10^pot+k)^2 = 10^pot*(10^pot+2*k) + k^2
s_lastsqr = k*k
s_DeltaSqr = (10^pot+2*k) => 1222....2226
shift s_DeltaSqr by pot digits in SumMyDeltaSqr => 10^pot*(10^pot+2*k)
}
program OnesAppend3AndSquare;
const
MAX = 3700;
type
tmyNumb = array of byte;
var
res :AnsiString;
 
procedure OutMyNumb(const n: tmyNUmb;l,w: integer);
var
i,ofs : integer;
begin
l += 1;
if w < l then
w := l+1;
setlength(res,w);
fillchar(res[1],w,' ');
ofs := w-l;
For i := 1 to l do
res[i+ofs] := chr(n[l-i]+48);
write(res);
end;
 
procedure Out_k_sqr(const k,sqr_k: tmyNUmb;pot:integer);
var
dgtcnt : integer;
Begin
write(pot:4);
dgtcnt := 22;
if pot > 10 then
dgtcnt := 78;
OutMyNumb(k,pot,dgtcnt-4);
if pot > 10 then
writeln;
OutMyNumb(sqr_k,2*pot,dgtcnt);
writeln;
end;
procedure SumMyDeltaSqr(var res:tmyNUmb;const s:tmyNumb;pot: integer);
//res = s_lastsqr
//s = s_DeltaSqr
//shift s by l => (10^pot) * s_DeltaSqr = 10^pot*(10^pot+2*k)
var
i,sum,carry : integer;
begin
carry := 0;
For i := 0 to pot+1 do
begin
sum := res[i+pot]+s[i]+carry;
carry := ord(sum>9);
sum -= (-carry) AND 10;
res[i+pot] := sum;
end;
end;
 
var
s,s_DeltaSqr,s_lastsqr : tmyNumb;
pot: integer;
Begin
setlength(s,MAX);
setlength(s_DeltaSqr,Max+1);
setlength(s_lastsqr,2*Max+1);
pot := 0;
s[pot] := 3;
s_lastsqr[pot] := 9;
repeat
SumMyDeltaSqr(s_lastsqr,s_DeltaSqr,pot);
if pot < 10 then
Out_k_sqr(s,s_lastsqr,pot);
if pot = 37 then
Out_k_sqr(s,s_lastsqr,pot);
 
if pot > 0 then
s_DeltaSqr[pot]:= 2 // =>2*s[i] 2222...26
else
s_DeltaSqr[0] := 6;// =>2*s[0] 6
inc(pot);
s_DeltaSqr[pot]:= 1; //1...6
s[pot] := 1;
until pot = MAX;
Writeln('Finished til ',MAX);
end.
</syntaxhighlight>
{{out|@TIO.RUN}}
<pre>
0 3 9
1 13 169
2 113 12769
3 1113 1238769
4 11113 123498769
5 111113 12346098769
6 1111113 1234572098769
7 11111113 123456832098769
8 111111113 12345679432098769
9 1111111113 1234567905432098769
37 11111111111111111111111111111111111113
123456790123456790123456790123456790165432098765432098765432098765432098769
Finished til 3700
Real time: 0.106 s CPU share: 99.03 %
@home real 0m0.016s
</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared
use warnings;
#use bignum; # uncomment for larger than 9 or 32-bit perls
 
for ( 0 .. 7 )
{
my $number = 1 x $_ . 3;
print "$number ", $number ** 2, "\n";
}</syntaxhighlight>
{{out}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
</pre>
 
=={{header|Phix}}==
Perfect opportunity for a little string math, why not...
<!--<syntaxhighlight lang="phix">(phixonline)-->
<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>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"0"</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">res</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">digit</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">i</span> <span style="color: #008080;">to</span> <span style="color: #000000;">1</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">digit</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]-</span><span style="color: #008000;">'0'</span>
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)+</span><span style="color: #008000;">'0'</span>
<span style="color: #000000;">digit</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">/</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</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;">"%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>
<!--</syntaxhighlight>-->
{{out}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
111111113 12345679432098769
1111111113 1234567905432098769
11111111113 123456790165432098769
111111111113 12345679012765432098769
1111111111113 1234567901238765432098769
11111111111113 123456790123498765432098769
111111111111113 12345679012346098765432098769
1111111111111113 1234567901234572098765432098769
11111111111111113 123456790123456832098765432098769
111111111111111113 12345679012345679432098765432098769
1111111111111111113 1234567901234567905432098765432098769
11111111111111111113 123456790123456790165432098765432098769
111111111111111111113 12345679012345679012765432098765432098769
1111111111111111111113 1234567901234567901238765432098765432098769
11111111111111111111113 123456790123456790123498765432098765432098769
111111111111111111111113 12345679012345679012346098765432098765432098769
1111111111111111111111113 1234567901234567901234572098765432098765432098769
11111111111111111111111113 123456790123456790123456832098765432098765432098769
111111111111111111111111113 12345679012345679012345679432098765432098765432098769
1111111111111111111111111113 1234567901234567901234567905432098765432098765432098769
11111111111111111111111111113 123456790123456790123456790165432098765432098765432098769
111111111111111111111111111113 12345679012345679012345679012765432098765432098765432098769
1111111111111111111111111111113 1234567901234567901234567901238765432098765432098765432098769
11111111111111111111111111111113 123456790123456790123456790123498765432098765432098765432098769
111111111111111111111111111111113 12345679012345679012345679012346098765432098765432098765432098769
1111111111111111111111111111111113 1234567901234567901234567901234572098765432098765432098765432098769
11111111111111111111111111111111113 123456790123456790123456790123456832098765432098765432098765432098769
111111111111111111111111111111111113 12345679012345679012345679012345679432098765432098765432098765432098769
1111111111111111111111111111111111113 1234567901234567901234567901234567905432098765432098765432098765432098769
11111111111111111111111111111111111113 123456790123456790123456790123456790165432098765432098765432098765432098769
</pre>
 
=={{header|Plain English}}==
Only 5 entries are shown due to Plain English's 32-bit signed integers.
<langsyntaxhighlight lang="plain english">To run:
Start up.
Put 0 into a counter.
Line 615 ⟶ 1,020:
Repeat.
Wait for the escape key.
Shut down.</langsyntaxhighlight>
{{out}}
<pre>
Line 627 ⟶ 1,032:
=={{header|Python}}==
===One Liner===
The most Pythonic way.............
<syntaxhighlight lang="python">
<lang Python>
[print("( " + "1"*i + "3 ) ^ 2 = " + str(int("1"*i + "3")**2)) for i in range(0,8)]
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 642 ⟶ 1,047:
( 11111113 ) ^ 2 = 123456832098769
</pre>
 
===Procedural===
<syntaxhighlight lang="python">#!/usr/bin/python
{{trans|FreeBASIC}}
<lang python>#!/usr/bin/python
 
def make13(n):
return 10 ** (n + 1) // 9 + 2
t = 0
while n:
t = 10*(t+1)
n -= 1
return t+3
 
for n in rangemap(0make13,7 range(8)):
print('%9d%16d' % (n, n * n))</syntaxhighlight>
m = make13(n)**2
print("{:d}\t\t{:d}".format(make13(n),m))</lang>
 
===Functional===
 
Taking the first n terms from an infinite series:
<langsyntaxhighlight lang="python">'''Sequence of 1s appended with a 3, then squared'''
 
from itertools import islice
Line 746 ⟶ 1,145:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre> 3^2 = 9
Line 757 ⟶ 1,156:
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery"> [ char 1 swap of
 
<lang Quackery> [ char 1 swap of3 join
char 3 join
$->n drop ] is 1's+3 ( n -> n )
 
8 times
[ i^ 1's+3
dup echo
say " --> "
dup * echo cr ]</langsyntaxhighlight>
 
{{out}}
 
<pre>3 --> 9
13 --> 169
Line 778 ⟶ 1,175:
1111113 --> 1234572098769
11111113 --> 123456832098769</pre>
 
=={{header|PARI/GP}}==
<lang parigp>Make13(n)=m=0;while(n>0,m=10*(m+1);n=n-1);m=3+m;return(m)
for(i=0,7,print(Make13(i)," ",Make13(i)^2))</lang>
{{out}}
<pre>3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
</pre>
=={{header|Pascal}}==
==={{header|Free Pascal}}===
like [[Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared#Phix|Phix]] using string
<lang pascal>
program OnesAppend3AndSquare;
const
MAX = 10;//37
 
procedure AddNumStrings(var s:Ansistring;const n:Ansistring;Offset:integer);
var
l,sum,carry : integer;
begin
l := length(n);
carry := 0;
repeat
sum := Ord(s[l+Offset])+Ord(n[l])-2*Ord('0')+carry;
If sum >= 10 then
begin
dec(sum,10);
carry := 1;
end
else
carry := 0;
s[l+Offset]:= chr(sum+Ord('0'));
dec(l)
until l <= 0;
//correct carry, never used for '3' but > '3' only once
while (Offset>0) AND(carry = 1) do
begin
sum := Ord(s[Offset])-Ord('0')+carry;
If sum >= 10 then
begin
dec(sum,10);
carry := 1;
end
else
carry := 0;
s[Offset]:= chr(sum+Ord('0'));
dec(Offset)
end;
end;
 
procedure OnesAppend3AndSquare(CntOfOnes:integer;var s:AnsiString);
var
fac : Ansistring;
i,l : integer;
begin
l := CntOfOnes+1;
setlength(fac,l);
FillChar(fac[1],l-1,'1');
fac[l]:= '3';
write(fac:MAX+1);
repeat
i := Ord(fac[l])-Ord('0');
if i > 0 then
repeat
AddNumStrings(s,fac,l);
dec(i)
until i<=0;
dec(l);
until l <=0;
end;
 
var
s : AnsiString;
i,j,l : integer;
Begin
For i := 0 to MAX do
begin
l := i+1;
inc(l,l);
setlength(s,l);
Fillchar(s[1],l,'0');
OnesAppend3AndSquare(i,s);
//remove leading '0'
j := 1;
while (j < l) AND (s[j] = '0') do
begin
s[j]:= ' ';
inc(j);
end;
writeln(s:2*MAX+2);
end;
end.</lang>
{{out|@TIO.RUN}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
111111113 12345679432098769
1111111113 1234567905432098769
11111111113 123456790165432098769
..37 '1'
11111111111111111111111111111111111113 123456790123456790123456790123456790165432098765432098765432098765432098769
</pre>
 
=={{header|Perl}}==
<lang perl>#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Show_the_(decimal)_value_of_a_number_of_1s_appended_with_a_3,_then_squared
use warnings;
#use bignum; # uncomment for larger than 9 or 32-bit perls
 
for ( 0 .. 7 )
{
my $number = 1 x $_ . 3;
print "$number ", $number ** 2, "\n";
}</lang>
{{out}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
</pre>
 
=={{header|Phix}}==
Perfect opportunity for a little string math, why not...
<!--<lang Phix>(phixonline)-->
<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>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"0"</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">res</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">digit</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">i</span> <span style="color: #008080;">to</span> <span style="color: #000000;">1</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">digit</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]-</span><span style="color: #008000;">'0'</span>
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)+</span><span style="color: #008000;">'0'</span>
<span style="color: #000000;">digit</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digit</span><span style="color: #0000FF;">/</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</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;">"%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>
<!--</lang>-->
{{out}}
<pre>
3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
111111113 12345679432098769
1111111113 1234567905432098769
11111111113 123456790165432098769
111111111113 12345679012765432098769
1111111111113 1234567901238765432098769
11111111111113 123456790123498765432098769
111111111111113 12345679012346098765432098769
1111111111111113 1234567901234572098765432098769
11111111111111113 123456790123456832098765432098769
111111111111111113 12345679012345679432098765432098769
1111111111111111113 1234567901234567905432098765432098769
11111111111111111113 123456790123456790165432098765432098769
111111111111111111113 12345679012345679012765432098765432098769
1111111111111111111113 1234567901234567901238765432098765432098769
11111111111111111111113 123456790123456790123498765432098765432098769
111111111111111111111113 12345679012345679012346098765432098765432098769
1111111111111111111111113 1234567901234567901234572098765432098765432098769
11111111111111111111111113 123456790123456790123456832098765432098765432098769
111111111111111111111111113 12345679012345679012345679432098765432098765432098769
1111111111111111111111111113 1234567901234567901234567905432098765432098765432098769
11111111111111111111111111113 123456790123456790123456790165432098765432098765432098769
111111111111111111111111111113 12345679012345679012345679012765432098765432098765432098769
1111111111111111111111111111113 1234567901234567901234567901238765432098765432098765432098769
11111111111111111111111111111113 123456790123456790123456790123498765432098765432098765432098769
111111111111111111111111111111113 12345679012345679012345679012346098765432098765432098765432098769
1111111111111111111111111111111113 1234567901234567901234567901234572098765432098765432098765432098769
11111111111111111111111111111111113 123456790123456790123456790123456832098765432098765432098765432098769
111111111111111111111111111111111113 12345679012345679012345679012345679432098765432098765432098765432098769
1111111111111111111111111111111111113 1234567901234567901234567901234567905432098765432098765432098765432098769
11111111111111111111111111111111111113 123456790123456790123456790123456790165432098765432098765432098765432098769
</pre>
 
=={{header|Raku}}==
In an attempt to stave of terminal ennui, Find the first 8 where a(n) is semiprime.
<syntaxhighlight lang="raku" line>say "$_, {.²}" for (^∞).map({ ( 1 x $_ ~ 3)} ).grep({ .is-prime })[^8]</syntaxhighlight>
 
<lang perl6>say "$_, {.²}" for (^∞).map({ ( 1 x $_ ~ 3)} ).grep({ .is-prime })[^8]</lang>
{{out}}
<pre>3, 9
Line 992 ⟶ 1,191:
=={{header|REXX}}==
A little extra code was added to pre-compute the biggest number to find the widths for output alignment.
<langsyntaxhighlight lang="rexx">/*REXX program appends a "3" to a number of "1"s, and then squares that number. */
numeric digits 1000 /*be able to handle huge numbers. */
parse arg n . /*obtain optional argument from the CL.*/
Line 1,005 ⟶ 1,204:
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 ?</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 37 </tt>}}
 
Line 1,051 ⟶ 1,250:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 1,064 ⟶ 1,263:
for n = 1 to limit
if n = 1
strn = number(str)
res = pow(strn,2)
see "{" + strn + "," + res + "}" + nl
else
str = "1" + strn
strn = number(str)
res = pow(strn,2)
see "{" + strn + "," + res + "}" + nl
ok
next
 
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,089 ⟶ 1,288:
{11111113,123456832098769}
done...
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
≪ { }
0 7 '''FOR''' n
10 n ^ 1 - 9 / 10 * 3 + SQ +
'''NEXT'''
≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: { 9 169 12769 1238769 123498769 12346098769 1234572098769 123456832098769 }
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">m = 8
(0..m).each do |n|
ones3 = "1"*n +"3"
puts ones3.ljust(m+2) + ( ones3.to_i**2).to_s
end</syntaxhighlight>
{{out}}
<pre>3 9
13 169
113 12769
1113 1238769
11113 123498769
111113 12346098769
1111113 1234572098769
11111113 123456832098769
111111113 12345679432098769
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">
fn main() {
let mut big_squares : Vec<u64> = Vec::new( ) ;
let mut numberstrings : Vec<String> = Vec::new( ) ;
for n in 0..8 {
let mut numberstring : String = String::new( ) ;
for i in 0..=n {
if i != 0 {
numberstring.push( '1' ) ;
}
}
numberstring.push('3') ;
let number : u64 = numberstring.parse::<u64>().unwrap( ) ;
numberstrings.push( numberstring ) ;
big_squares.push( number.pow( 2 )) ;
}
for i in 0..numberstrings.len( ) {
print!("{} ^ 2 =" , numberstrings[ i ] ) ;
let width = 30 - (7 + i ) ;
println!("{:>width$}" , big_squares[ i ] ) ;
}
}</syntaxhighlight>
{{out}}
<pre>
3 ^ 2 = 9
13 ^ 2 = 169
113 ^ 2 = 12769
1113 ^ 2 = 1238769
11113 ^ 2 = 123498769
111113 ^ 2 = 12346098769
1111113 ^ 2 = 1234572098769
11111113 ^ 2 = 123456832098769
</pre>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 1,103 ⟶ 1,367:
writeln(a <& " " <& a * a);
end for;
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,117 ⟶ 1,381:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">0..^8 -> each {|n|
var k = ((10**(n+1) - 1)/9 + 2)
say [k, k**2]
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,135 ⟶ 1,399:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
 
var a = Fn.new { |n|
Line 1,143 ⟶ 1,407:
}
 
for (n in 0..7) a.call(n)</langsyntaxhighlight>
 
{{out}}
Line 1,159 ⟶ 1,423:
=={{header|XPL0}}==
Only 32-bit integers are available, but the standard 64-bit floating point (real) provides 15 decimal digits.
<langsyntaxhighlight XPL0lang="xpl0">int N, M;
real X;
[Format(16, 0);
Line 1,171 ⟶ 1,435:
CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
9,479

edits