Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 10 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, 6267 bytes

function(a,b)sum(which(!a%%1:a))-a==b|suma==b&sum(which(!b%%1:b))-b==ab==a&b!=a

Try it online! Try it online!

returns TRUE for amicable, FALSE for not.

R, 62 bytes

function(a,b)sum(which(!a%%1:a))-a==b|sum(which(!b%%1:b))-b==a

Try it online!

returns TRUE for amicable, FALSE for not.

R, 67 bytes

function(a,b)sum(which(!a%%1:a))-a==b&sum(which(!b%%1:b))-b==a&b!=a

Try it online!

returns TRUE for amicable, FALSE for not.

Post Undeleted by Giuseppe
deleted 177 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, (削除) 60 (削除ここまで) 5362 bytes

function(a,b)sum(which(!a%%1:a))==sum-a==b|sum(which(!b%%1:b))-b==a

Try it online! Try it online!

returns TRUE for amicable numbers, FALSE otherwise. which(!a%%1:a) computes the divisors of a, including a itself. Since sum(which(!a%%1:a))==a+b if and only if a,b are amicable, we just check if the divisor sums are equalfor not.

R, (削除) 60 (削除ここまで) 53 bytes

function(a,b)sum(which(!a%%1:a))==sum(which(!b%%1:b))

Try it online!

returns TRUE for amicable numbers, FALSE otherwise. which(!a%%1:a) computes the divisors of a, including a itself. Since sum(which(!a%%1:a))==a+b if and only if a,b are amicable, we just check if the divisor sums are equal.

R, 62 bytes

function(a,b)sum(which(!a%%1:a))-a==b|sum(which(!b%%1:b))-b==a

Try it online!

returns TRUE for amicable, FALSE for not.

Post Deleted by Giuseppe
deleted 104 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

R, 60(削除) 60 (削除ここまで) 53 bytes

function(a,b)sum(which(!a%%1:a))-b-a|sum==sum(which(!b%%1:b))-b-a

Try it online! Try it online!

returns FALSETRUE for amicable numbers, TRUEFALSE otherwise. which(!a%%1:a) computes the divisors of a, including a itself. Hence,Since sum(which(!a%%1:a))==a+b if and only if a,b are amicable, and likewise for b. Since zero is falsey in R and nonzero is truthy, we can use arithmetic and | to combine them, yieldingjust check if the inverted resultdivisor sums are equal.

R, 60 bytes

function(a,b)sum(which(!a%%1:a))-b-a|sum(which(!b%%1:b))-b-a

Try it online!

returns FALSE for amicable numbers, TRUE otherwise. which(!a%%1:a) computes the divisors of a, including a itself. Hence, sum(which(!a%%1:a))==a+b if and only if a,b are amicable, and likewise for b. Since zero is falsey in R and nonzero is truthy, we can use arithmetic and | to combine them, yielding the inverted result.

R, (削除) 60 (削除ここまで) 53 bytes

function(a,b)sum(which(!a%%1:a))==sum(which(!b%%1:b))

Try it online!

returns TRUE for amicable numbers, FALSE otherwise. which(!a%%1:a) computes the divisors of a, including a itself. Since sum(which(!a%%1:a))==a+b if and only if a,b are amicable, we just check if the divisor sums are equal.

Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106
Loading

AltStyle によって変換されたページ (->オリジナル) /