Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
47
Task/Weird-numbers/Arturo/weird-numbers.arturo
Normal file
47
Task/Weird-numbers/Arturo/weird-numbers.arturo
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
semiperfect?: function [facts number].memoize [
|
||||
sumAll: sum facts
|
||||
|
||||
if sumAll = number -> return true
|
||||
if sumAll < number -> return false
|
||||
|
||||
current: first facts
|
||||
remaining: drop facts
|
||||
|
||||
if number < current -> return semiperfect? remaining number
|
||||
if number = current -> return true
|
||||
|
||||
if semiperfect? remaining number-current -> return true
|
||||
return semiperfect? remaining number
|
||||
]
|
||||
|
||||
findWeirdNumbers: function [limit][
|
||||
sieve: repeat false limit
|
||||
|
||||
loop 2..limit-1 'num [
|
||||
unless sieve\[num][
|
||||
divisors: (factors num) -- num
|
||||
sumDivisors: sum divisors
|
||||
|
||||
(sumDivisors =< num)? [
|
||||
sieve\[num]: true
|
||||
][
|
||||
if semiperfect? divisors num [
|
||||
j: num
|
||||
while [j < limit][
|
||||
sieve\[j]: true
|
||||
j: j + num
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
return drop.times:2 sieve
|
||||
]
|
||||
|
||||
print "The first 25 weird numbers:"
|
||||
|
||||
(findWeirdNumbers 17000) | map.with:'i 'x -> @[i+2,x]
|
||||
| select.first: 25 => [not? last &]
|
||||
| map => [first &]
|
||||
| print
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
!yamlscript/v0
|
||||
!YS-v0
|
||||
|
||||
defn main(max=16500):
|
||||
weird =: sieve(max)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue