Skip to main content
edited body
Source Link
Dominic van Essen
  • 35.5k
  • 2
  • 21
  • 57

Another recursive 'try 21,32,43 or 54 pastes at each step' approach.

Another recursive 'try 2,3,4 or 5 pastes at each step' approach.

Another recursive 'try 1,2,3 or 4 pastes at each step' approach.

Source Link
Dominic van Essen
  • 35.5k
  • 2
  • 21
  • 57

Nibbles, 26 nibbles (13 bytes)

 `; 1 -@$ 0 `/ . +~,4 + _ * @$ +$~ [

Attempt This Online!

Another recursive 'try 2,3,4 or 5 pastes at each step' approach.

Nibbles only has integer arithmetic, so we can't (easily) count down & divide the target at each recursive step (as used in xnor's approach).

However, Nibbles does remember the program input as a global variable across all recursive calls, so we can simply count up the string-copies-so-far (starting at 1) and stop when we reach the program input, which is more intuitive to me anyway.

`; 1 -@$ 0 `/ . +~,4 + _ * @$ +$~ [         # full program; input is stored in variable @
`; 1                                        # launch recursive function starting with copies=1 
                                            # (stored in variable $)
     -@$                                    # stop when input <= copies-so-far
         0                                  # and return zero
                                            # otherwise return
           `/                     [         # minimum of
              .                             # map over
                +~,4                        # i in 2..5
                     +                      #   sum of
                       _                    #     recursive call using
                         * @$               #       copies-so-far * i
                              +$~           #     and i+1 (steps needed to multiply copies by i)