g | x | w | all
Bytes Lang Time Link
082Tcl250618T155401Zsergiol
065Haskell250618T072226ZIbozz91
074Commodore BASIC250617T203127ZMark Ree
045Arturo230203T013424Zchunes
017Uiua SBCS240216T140549Zchunes
036Ruby221125T042330ZJordan
072Janet250430T181119ZAdam
084Swift 6250430T002821ZmacOSist
050Juby221010T034622ZJordan
072Scala230418T062829Z138 Aspe
008Vyxal220507T003637Zlyxal
085Nibbles230325T223221ZAdam
123Rust230207T140430ZJSorngar
093Java 8230203T175526ZFhuvi
nan230205T102636ZThe Thon
104Swift230203T160954ZBbrk24
078Python 3221216T055200Zuser1139
010Japt221010T144247ZShaggy
033Raku221010T191017ZSean
010Pyth221010T181935Zhakr14
nan221010T141754Zbigyihsu
047Python220509T152841ZSamathin
075R220509T101910ZDominic
099SNOBOL4 CSNOBOL4220510T161753ZGiuseppe
084Brainfuck220507T214125ZJiří
01005AB1E220508T145614ZCommand
040Julia220509T091740ZMarcMush
044JavaScript Node.js220509T103014Zferikeem
069JavaScript Node.js220507T225937ZNoodle9
058PARI/GP220507T012816Zalephalp
020Burlesque220508T221636ZDeathInc
059C clang220507T005536Za stone
028BQN220508T005012ZRazetime
021BQN220508T102201Zovs
114Javascript Node.js220507T143931ZLWS SWL
053Factor220507T012416Zchunes
010Jelly220507T213051ZUnrelate
036Wolfram Language Mathematica220507T015811Zatt
151C gcc220507T162407ZLWS SWL
021K ngn/k220507T151413ZTraws
012Husk220507T094840ZDominic
083Bash220507T110956ZNoodle9
010Charcoal220507T070415ZNeil
1513Retina220507T022517Zm90
014Retina 0.8.2220507T065437ZNeil
015Pip220507T050847ZDLosc
054Python220507T011119Zloopy wa
014Jelly220507T005320Zhyperneu

Tcl, 82 85 98 bytes

