Smallest square that begins with n: Difference between revisions

(Add VTL-2)
Line 1,515:
48: 484
49: 49</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>max = 49;
maxlen = IntegerLength[max];
results = <||>;
Do[
sq = i^2;
id = IntegerDigits[sq];
starts = DeleteDuplicates[Take[id, UpTo[#]] & /@ Range[maxlen]];
starts //= Map[FromDigits];
starts //= Select[LessEqualThan[max]];
Do[
If[! KeyExistsQ[results, s],
results = AssociateTo[results, s -> i^2]
]
,
{s, starts}
]
If[Length[results] == max, Break[]]
,
{i, 1, \[Infinity]}
]
Column[results[#] & /@ Range[49]]</lang>
{{out}}
<pre>1
25
36
4
529
64
729
81
9
100
1156
121
1369
144
1521
16
1764
1849
196
2025
2116
225
2304
2401
25
2601
2704
289
2916
3025
3136
324
3364
3481
35344
36
3721
3844
3969
400
41209
4225
4356
441
45369
4624
4761
484
49</pre>
 
=={{header|Nim}}==
1,111

edits