| Bytes | Lang | Time | Link |
|---|---|---|---|
| 065 | TIBASIC TI84 Plus CE Python | 250912T135615Z | madeforl |
| 592 | jBasher2 | 250909T154911Z | madeforl |
| 080 | APLNARS | 250905T160745Z | Rosario |
| 081 | YASEPL | 250904T163917Z | madeforl |
| 085 | Nibbles | 230226T130028Z | Adam |
| 022 | Pyt | 230225T172600Z | Kip the |
| 005 | Vyxal 2.6.1 | 211123T002659Z | lyxal |
| 094 | Python 3 | 211204T213823Z | empii |
| 111 | Scala | 211126T203102Z | user |
| 151 | Zephyr | 211125T195435Z | DLosc |
| 040 | Wolfram Language Mathematica | 211123T093511Z | ovs |
| 011 | Stax | 211125T010117Z | recursiv |
| 009 | Husk | 211124T231036Z | Dominic |
| 248 | Core Maude | 211124T220621Z | Chris Bo |
| 009 | Jelly | 211123T185842Z | lynn |
| 056 | Ruby | 211123T081206Z | AZTECCO |
| 063 | JavaScript V8 | 211123T015501Z | Arnauld |
| 079 | Python 3 | 211123T085942Z | Jitse |
| 052 | R | 211123T070657Z | pajonk |
| 013 | MathGolf | 211123T080027Z | Kevin Cr |
| 046 | Raku | 211123T075327Z | Sean |
| 065 | Factor + lists.lazy math.primes.factors math.unicode | 211123T022400Z | chunes |
| 042 | Pari/GP | 211123T012524Z | alephalp |
| 009 | Jelly | 211123T012430Z | hyperneu |
| 037 | Charcoal | 211123T003717Z | Neil |
TI-BASIC (TI-84 Plus CE Python), 74 67 65 bytes
While 1
Ans+1
If not(fPart(round(AnsΣ(int(Ans/K)-int((Ans-1)/K),K,1,1+Ans)/Σ(Knot(fPart(Ans/K)),K,1,1+Ans),9
Disp Ans
End
make sure Ans is set to 0 before running.
jBasher2, 592 bytes
create n with type number
while 1 == 1
add n by 1
set that to n
create k with type number
set 1 to k
create f with type number
create o with type number
while k <= n
create g with type number
subtract n by 1
divide that by k
parse that as int
set that to g
divide n by k
parse that as int
subtract that by g
add f by that
set that to f
divide n by k
modulo that by 1
if that == 0
add k by o
set that to o
endif
add 1 by k
set that to k
endwhile
divide 1 by 10
add o by that
parse that as int
set that to o
divide f by o
multiply that by n
modulo that by 1
if that == 0
output n
endif
endwhile
awesome translation of my YASEPL answer
APL(NARS), 80 chars
r←F w;x;m;k
r←⍬⋄x←0x
→0×⍳0≥w
x+←1⋄→3×⍳∼1=÷1∨(≢m)÷+/÷m←k/⍨0=x∣⍨k←⍳x
r,←x⋄w-←1⋄→2
// +/ 12 9 8 38 13=80
F 1-indexed, and it is slow it seems has at last O(n^5) if goes well. F use rationals.
÷1∨k finds the denominator of k rational.
Test:
F 5
1 6 28 140 270
F 10
1 6 28 140 270 496 672 1638 2970 6200
F 1
1
YASEPL, 81 bytes
=n!+=k$=f=o`1=g$n-/k(=l$n/k(-g!f+l=u$n/k%1+[2!o+k`2!k+}4,n!o+.9(!f/o*n%1+[3>n`3?3
this prints them infinitely
explanation
=n main increment
(after this is where the loop starts)
!+ add 1 to n
=k$ K variable for summation
=f F is total amount of divisors of N
=o O is sum of divisors of N
`1 start sum
( calculating number of divisors )
=g$n-/k(=l$n/k(-g l = floor(n/k) - floor(n-1/k)
!f+l add to sum
( calculating sum of divisors )
=u$n/k%1+[2 if (n/k) = 0...
!o+k add K to O
`2 end if
!k+ increment K
}4,n if K <= N, go back to `1
!o+.9( ceil O
!f/o*n%1+[3 if (f/o)*n = 0...
>n print n
`3 endif
?3 go back to the third char of the program (where !+ is)
this assumes that \$ n \$ is a harmonic divisor number if the following is true:
$$ 0=(\frac{\sum_{k=1}^{n}(\left\lfloor\frac{n}{k}\right\rfloor-\left\lfloor\frac{n-1}{k} \right\rfloor)}{\left\lceil\sum_{i=1}^{n}(0^{\frac{n}{i}\mod1}i)\right\rceil}\times n)\mod1 $$ I'm not the best with writing math equations so take it with a grain of salt.
this thing gets really slow.
Pyt, 22 bytes
1`ĐðĐĐΠ⇹/Ʃ⇹Π|?ŕĐƥ:ŕ;⁺ł
Prints Ore numbers forever.
1 Push 1
` ł Do... while top of stack is truthy
Đ Đuplicate
ð Get list of ðivisors
ĐĐ Đuplicate twice
Π Get product
⇹ Swap top two elements on stack
/ Divide
Ʃ Ʃum
⇹ Swap top two elements
Π|? Does the sum divide the product cleanly?
ŕĐƥ If so, ŕemove the boolean, Đuplicate, and ƥrint
:ŕ Otherwise, ŕemove the boolean
;⁺ Either way, increment
Vyxal 2.6.1, 5 bytes
≬KṁḊȯ
This doesn't work in 2.4 because 2.6 uses sympy rationals to store non-integers. Essentially a port of hyper's hypothetical Jelly answer.
Explained
≬KṁḊȯ
≬ # The next three elements as a function, taking single argument n:
K # divisors of n
ṁ # the average of that
Ḋ # does that divide n?
ȯ # First input numbers that satisfy the above function.
Python 3, 94 bytes
v=0
while 1:p=q=1;v+=1;-~len([(p:=p*d+q,q:=q*d)for d in range(2,v+1)if v%d<1])*q%p or print(v)
Outputs indefinitely. This is otherwise like (my edit to) @Jitse's answer, but computes the sum of the reciprocals p/q exactly as a pair of (big)ints (p,q).
Scala, 111 bytes
Stream.iterate(1:BigInt)(_+1)filter{n=>val d=n to(1,-1)filter(n%_<1)
val p=d.product
p*d.size%d.map(p./).sum<1}
Returns an infinite Stream.
Scala, 92 bytes
Stream from 1 filter{n=>val d=1 to n filter(n%_<1)
val p=d.product
p*d.size%(0/:d)(_+p/_)<1}
This one uses normal Ints, evading some of the boilerplate above, but it only generates the first three elements correctly due to integer overflows.
Zephyr, 151 bytes
set n to 1
while 1=1
set s to 0
set c to 0
for d from 1to n
if(n mod d)=0
set s to(/d)+s
inc c
end if
next
if((c/s)mod 1)=0
print n
end if
inc n
repeat
Try it online! Uses the output-infinitely strategy; you'll need to kill the program before 60 seconds in order to see any output.
Ungolfed
# Start from 1
set num to 1
# Loop forever
while true
# Calculate the sum of the reciprocals of the divisors
# and also the total number of divisors
set reciprocalSum to 0
set divisorCount to 0
for divisor from 1 to num
if (num mod divisor) = 0
set reciprocalSum to reciprocalSum + (/ divisor)
inc divisorCount
end if
next
# Print the number if the divisor count divided by the
# divisor-reciprocal sum is an integer
if ((divisorCount / reciprocalSum) mod 1) = 0
print num
end if
# Go to the next number
inc num
repeat
Wolfram Language (Mathematica), 42 40 bytes
-2 bytes thanks to att!
Do[Mean@Divisors@n∣n&&Print@n,{n,∞}]
Husk, 9 bytes
fo§¦ṁ\LḊN
Try it online! (header outputs the first few elements to avoid timing-out)
N # from the infinite list of integers
fo # output those for which
ṁ\ # the sum of the reciprocals of their divisors
§¦ # exactly divides
LḊ # the length (number) of their divisors
Core Maude, 248 bytes
mod H is pr LIST{Rat}. ops o h : Rat ~> Rat . var A B C D : Rat . eq o(A)= o(2
A). eq o(s A 0)= A . eq o(A s B)= o(s A(B + ceiling(frac(h(A A 0 0))))). eq h(A
s B C D)= h(A B(0 ^(A rem s B)/ s B + C)(0 ^(A rem s B)+ D)). eq h(A 0 C D)=
D / C . endm
The result is obtained by reducing the o function with the zero-indexed input \$n\$.
Example Session
Maude> red o(0) . --- 1
result NzNat: 1
Maude> red o(1) . --- 6
result NzNat: 6
Maude> red o(2) . --- 28
result NzNat: 28
Maude> red o(3) . --- 140
result NzNat: 140
Maude> red o(4) . --- 270
result NzNat: 270
Maude> red o(5) . --- 496
result NzNat: 496
Maude> red o(6) . --- 672
result NzNat: 672
Maude> red o(7) . --- 1638
result NzNat: 1638
Maude> red o(8) . --- 2970
result NzNat: 2970
Maude> red o(9) . --- 6200
result NzNat: 6200
Maude> red o(10) . --- 8128
result NzNat: 8128
Maude> red o(11) . --- 8190
result NzNat: 8190
Ungolfed
mod H is
pr LIST{Rat} .
ops o h : Rat ~> Rat .
var A B C D : Rat .
eq o(A) = o(2 A) .
eq o(s A 0) = A .
eq o(A s B) = o(s A (B + ceiling(frac(h(A A 0 0))))) .
eq h(A s B C D) = h(A B (0 ^ (A rem s B) / s B + C) (0 ^ (A rem s B) + D)) .
eq h(A 0 C D) = D / C .
endm
Maude has built-in support for rational arithmetic, so we just compute the harmonic mean of the divisors with h. Then, ceiling(frac(h(...))) will be 0 if h(...) is a natural number or 1 otherwise. Also, note that in Maude 0 ^ 0 == 1 and 0 ^ X = 0 for X =/= 1.
Jelly, 9 bytes
1Æd×ọÆsƲ#
More boring than the other answer:
Implicit input: an integer z.
1 Ʋ# Count up from 1, finding z numbers for which...
Æd× divisor_count(n) × n
ọ is divisible by
Æs divisor_sum(n).
Ruby, 71 56 bytes
1.step{|n|k=0;(1..n).count{|x|n%x<1&&k+=1r/x}%k>0||p(n)}
- Saved 15 thanks to @G B lots of golfs
Outputs the sequence indefinitely.
JavaScript (V8), 63 bytes
Prints the sequence forever.
{for(n=0;;s%t||print(n))for(k=++n,t=s=0;k;)n%k--||(s+=n,t-=~k)}
Python 3, 79 bytes
n=0
while 1:n+=1;a=[i for i in range(1,n+1)if n%i<1];n*len(a)%sum(a)or print(n)
Outputs indefinitely.
R, 55 52 bytes
-3 bytes thanks to @Dominic van Essen.
while(F<-F+1)(1/mean(1/(y=1:F)[!F%%y]))%%1||print(F)
Prints Ore numbers infinitely.
MathGolf, 13 bytes
î∙─‼Σ£î*\÷╛p∟
Outputs indefinitely.
Try it online. (You do have to manually cancel it during runtime to see output apparently, before it times out after 60 seconds..)
Explanation:
∟ # Do-while true without popping:
î # Push the 1-based loop-index
∙ # Triplicate it
─ # Pop the top, and get a list of its divisors
‼ # Apply the following two commands separately:
Σ # Sum the divisors-list
£ # Get the length of the divisors-list
î* # Multiply the length by the 1-based loop-index
\ # Swap the top two values on the stack
÷ # Check that the length*î is divisible by the sum
╛ # If this is truthy:
p # Pop the remaining copy of the index, and print it
Raku, 46 bytes
grep {{@_%%sum 1 X/@_}(grep $_%%*,1..$_)},^∞
This is a lazy infinite sequence of the harmonic divisor numbers.
Factor + lists.lazy math.primes.factors math.unicode, 69 65 bytes
[ 1 lfrom [ divisors [ length 1 ] keep n/v Σ mod 0 = ] lfilter ]
It's a quotation that returns an infinite lazy list of the harmonic divisor numbers.
Explanation
1 lfroman infinite lazy list of natural numbers[ ... ] lfilterselect numbers for which the quotation returnstruedivisorsget the divisors of a number (e.g.6 divisors->{ 1 2 3 6 })[ length 1 ] keep(e.g.{ 1 2 3 6 } [ length 1 ] keep->4 1 { 1 2 3 6 })n/vdivide number by vector (e.g.1 { 1 2 3 6 } n/v->{ 1 1/2 1/3 1/6 })Σtake the summod 0 =is it a divisor?
Jelly, 9 bytes
ÆDpWSḍ/µ#
This is horribly scuffed because I couldn't figure out how to get it working with precision. I had the same idea as ovs it turns out, but ÆDÆmḍµ# fails due to precision issues.
I honestly hate how this is written.
ÆDpWSḍ/µ# Main Link
µ# nfind; return first n values satisfying:
ÆD divisors of n
p cartesian product with
W [n] (returns [[a, n], [b, n], ...])
S sum (returns [divisor sum, divisor count * n])
ḍ/ reduce by divisibility check
Charcoal, 37 bytes
Nθ≔⁰ηWθ«≦⊕η≔Φ⊕η∧κ¬﹪ηκζ¿¬﹪×ηLζΣζ≦⊖θ»Iη
Try it online! Link is to verbose version of code. Outputs the 1-indexed nᵗʰ Ore number. Explanation:
Nθ
Input n.
≔⁰η
Start looking for Ore numbers greater than zero.
Wθ«
Repeat until the nᵗʰ number has been found.
≦⊕η
Try the next integer.
≔Φ⊕η∧κ¬﹪ηκζ
Get its factors.
¿¬﹪×ηLζΣζ
If the harmonic mean is an integer, then...
≦⊖θ
Decrement the count of remaining Ore numbers to find.
»Iη
Print the found Ore number.