Jump to content

Digit fifth powers: Difference between revisions

(Add PILOT)
Line 636:
{{out}}
<pre>443839</pre>
 
=={{header|jq}}==
'''Adapted from [[#Julia|Julia]]
 
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
'''Preliminaries'''
<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);
 
def sum(s): reduce s as $x (0; .+$x);
 
# Output: a stream of integers
def digits: tostring | explode[] | [.] | implode | tonumber;</lang>
'''The Task'''
<lang jq># Output: an array of i^5 for i in 0 .. 9 inclusive
def dp5: [range(0;10) | power(5)];
 
def task:
dp5 as $dp5
| ($dp5[9] * 6) as $limit
| sum( range(2; $limit + 1)
| sum( digits | $dp5[.] ) as $s
| select(. == $s) ) ;
 
"The sum of all numbers that can be written as the sum of the 5th powers of their digits is:", task</lang>
{{out}}
<pre>
The sum of all numbers that can be written as the sum of the 5th powers of their digits is:
443839
</pre>
 
 
=={{header|Julia}}==
2,472

edits

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