Magic constant: Difference between revisions

Add Factor
m (typo)
(Add Factor)
Line 38:
 
 
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<lang factor>USING: formatting io kernel lists lists.lazy math math.functions
math.ranges prettyprint sequences tools.memory.private ;
 
: magic-constants ( -- list )
3 lfrom [ dup sq 1 + 2 / * ] lmap-lazy ;
 
: smallest ( m -- n )
[ magic-constants 3 lfrom lzip ] dip
'[ first _ 10^ > ] lfilter car second ;
 
"First 20 magic constants:" print
20 magic-constants ltake [ pprint bl ] leach nl
nl
"1000th magic constant:" print
999 magic-constants lnth commas print
nl
"Smallest order magic square with a constant greater than:" print
20 [1,b] [ dup smallest commas "10^%02d: %s\n" printf ] each
</lang>
{{out}}
<pre>
First 20 magic constants:
15 34 65 111 175 260 369 505 671 870 1105 1379 1695 2056 2465 2925 3439 4010 4641 5335
 
1000th magic constant:
503,006,505
 
Smallest order magic square with a constant greater than:
10^01: 3
10^02: 6
10^03: 13
10^04: 28
10^05: 59
10^06: 126
10^07: 272
10^08: 585
10^09: 1,260
10^10: 2,715
10^11: 5,849
10^12: 12,600
10^13: 27,145
10^14: 58,481
10^15: 125,993
10^16: 271,442
10^17: 584,804
10^18: 1,259,922
10^19: 2,714,418
10^20: 5,848,036
</pre>
 
=={{header|Raku}}==
1,827

edits