proc D x {join [lmap c [set X [split $x ""]] {join [linsert $X [incr i] '] ""}] +}

Try it online!

Haskell, 65 bytes

g(c:a@(d:s))=(c:'\'':a++"+"):map(c:)(g a)
g c=[c++"'"]
f=concat.g

Try it online!

Commodore BASIC, 74 bytes

0INPUTE$:L=LEN(E$):FORI=1TOL:FORJ=1TOL:PRINTMID$(E$,J,1);:IFI=JTHENPRINT"'";
1NEXT:PRINT"+";:NEXT:PRINTCHR$(20)

This is a complete RUNnable program; the 74-byte figure is the amount of memory it takes up. The full-text source above is 111 characters, though it can be typed in using keyword abbreviations in only 83:

0inpute$:l=len(e$):fOi=1tol:fOj=1tol:?mI(e$,j,1);:ifi=jtH?"'";
1nE:?"+";:nE:?cH(20)

Arturo, 49 47 45 bytes

$[s][join.with:"+"map size s=>[insert s&"'"]]

Try it

Uiua SBCS, 21 20 17 bytes

/⊂₃@+≡⌟⍜⊙↻⊂@'+₁°⊏

Try it!

-1 thanks to janMakoso

-3 thanks to language updates and janMakoso

Ruby, 36 bytes

->s{s.chars.map{s.sub _1,'\&\''}*?+}

Attempt This Online!

Ruby, 36 bytes

Alternate based on Deadcode's comment on OP.

->s{s.gsub(/./){"+#$`#$&'#$'"}[1..]}

Attempt This Online!

Janet, 72 bytes

|(string/join(seq[n :keys $](string(take(inc n)$)"'"(drop(inc n)$)))"+")

Swift 6, 84 bytes

let d={s in{(1...(s+"").count).map{s.prefix($0)+"'"+s.dropFirst($0)}.joined}()("+")}

Try it on SwiftFiddle!

J-uby, 50 bytes

(:-&(:& &:*))%[:& &:sub|:~|~:& &'\&\'',A]|(~:*&?+)

Attempt This Online!

Scala, 72 bytes

Golfed version. Try it online!

def f(l:String)=l.indices.map(i=>l.patch(i,s"${l(i)}'",1)).mkString("+")

Ungolfed version

object Main extends App {
  def f(l: String): String = {
    l.indices.map(i => l.patch(i, s"${l(i)}'", 1)).mkString("+")
  }

  val test = List("abc", "de", "longabcdef", "short")
  val expected = List(
    "a'bc+ab'c+abc'",
    "d'e+de'",
    "l'ongabcdef+lo'ngabcdef+lon'gabcdef+long'abcdef+longa'bcdef+longab'cdef+longabc'def+longabcd'ef+longabcde'f+longabcdef'",
    "s'hort+sh'ort+sho'rt+shor't+short'"
  )
  val checker = List("✖️", "✓")

  for ((t, e) <- test zip expected) {
    val s = f(t)
    val checkMark = checker(if (s == e) 1 else 0)
    println(s"$t -> $s $checkMark")
  }
}

Vyxal, 8 bytes

ż\'vṀ\+j

Try it Online!

No clue why I didn't vectorise insertion back in May 2022.

Explained

żƛ?n\'Ṁ;\+j
żƛ           # For each item P in the range 1...len(input):
  ?n         #   at position P in the input,
    \'Ṁ      #   insert a '
       ;     # end map
        \+j  # join the result of that on "+" and output

Nibbles, 8.5 bytes

*"+".,,@::`<$_"'"

Attempt This Online!

*"+".,,@::`<$_"'"
*                 Join
 "+"               with plus signs
    .              for each n in
     ,              range
      ,              length
       @              input
        :           join
         :           join
          `<$         first n characters of
             _         input
              "'"      apostrophe
                      the remaining characters

Rust, 123 bytes

|s|{s.chars().map(|_|s).enumerate().map(|(i,w)|{let mut t=w.repeat(1);t.insert(i+1,'\'');t}).collect::<Vec<_>>().join("+")}

Attempt This Online!

Java 8, 93 bytes

s->s.chars().mapToObj(e->s.replace((char)e+"",(char)e+"'")).reduce("",(a,b)->a==""?b:a+"+"+b)

Try it online!


Another close solution not using Streams (95 bytes) :

s->{String r="";for(String c:s.split("")){r+=(s+"+").replaceAll(c+"\\+{0,1}",c+"'");}return r;}

Thunno, \$ 16 \log_{256}(96) \approx \$ 13.17 bytes

LDIA*'+sjsAp''sj

Attempt This Online!

Port of DLosc's Pip answer.

Explanation

LDIA*'+sjsAp''sj  # Implicit input
LD                # Length of input and duplicate
  IA*             # Wrap input in a list and repeat length times
     '+sj         # Join this list by "+"
         sAp      # Split into chunks of length of input
            ''sj  # Join this list by "'"
                  # Implicit output

Swift, 104 bytes

Swift is not a good language for string manipulation.

{var a=""
for i in $0.indices{var c=$0
c.insert("'",at:c.index(after:i))
a+=c+"+"}
a.popLast()
return a}

Type is (String) -> String or (Substring) -> String.

Try it online!

Swift, 120 bytes

Not as short, but I think the way that a is initialized is funny.

{var a=[$0][..<0]
for i in $0.indices{var c=$0
c.insert("'",at:c.index(after:i))
a+=[c]}
return a.joined(separator:"+")}

If Array is a pair (pointer, length)*, indexing operations are like this:

So, arr[..<0] creates an empty collection no matter what the array is. Here, I'm applying it to the array literal [$0], which you would never do in practice but is technically legal.

*It's actually a triplet (pointer, length, capacity), but this gets the point across.

**Yes, this exists for some reason.

Python 3, 78 bytes

d=lambda s:'+'.join([s[:i+1]+'\''+s[i+1:] for i in range(len(s)) if i<len(s)])

Try it online!

Japt, 10 bytes

¬£i''YÄÃq+

Try it

¬£i''YÄÃq+     :Implicit input of string
¬              :Split
 £             :Map each element at 0-based index Y
  i''          :  Insert a "'" in U at index
     YÄ        :  Y+1
       Ã       :End map
        q+     :Join with "+"

Raku, 33 bytes

This 33-byte version works on my local recent-ish version of Raku:

{join '+',.comb.map:{S/$^a/$a'/}}

But not on TIO, where a few more bytes are needed:

{join '+',.comb.map:{$^a;S/$a/$a'/}}

Try it online!

Pyth, 10 bytes

j\+XRQ\'Sl

Test suite

Explanation:
j\+XRQ\'Sl  | Full code
j\+XRQ\'SlQ | with implicit variables
------------+--------------------------------------
    R   SlQ | For each 1-index d of the input,
   X Q\'    |  Insert "'" into the input at index d
j\+         | Join with "+"

Go, 150 bytes

import."strings"
type S=string
func f(s S)S{b:=[]S{}
for i:=range s{k:=""
for j,d:=range s{k+=S(d)
if j==i{k+="'"}}
b=append(b,k)}
return Join(b,"+")}

Attempt This Online!

Using strings.Builder, 153 bytes

import."strings"
func f(s string)string{b:=Builder{}
w:=b.WriteRune
for i:=range s{w('+')
for j,d:=range s{w(d)
if j==i{w('\'')}}}
return b.String()[1:]}

Attempt This Online!

Surprised how the string builder solution is only 3 bytes logner.

Python, 47 bytes

lambda s:"+".join(s.replace(c,c+"'")for c in s)

Attempt This Online!

How it works:

a  b  c  d --> a' b  c  d 
a  b  c  d --> a  b' c  d 
a  b  c  d --> a  b  c' d 
a  b  c  d --> a  b  c  d'

then join with '+'

R, 81 75 bytes

Edit: -6 bytes thanks to Giuseppe

function(x,`[`=substring)paste0(x[1,s<-1:nchar(x)],"'",x[s+1],collapse="+")

Try it online!

Takes advantage of the vectorization of substring over a vector of start (& optional end) positions, and the vectorization & argument-recycling of paste over vectors of strings to paste-together.

SNOBOL4 (CSNOBOL4), 99 bytes

	I =INPUT
N	X =X + 1
	I TAB(X) . L REM . R	:F(O)
	O =O "+" L "'" R	:(N)
O	O TAB(1) REM . OUTPUT
END

Try it online!

Brainfuck, 87 84 bytes

>,>---[>+<+++++++]>++[>,]<[<]<[<]>[[.>]>.>[.[-<<+>>]>[.>]<[<]<++++.----[->+<]<[<]]>]

Saved 3 bytes thanks to Nitrodon.

Try it online!

Explanation:

memory progress for abc:
null a null 'bc
null ab null 'c
null abc' null

string is split to two parts by null character

>,>                load first character
---[>+<+++++++]>++ load ' to memory; taken form esolangs wiki
[>,]               load rest of input
<[<]<[<]>          go to beginning of memory
[ 
 [.>]              print first part
 >.>               print '
 [                 check if there is text after '
  .                print first char of second part 
  [-<<+>>]         move char to the first part
  >[.>]            print rest of second part
  <[<]<            go to position of '
  ++++.----        use ' to print plus
  [->+<]           move '
  <[<]             go before beginning
 ]
 >                 move back to beginning
                   if there wasn't text after ' move after end instead
]

05AB1E, 10 bytes

ε''«Nǝ}'+ý

Try it online!

ε       map each character (of the implicit input string)
 ''     the ' character
 «      append to the current character
 N      iteration index
 ǝ      replace the input string's Nth character with the character with ' appended
}
'+      + character
ý       join by it

Julia, 40 bytes

a->join([replace(a,i=>"$i'") for i=a],+)

Attempt This Online!

only works with all letters distinct

Why...how...what...

JavaScript (Node.js), 46 44 bytes

l=>[...l].map(s=>l.replace(s,s+"'")).join`+`

Try it online!

-2 bytes thanks to emanresu A

JavaScript (Node.js), 83 \$\cdots\$ 72 69 bytes

s=>g=(r="",i=0)=>s[i]?g(r+("+"+s).slice(!i,++i+1)+"'"+s.slice(i),i):r

Try it online!

Saved 7 8 bytes thanks to emanresu A!!!
Saved 3 bytes thanks to Samathingamajig!!!

PARI/GP, 58 bytes

s->j=strjoin;j([j(strsplit(s,c),Str(c"'"))|c<-Vec(s)],"+")

Attempt This Online!

A port of @att's Mathematica answer.

Takes input as a string. Requires that all characters are unique.


PARI/GP, 64 bytes

v->i=1;j=strjoin;j([j([j(v[1..i]),j(v[i++..#v])],"'")|c<-v],"+")

Attempt This Online!

Take input as a list of characters.

Burlesque, 20 bytes

JiTjiS{''IC}Z[[-'+IC

Try it online!

J      # Dup
iT     # Tails
j      # Swap
iS     # Heads
{
 ''IC  # Intercalate "'"
}Z[    # Zip together then map
[-     # Drop head
'+IC   # Intercalate "+"

C (clang), 69 64 59 bytes

-10 thanks to @Noodle9 and @ceilingcat

l;f(char*a){for(l=0;a[l];)printf("+%.*s'%s"+!l,++l,a,a+l);}

Try it online!

BQN, 28 bytesSBCS

{1↓⥊'''∾˘⟨∘,≠𝕩⟩⥊«⥊'+'∾˘⊢⌜˜𝕩}

Run online!

returns the required string with a trailing space. removing that is +3 bytes

-3 from ovs, who also made this tacit.

BQN, 21 bytesSBCS

1↓⟜∾'+'∾¨1↓↑∾⟜'''⊸∾¨↓

Run online!

gives prefixes, suffixes. ∾⟜'''⊸∾¨ joins matching prefixes and suffixes with a single quote.

1↓ removes the first value (empty prefix ∾ ' ∾ full suffix).

'+'∾¨ prepends a + to each string.

1↓⟜∾ joins the string and removes the leading +.

Javascript (Node.js), 114 bytes

function a(b){l=b.length;s="";for(i=1;i<=l;i++){if(i>1)s+='+';s+=b.substring(0,i)+"'"+b.substring(i,l);}return s;}

Try it online!

I forgot to add "+"

+10 characters to remove a trailing '+'

Factor, 53 bytes

[ dup length [1,b] [ cut "'"glue ] with map "+"join ]

Try it online!

If the order of each product doesn't matter:

Factor, 43 bytes

[ all-rotations [ 39 suffix ] map "+"join ]

Try it online!

Explanation

                  ! "short"
all-rotations     ! { "short" "horts" "ortsh" "rtsho" "tshor" }
[ 39 suffix ] map ! { "short'" "horts'" "ortsh'" "rtsho'" "tshor'" }
"+"join           ! "short'+horts'+ortsh'+rtsho'+tshor'"

Jelly, 10 bytes

ṛ€j”+sLj”'

Try it online!

Port of DLosc's Pip solution.

 €            For each element of the input,
ṛ             the input.
  j”+         Join the copies on +,
     sL       split into slices the length of the original input,
       j”'    and join those on '.

Jelly, 11 bytes

p”'$ṛ¦ⱮJj”+

Try it online!

The implementation of ¦ is a bit questionable, so we can just abuse Cartesian product to make up for it.

p”'            Pair each element of the input with ',
   $ṛ¦         and substitute elements of that into the input at
      ⱮJ       each index, individually.
        j”+    Join the results on +.

Just for fun, without preserving the order within each term, ṭ-Ƥ”'ż@j”+ is 10.

Wolfram Language (Mathematica), 45 36 bytes

aRiffle[a/.#->#<>"'"&/@a,"+"]<>""

Try it online!

Input [{characters...}]. Assumes all characters in input are unique. Returns a string.


Wolfram Language (Mathematica), 35 bytes

ToString@Expand[Dt[1##]/._@a_:>a']&

Try it online!

Input [symbols...]. Assumes symbols are unique and not defined. Returns a spaced string.

Dt treats strings as constants.

C (gcc), 151 bytes

char*f(char*c,int i){char*r=malloc(i*i+i);char*o=r,k=0;for(;k<i*i;){if(k++%(i+1)==1)*o++='\'';*o++=*c++;if(!*c)c-=i,*o++='+';}*o--=0;*o='\'';return r;}

Try it online!

K (ngn/k), 21 bytes

Most straightforward K solution.

{"+"/?[x;;"'"]'1+!#x}

Try it online!

Explanation

{"+"/?[x;;"'"]'1+!#x}
     ?[x;;"'"]          / insert "'" in string at 
              '         / each position
               1+!#x    / 1..len of string
 "+"/                   / join the resulting strings with "+"

Husk, 14 12 bytes

J''CL¹J'+SRL

Try it online!

Same approach as DLosc's Pip answer.

Bash, 83 bytes

v=$1\';until [ $v = \'$1 ];do a+=+$v;v=$(sed "s/\(.\)'/'\1/"<<<$v);done;echo ${a#+}

Try it online!

Charcoal, 10 bytes

⪫⪪⪫Eθθ+Lθ'

Try it online! Link is to verbose version of code. Explanation: Port of @DLosc's Pip answer.

    θ       Input string
   E        For each character
     θ      Input string
  ⪫         Join on
      +     Literal string `+`
 ⪪          Split into substrings of length
        θ   Input string
       L    Length
⪫           Join on
         '  Literal string `'`
            Implicitly print

Retina, 15 13 bytes

L$|+`.
$>`'$'

Try it online!

-2 thanks to Neil.

Match every character. For each one, take the text before the separator after the matched string, followed by an apostrophe, followed by the text after the matched string. Print as a list with separator +.

Retina 0.8.2, 14 bytes

.
$`$&'$'+
.$

Try it online! Link includes test cases. Explanation:

.
$`$&'$'+

Replace each variable with its derivative multiplied by the other terms plus a trailing + to sum the products together.

.$

Delete the final trailing +.

Pip, 15 bytes

aRL#aJ'+<>#aJ''

Attempt This Online!

Explanation

aRL#aJ'+<>#aJ''
a                Command-line arg       "abc"
   #a            Length of arg          3
 RL              Repeat-list            ["abc"; "abc"; "abc"]
     J'+         Join on "+"            "abc+abc+abc"
        <>#a     Groups of size len(a)  ["abc"; "+ab"; "c+a"; "bc"]
            J''  Join on "'"            "abc'+ab'c+a'bc"

Python, 54 bytes

lambda s:((l:=len(s))*(l*"'"+-~l*(s+"+")))[-~l*~l::-l]

Attempt This Online!

Python, 56 bytes

lambda s:((l:=-~len(s))*(l*(s+"+")+-~l*"'"))[l:-3*l:-~l]

Attempt This Online!

Old Python, 58 bytes

lambda s:((l:=-~len(s))*(l*(s+"+")+l*"'"+"+"))[l:-3*l:-~l]

Attempt This Online!

How?

 a b c d +
(a)b c d +
 a(b)c d +
 a b(c)d +
 a b c(d)+
 ' ' ' '(')'
 a b c d(+)
 a b c d +
(a)b c d +
 a(b)c d +
 a b(c)d +
 ' ' '(')' '
 a b c(d)+
 a b c d(+)
 a b c d +
(a)b c d +
 a(b)c d +
 ' '(')' ' '
 a b(c)d +

   etc.

Jelly, 14 bytes

J‘œṖ€j€”'j”+”'

Try It Online!

J‘œṖ€j€”'j”+”'  Full Program
J               [1, 2, ..., len]
 ‘              [2, 3, ..., len + 1]
  œṖ€           For each of these, partition (*)
     j€”'       Join each partition on ' (**)
         j”+    Join on +
            ”'  An unparseable nilad forces the current string to be printed

(And then the ' is printed at the end)

(*)  partition takes a list on the left but since we give it a single number,
     it auto-wraps it so we just get all needed splits
(**) the last partition only has one sublist so join doesn't work properly here