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 1158 characters in body
Source Link
Martin Ender
  • 198.2k
  • 67
  • 455
  • 998

Retina, 34 bytes

Byte count assumes ISO 8859-1 encoding.

M!&`(1+)$(?<=^1円+)
1>`¶
^(1+)¶11円

Input in unary, output 1 for abundant numbers, 0 otherwise.

Try it online!

Explanation

M!&`(1+)$(?<=^1円+)

We start by getting all divisors of the input. To do this, we return (!) all overlapping (&) matches (M) of the regex (1+)$(?<=^1円+). The regex matches some suffix of the input, provided that the entire input is a multiple of that suffix (which we ensure by trying to reach the beginning fo the string using only copies of the suffix). Due to the way the regex engine looks for matches, this will result a list of divisors in descending order (separated by linefeeds).

1>`¶

The stage itself simply matches linefeeds () and removes them. However, the 1> is a limit, which skips the first match. So this effectively adds together all divisors except the input itself. We end up with the input on the first line and the sum of all proper divisors on the second line.

^(1+)¶11円

Finally, we try to match the at least one more 1 on the second line than we have on the first line. If that's the case, the sum of proper divisors exceeds the input. Retina counts the number of matches of this regex, which will be 1 for abundant numbers and 0 otherwise.

Retina, 34 bytes

Byte count assumes ISO 8859-1 encoding.

M!&`(1+)$(?<=^1円+)
1>`¶
^(1+)¶11円

Input in unary, output 1 for abundant numbers, 0 otherwise.

Try it online!

Retina, 34 bytes

Byte count assumes ISO 8859-1 encoding.

M!&`(1+)$(?<=^1円+)
1>`¶
^(1+)¶11円

Input in unary, output 1 for abundant numbers, 0 otherwise.

Try it online!

Explanation

M!&`(1+)$(?<=^1円+)

We start by getting all divisors of the input. To do this, we return (!) all overlapping (&) matches (M) of the regex (1+)$(?<=^1円+). The regex matches some suffix of the input, provided that the entire input is a multiple of that suffix (which we ensure by trying to reach the beginning fo the string using only copies of the suffix). Due to the way the regex engine looks for matches, this will result a list of divisors in descending order (separated by linefeeds).

1>`¶

The stage itself simply matches linefeeds () and removes them. However, the 1> is a limit, which skips the first match. So this effectively adds together all divisors except the input itself. We end up with the input on the first line and the sum of all proper divisors on the second line.

^(1+)¶11円

Finally, we try to match the at least one more 1 on the second line than we have on the first line. If that's the case, the sum of proper divisors exceeds the input. Retina counts the number of matches of this regex, which will be 1 for abundant numbers and 0 otherwise.

Source Link
Martin Ender
  • 198.2k
  • 67
  • 455
  • 998

Retina, 34 bytes

Byte count assumes ISO 8859-1 encoding.

M!&`(1+)$(?<=^1円+)
1>`¶
^(1+)¶11円

Input in unary, output 1 for abundant numbers, 0 otherwise.

Try it online!

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