Skip to main content
added 134 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina, 5252 31 bytes

\d+ $* +m`^^((1+) ((1+|1+ )*)(+(\1?)(1*)<-2>\2)$ $2$4¶$2$6 1m`^$+$ 

Try it online!Try it online! Takes input as a space-separated list of coins and notes followed by the desired value.

I wanted Edit: Saved 18 bytes thanks to do this in a single regexp using balancing groups@Kobi who debugged my code. Explanation: The idea isfirst two lines simply convert from decimal to match all of the coin and note values,unary. The third line then repeat through possibly matching each ofcaptures the balancing groupslist of coins and notes. But I guessThe alternation allows the regexp engine doesn'tto backtrack inand choose not to capture specific coins/notes. The balancing group then matches the way I wantvalue against all suffixes of the the capture list (unnecessary but golfier.)

\d+ $* ^((1+) )+(\2?(?<-2>))+$ 

Retina, 52 bytes

\d+ $* +m`^(1+) ((1+ )*)((\1?)(1*))$ $2$4¶$2$6 1m`^$ 

Try it online! Takes input as a space-separated list of coins and notes followed by the desired value.

I wanted to do this in a single regexp using balancing groups. The idea is to match all of the coin and note values, then repeat through possibly matching each of the balancing groups. But I guess the regexp engine doesn't backtrack in the way I want.

\d+ $* ^((1+) )+(\2?(?<-2>))+$ 

Retina, 52 31 bytes

\d+ $* ^((1+) |1+ )+(?<-2>\2)+$ 

Try it online! Takes input as a space-separated list of coins and notes followed by the desired value. Edit: Saved 18 bytes thanks to @Kobi who debugged my code. Explanation: The first two lines simply convert from decimal to unary. The third line then captures the list of coins and notes. The alternation allows the engine to backtrack and choose not to capture specific coins/notes. The balancing group then matches the value against all suffixes of the the capture list (unnecessary but golfier.)

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

Retina, 52 bytes

\d+ $* +m`^(1+) ((1+ )*)((\1?)(1*))$ $2$4¶$2$6 1m`^$ 

Try it online! Takes input as a space-separated list of coins and notes followed by the desired value.

I wanted to do this in a single regexp using balancing groups. The idea is to match all of the coin and note values, then repeat through possibly matching each of the balancing groups. But I guess the regexp engine doesn't backtrack in the way I want.

\d+ $* ^((1+) )+(\2?(?<-2>))+$