Jump to content

Distinct power numbers: Difference between revisions

m (→‎{{header|Haskell}}: A variation on liftA2)
Line 407:
<pre>4 8 9 16 25 27 32 64 81 125 243 256 625 1024 3125</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
For relatively small integers, such as involved in the specified task, the built-in function `pow/2` does the job:
<lang jq>[range(2;6) as $a | range(2;6) as $b | pow($a; $b)] | unique</lang>
{{out}}
<pre>
[4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125]
</pre>
However, if using gojq, then for unbounded precision, a special-purpose "power" function is needed:<lang jq>def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
 
[range(2;6) as $a | range(2;6) as $b | $a|power($b)] | unique</lang>
{{out}}
As above.
=={{header|Julia}}==
<lang julia>println(sort(unique([a^b for a in 2:5, b in 2:5])))</lang>{{out}}
2,472

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.