Show the (decimal) value of a number of 1s appended with a 3, then squared: Difference between revisions
Content added Content deleted
(Add Factor) |
m (→{{header|Factor}}: formatting) |
||
Line 6: | Line 6: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<big>{{math| |
<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}} |
{{works with|Factor|0.99 2021-02-05}} |
||
<lang factor>USING: io kernel math math.functions prettyprint ; |
<lang factor>USING: io kernel math math.functions prettyprint ; |
Revision as of 17:34, 5 April 2021
Show the (decimal) value of a number of 1s appended with a 3, then squared 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
a(n) = (n 1's followed by a 3)^2, where 0 <= n < 8
Factor
a(n) = ((10n+1 - 1) / 9 + 2)2
<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</lang>
- Output:
3 9 13 169 113 12769 1113 1238769 11113 123498769 111113 12346098769 1111113 1234572098769 11111113 123456832098769
Ring
<lang ring> load "stdlib.ring"
decimals(0)
see "working..." + nl
row = 0 limit = 8
str = "3" 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 </lang>
- Output:
working... {3,9} {13,169} {113,12769} {1113,1238769} {11113,123498769} {111113,12346098769} {1111113,1234572098769} {11111113,123456832098769} done...