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 47 characters in body
Source Link
lyxal
  • 35.6k
  • 2
  • 69
  • 148

Vyxal g, 1511 bytes

ẏ:Ẋsλƒṡ1İ∑0=;csẊ'ƒṡ1İ∑0=

Try it Online! Try it Online!

A simple little approach.

Explained

ẏ:Ẋsλƒṡ1İ∑0=;csẊ'ƒṡ1İ∑0=
ẏ: # The range [0, len(input)), twice.
 Ẋs # cartesian product of the two lists and sort to get the first
 ' λ ;c # get the firstall itemitems of that where
 ƒṡ # the list turned into an inclusive range between the two numbers
 1İ # indexed into the sequence of numbers
 ∑0= # summed equals n
 s # sort the list sog it'sflag ingets the rightsmallest order.pair

Vyxal, 15 bytes

ẏ:Ẋsλƒṡ1İ∑0=;cs

Try it Online!

A simple little approach.

Explained

ẏ:Ẋsλƒṡ1İ∑0=;cs
ẏ: # The range [0, len(input)), twice.
 Ẋs # cartesian product of the two lists and sort to get the first
 λ ;c # get the first item of that where
 ƒṡ # the list turned into an inclusive range between the two numbers
 1İ # indexed into the sequence of numbers
 ∑0= # summed equals n
 s # sort the list so it's in the right order.

Vyxal g, 11 bytes

ẏ:Ẋ'ƒṡ1İ∑0=

Try it Online!

A simple little approach.

Explained

ẏ:Ẋ'ƒṡ1İ∑0=
ẏ: # The range [0, len(input)), twice.
  # cartesian product of the two lists and sort to get the first
 ' # get all items of that where
 ƒṡ # the list turned into an inclusive range between the two numbers
 1İ # indexed into the sequence of numbers
 ∑0= # summed equals n
# g flag gets the smallest pair
Source Link
lyxal
  • 35.6k
  • 2
  • 69
  • 148

Vyxal, 15 bytes

ẏ:Ẋsλƒṡ1İ∑0=;cs

Try it Online!

A simple little approach.

Explained

ẏ:Ẋsλƒṡ1İ∑0=;cs
ẏ: # The range [0, len(input)), twice.
 Ẋs # cartesian product of the two lists and sort to get the first
 λ ;c # get the first item of that where
 ƒṡ # the list turned into an inclusive range between the two numbers
 1İ # indexed into the sequence of numbers
 ∑0= # summed equals n
 s # sort the list so it's in the right order.

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