Digit fifth powers: Difference between revisions

Content added Content deleted
(Add PILOT)
Line 636: Line 636:
{{out}}
{{out}}
<pre>443839</pre>
<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}}==
=={{header|Julia}}==