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

Source Link
ais523
  • 11
  • 19
  • 35

Brachylog (v2), 14 bytes

;A{Nfdmc≠&}f(t

Try it online!

Function submission; input from the left, output to the right. (The TIO link contains a command-line argument to run a function as though it were a full program.)

Explanation

"Is this a hostile divisor number?" code:

Nfdmc≠
N number is ≥0 (required to match the question's definition of "nth solution")
 f list of all factors of the number
 m for each factor
 d deduplicate its digits
 c concatenate all the deduplications with each other
 ≠ the resulting number has no repeated digits

This turned out basically the same as @UnrelatedString's, although I wrote it independently.

"nth solution to a " wrapper:

;A{...&}f(t
 & output the successful input to
 { }f the first n solutions of the problem
 ( taking <n, input> as a pair
;A form a pair of user input and a "no constraints" value
 t take the last solution (of those first n)

This is one of those cases where the wrapper required to produce the nth output is significantly longer than the code required to test each output in turn :-)

I came up with this wrapper independently of @UnrelatedString's. It's the same length and works on the same principle, but somehow ends up being written rather differently. It does have more potential scope for improvement, as we could add constraints on what values we were looking at for free via replacing the A with some constraint variable, but none of the possible constraint variables save bytes. (If there were a "nonnegative integer" constraint variable, you could replace the A with it, and then save a byte via making the the N unnecessary.)

Post Made Community Wiki by ais523

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