Skip to main content
added 139 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Retina 0.8.2, 201 9292 91 bytes

.+
$*
^((^1|11\2)+)?*?)((1(?(4)1\4))+)?*?)((1(?(6)1\6))+)?*?)((1(?(8)1\8))+)$
$.17 $.35 $.53 $.71
^+` +0$

Try it online!Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

^((^1|11\2)+)?*?)((1(?(4)1\4))+)?*?)((1(?(6)1\6))+)?*?)((1(?(8)1\8))+)$

Try to match 43 squares greedilylazily, plus a 4th square (greedily, since that's golfier). This is based on my answer to Three triangular numbers but adjusted to match squares instead. (I'm not sure where the original square matching pattern was devised but Retina's entry in the Showcase of Languages has it.) The lazy matching of the first three squares are lazily quantified so as to match as fewgenerates the squares in ascending order, with the first squares as low as possible (preferably zero).

$.17 $.35 $.53 $.71

List the matched squares in descending order.

^+` +0$

Delete any leadingtrailing zeros.

Retina 0.8.2, 201 92 bytes

.+
$*
^((^1|11\2)+)??((1(?(4)1\4))+)??((1(?(6)1\6))+)??((1(?(8)1\8))+)$
$.1 $.3 $.5 $.7
^ +

Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

^((^1|11\2)+)??((1(?(4)1\4))+)??((1(?(6)1\6))+)??((1(?(8)1\8))+)$

Try to match 4 squares greedily. This is based on my answer to Three triangular numbers but adjusted to match squares instead. (I'm not sure where the original square matching pattern was devised but Retina's entry in the Showcase of Languages has it.) The first three squares are lazily quantified so as to match as few squares as possible.

$.1 $.3 $.5 $.7

List the matched squares.

^ +

Delete any leading zeros.

Retina 0.8.2, 201 92 91 bytes

.+
$*
^((^1|11\2)*?)((1(?(4)1\4))*?)((1(?(6)1\6))*?)((1(?(8)1\8))+)$
$.7 $.5 $.3 $.1
+` 0$

Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

^((^1|11\2)*?)((1(?(4)1\4))*?)((1(?(6)1\6))*?)((1(?(8)1\8))+)$

Try to match 3 squares lazily, plus a 4th square (greedily, since that's golfier). This is based on my answer to Three triangular numbers but adjusted to match squares instead. (I'm not sure where the original square matching pattern was devised but Retina's entry in the Showcase of Languages has it.) The lazy matching of the first three squares generates the squares in ascending order, with the first squares as low as possible (preferably zero).

$.7 $.5 $.3 $.1

List the matched squares in descending order.

+` 0$

Delete any trailing zeros.

deleted 360 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Retina 0.8.2, 201201 92 bytes

.+
$*
^((^1|11\2)+)??((1(?(4)1\4))*)$|^((^1|11\6)+)((1(?(8)1\8))+)((1(?(10)1\10))+)$|^((^1|11\12)+)((1(?(146)1\141\6))+)((1(?(16)1\16))+)?((1(?(188)1\181\8))+)$
$.1 $.3 $.5 $.7 $.9 $.11 $.13 $.15 $.17
^ +| 0? *$+

Try it online!Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

^((^1|11\2)+)??((1(?(4)1\4))*)$

Try to match 1 or 2 squares greedily (this always prefers to match 1 square if possible)...

|^((^1|11\6)+)((1(?(8)1\8))+)((1(?(10)1\10))+)$

... otherwise try to match 3 squares greedily...

|^((^1|11\12)+)((1(?(146)1\141\6))+)((1(?(16)1\16))+)?((1(?(188)1\181\8))+)$

... otherwise Try to match 4 squares greedily. This is based on my answer to Three triangular numbers but adjusted to match squares instead. (I'm not sure where the original square matching pattern was devised but Retina's entry in the Showcase of Languages has it.) The first three squares are lazily quantified so as to match as few squares as possible.

$.1 $.3 $.5 $.7 $.9 $.11 $.13 $.15 $.17

List all of the matched squares.

^ +| 0? *$+

Delete empty or zero matchesany leading zeros.

Retina 0.8.2, 201 bytes

.+
$*
^((^1|11\2)+)((1(?(4)1\4))*)$|^((^1|11\6)+)((1(?(8)1\8))+)((1(?(10)1\10))+)$|^((^1|11\12)+)((1(?(14)1\14))+)((1(?(16)1\16))+)((1(?(18)1\18))+)$
$.1 $.3 $.5 $.7 $.9 $.11 $.13 $.15 $.17
^ +| 0? *$

Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

^((^1|11\2)+)((1(?(4)1\4))*)$

Try to match 1 or 2 squares greedily (this always prefers to match 1 square if possible)...

|^((^1|11\6)+)((1(?(8)1\8))+)((1(?(10)1\10))+)$

... otherwise try to match 3 squares greedily...

|^((^1|11\12)+)((1(?(14)1\14))+)((1(?(16)1\16))+)((1(?(18)1\18))+)$

... otherwise match 4 squares greedily. This is based on my answer to Three triangular numbers but adjusted to match squares instead. (I'm not sure where the original square matching pattern was devised but Retina's entry in the Showcase of Languages has it.)

$.1 $.3 $.5 $.7 $.9 $.11 $.13 $.15 $.17

List all of the matched squares.

^ +| 0? *$

Delete empty or zero matches.

Retina 0.8.2, 201 92 bytes

.+
$*
^((^1|11\2)+)??((1(?(4)1\4))+)??((1(?(6)1\6))+)??((1(?(8)1\8))+)$
$.1 $.3 $.5 $.7
^ +

Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

^((^1|11\2)+)??((1(?(4)1\4))+)??((1(?(6)1\6))+)??((1(?(8)1\8))+)$

Try to match 4 squares greedily. This is based on my answer to Three triangular numbers but adjusted to match squares instead. (I'm not sure where the original square matching pattern was devised but Retina's entry in the Showcase of Languages has it.) The first three squares are lazily quantified so as to match as few squares as possible.

$.1 $.3 $.5 $.7

List the matched squares.

^ +

Delete any leading zeros.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Retina 0.8.2, 201 bytes

.+
$*
^((^1|11\2)+)((1(?(4)1\4))*)$|^((^1|11\6)+)((1(?(8)1\8))+)((1(?(10)1\10))+)$|^((^1|11\12)+)((1(?(14)1\14))+)((1(?(16)1\16))+)((1(?(18)1\18))+)$
$.1 $.3 $.5 $.7 $.9 $.11 $.13 $.15 $.17
^ +| 0? *$

Try it online! Link includes test cases. Explanation:

.+
$*

Convert to unary.

^((^1|11\2)+)((1(?(4)1\4))*)$

Try to match 1 or 2 squares greedily (this always prefers to match 1 square if possible)...

|^((^1|11\6)+)((1(?(8)1\8))+)((1(?(10)1\10))+)$

... otherwise try to match 3 squares greedily...

|^((^1|11\12)+)((1(?(14)1\14))+)((1(?(16)1\16))+)((1(?(18)1\18))+)$

... otherwise match 4 squares greedily. This is based on my answer to Three triangular numbers but adjusted to match squares instead. (I'm not sure where the original square matching pattern was devised but Retina's entry in the Showcase of Languages has it.)

$.1 $.3 $.5 $.7 $.9 $.11 $.13 $.15 $.17

List all of the matched squares.

^ +| 0? *$

Delete empty or zero matches.