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

deleted 8 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina, 18 bytes

.+
$*
(^1?|111円)+$

Try it online! Shamelessly adapted from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Note that Is this number triangular? wasn't for some inexplicable reason required to support zero as a triangular number, so part of the adaption was to add a ? to make the leading 1 optional, allowing the group to match the empty string, and therefore a zero input. However, having immediatelynow matched the empty string, the + operator stops repeating, to avoid the infinite loop that would happen if it kept greedily matching the empty string (after all, ^1? would certainly keep matching). This means that it doesn't even try to match the other alternative in the group, thus avoiding the match of 2, 6, 12 etc. As @MartinEnder points out, a simpler way to avoid that while still matching the empty string is to anchor the match at the start while making the group optional for the same byte count: ^(^1|111円)*$.

Retina, 18 bytes

.+
$*
(^1?|111円)+$

Try it online! Shamelessly adapted from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Note that Is this number triangular? wasn't for some inexplicable reason required to support zero as a triangular number, so part of the adaption was to add a ? to make the leading 1 optional, allowing the group to match the empty string, and therefore a zero input. However, having immediately matched the empty string, the + operator stops repeating, to avoid the infinite loop that would happen if it kept greedily matching the empty string (after all, ^1? would certainly keep matching). This means that it doesn't even try to match the other alternative in the group, thus avoiding the match of 2, 6, 12 etc. As @MartinEnder points out, a simpler way to avoid that while still matching the empty string is to anchor the match at the start while making the group optional for the same byte count: ^(^1|111円)*$.

Retina, 18 bytes

.+
$*
(^1?|111円)+$

Try it online! Shamelessly adapted from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Note that Is this number triangular? wasn't for some inexplicable reason required to support zero as a triangular number, so part of the adaption was to add a ? to make the leading 1 optional, allowing the group to match the empty string, and therefore a zero input. However, having now matched the empty string, the + operator stops repeating, to avoid the infinite loop that would happen if it kept greedily matching the empty string (after all, ^1? would certainly keep matching). This means that it doesn't even try to match the other alternative in the group, thus avoiding the match of 2, 6, 12 etc. As @MartinEnder points out, a simpler way to avoid that while still matching the empty string is to anchor the match at the start while making the group optional for the same byte count: ^(^1|111円)*$.

added 826 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina, 18 bytes

.+
$*
(^1?|111円)+$

Try it online! Shamelessly adapted from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Note that Is this number triangular? wasn't for some inexplicable reason required to support zero as a triangular number, so part of the adaption was to add a ? to make the leading 1 optional, allowing the group to match the empty string, and therefore a zero input. However, having immediately matched the empty string, the + operator stops repeating, to avoid the infinite loop that would happen if it kept greedily matching the empty string (after all, ^1? would certainly keep matching). This means that it doesn't even try to match the other alternative in the group, thus avoiding the match of 2, 6, 12 etc. As @MartinEnder points out, a simpler way to avoid that while still matching the empty string is to anchor the match at the start while making the group optional for the same byte count: ^(^1|111円)*$.

Retina, 18 bytes

.+
$*
(^1?|111円)+$

Try it online! Shamelessly adapted from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Retina, 18 bytes

.+
$*
(^1?|111円)+$

Try it online! Shamelessly adapted from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Note that Is this number triangular? wasn't for some inexplicable reason required to support zero as a triangular number, so part of the adaption was to add a ? to make the leading 1 optional, allowing the group to match the empty string, and therefore a zero input. However, having immediately matched the empty string, the + operator stops repeating, to avoid the infinite loop that would happen if it kept greedily matching the empty string (after all, ^1? would certainly keep matching). This means that it doesn't even try to match the other alternative in the group, thus avoiding the match of 2, 6, 12 etc. As @MartinEnder points out, a simpler way to avoid that while still matching the empty string is to anchor the match at the start while making the group optional for the same byte count: ^(^1|111円)*$.

added 10 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina, 1718 bytes

.+
$*
(^1|111円^1?|111円)+$

Try it online! Try it online! Shamelessly stolenadapted from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Retina, 17 bytes

.+
$*
(^1|111円)+$

Try it online! Shamelessly stolen from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Retina, 18 bytes

.+
$*
(^1?|111円)+$

Try it online! Shamelessly adapted from @MartinEnder's answer to Is this number triangular? but with the base conversion included at a cost of 6 bytes.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290
Loading

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