Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    \$\begingroup\$ So this uses recursion to "regenerate" the set if the one generated is invalid? Definitely something wrong with your code if it's hitting recursion depth at f(1), the only possible array that should be generable at n=1 is [1] Also there's a lot of extraneous whitespace to be removed here. Remember this is a code-golf challenge, so the goal is to achieve the lowest bytecount \$\endgroup\$ Commented Nov 20, 2018 at 18:32
  • 1
    \$\begingroup\$ range(1,n) -> range(n) I believe should resolve the bug. \$\endgroup\$ Commented Nov 20, 2018 at 18:34
  • 1
    \$\begingroup\$ This should fix your bug, and also removes extraneous whitespace. I imagine there's a lot more room for golfing too \$\endgroup\$ Commented Nov 20, 2018 at 18:35
  • 1
    \$\begingroup\$ Although the recursion slightly worsens from 5 to 4, you can combine your two return statements like this: return len(s)==n and sum(s)==n*n and s or f(n) (Try it online 114 bytes). \$\endgroup\$ Commented Nov 20, 2018 at 19:38
  • 1
    \$\begingroup\$ You can have it all on one line. 111 bytes \$\endgroup\$ Commented Nov 20, 2018 at 22:02