Count in factors: Difference between revisions

(Added Fōrmulæ solution)
Line 2,270:
10 : 2 x 5
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
The following uses `factors/0`, a suitable implementation of which may be found at
[[Prime_decomposition#jq]].
 
gojq supports unlimited-precision integer arithmetic, but the C implementation of jq
currently uses IEEE 754 64-bit numbers, so using the latter, the following program will only be
reliable for integers up to and including 9,007,199,254,740,992 (2^53). However, "factors"
could be easily modified to work with a "BigInt" library for jq, such as [https://gist.github.com/pkoppstein/d06a123f30c033195841 BigInt.jq].
<lang jq># To take advantage of gojq's arbitrary-precision integer arithmetic:
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
 
# Input: a non-negative integer determining when to stop
def count_in_factors:
"1: 1",
(range(2;.) | "\(.): \([factors] | join("x"))");
 
def count_in_factors($m;$n):
if . == 1 then "1: 1" else empty end,
(range($m;$n) | "\(.): \([factors] | join("x"))");
</lang>
'''Examples'''
<lang jq>
10 | count_in_factors,
"",
count_in_factors(2144; 2145),
"",
(2|power(100) | count_in_factors(.; .+ 2))</lang>
{{out}}
The output shown here is based on a run of gojq.
<pre>
1: 1
2: 2
3: 3
4: 2x2
5: 5
6: 2x3
7: 7
8: 2x2x2
9: 3x3
 
2144: 2x2x2x2x2x67
 
1267650600228229401496703205376: 2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2x2
1267650600228229401496703205377: 17x401x61681x340801x2787601x3173389601
</pre>
 
 
=={{header|Julia}}==
2,460

edits