| Bytes | Lang | Time | Link |
|---|---|---|---|
| 021 | Uiua | 240818T193724Z | janMakos |
| 010 | Japt | 240818T181308Z | Shaggy |
| 069 | R | 240818T160530Z | int 21h |
| 004 | Burlesque | 200125T181202Z | Mintable |
| 048 | Perl 5 lF | 200204T232441Z | Xcali |
| 060 | Ruby | 200128T125424Z | G B |
| 004 | Husk | 200128T113835Z | user8505 |
| nan | PHP | 200125T185533Z | Guillerm |
| nan | Scratch 3.0 | 200126T071628Z | lyxal |
| 112 | R | 200126T231952Z | MickyT |
| 017 | Charcoal | 200126T112502Z | Neil |
| 090 | JavaScript ES7 | 200126T101947Z | Arnauld |
| 042 | PowerShell | 200126T092249Z | Andrei O |
| 034 | Haskell | 200125T191131Z | xnor |
| 068 | Python 2 | 200125T223507Z | Chas Bro |
| 002 | Jelly | 200125T153930Z | Jonathan |
| 005 | Pyth | 200125T151604Z | Mr. Xcod |
| 016 | J | 200125T145035Z | Jonah |
| 003 | 05AB1E | 200125T134713Z | Grimmy |
| 032 | Perl 6 | 200125T131424Z | Jo King |
| 006 | 05AB1E | 200125T121639Z | mabel |
| 095 | Python 3 | 200125T120006Z | RGS |
R, 69 bytes
for(j in s<-el(strsplit(scan(,q<-''),q)))cat(q<-outer(q,s,paste0),'')
A program which takes a string as an input and outputs the permutations as defined in the question.
A more verbose version with comments:
# q is an empty string
q <- ''
# split the input
# in characters and save as s
s <- el(strsplit(scan(,q),q))
# concatenate q with every character
# of s, assign the result back to q and
# print it out. Repeat the process
# as many times as the length
# of the input string
for(j in s)cat(q<-outer(q,s,paste0),'')
Burlesque, 5 4 bytes
sacb
-1 thanks to DeathIncarnate!
sa # Duplicate the input and get it's length
cb # Get all combinations of the input characters up to the length of the input
Husk, 4 bytes
Total Husk novice, there may be better ways to golf this.
Mπŀ¹
Explanation
ŀ¹ Find the range [1, ..., len(input)]
Mπ Map with cartesian power of input
PHP, 176 174 173 171 170 166 bytes
$c=$t=count($u=array_values(array_unique(str_split($argn))));for($s=1;$i<$t**$t;){$i-$c?:[$s++,$c*=$t,$i=0];for($k=$i++,$j=0;$j<$s;$j++,$k/=$t)echo$u[$k%$t];echo',';}
-4 bytes thanks to @Ismael Miguel.
Method: simply count in base N, where N is the number of unique characters in the input string.
Scratch 3.0, 65 blocks / 637 632 bytes
Look at y'all, having fun with your fancy shmancy permutation functions/map tools. Well, not I! No, not I! When using Scratch, one has to do things themselves! You won't find any built-ins around these parts! I'm just glad there still ain't any gotos ;)
But more seriously, the image is split into 4 parts because it's just soooo long Press space to clear the lists before each run
And finally,
As SB Syntax:
when gf clicked
set[c v]to(0
ask()and wait
set[L v]to(length of(answer
add(1)to[b v
repeat((L)-(1
add(0)to[b v
end
repeat until<(c)=(1
set[s v]to(0
set[l v]to(1
repeat(length of[b v
change[s v]by(item(l)of[b v
change[l v]by(1
end
if<(s)=((L)*(L))>then
set[c v]to(1
end
set[r v]to(
set[l v]to(1
repeat(length of[b v
set[r v]to(join(r)(letter(item(i)of[b v])of(answer
change[i v]by(1
end
add(r)to[o v
replace item(1)of[b v]with((item(1)of[b v])+(1
set[j v]to(1
repeat(length of[b v
if<(item(j)of[b v])>(length of(answer))>then
replace item(j)of[b v]with(1
replace item((j)+(1))of[b v]with((item((j)+(1))of[b v])+(1
end
change[j v]by(1
-5 bytes due to not being a silly billy and removing extranous spaces
R, 112 bytes
function(S,s=sapply)cat(unlist(s(1:nchar(S),function(X)do.call('paste0',expand.grid(s(rep(S,X),strsplit,''))))))
Things that make you go Argh, strings in R.
Expands out to the following
cat( # output the results
unlist( # collapse the list
sapply(1:nchar(S), # for 1 to character length of S
function(X)do.call('paste0', # for each row from the grid paste characters together
expand.grid( # create permutations
sapply(rep(S,X),strsplit,'')))))) # replicate the string X times and split.
So we produce a lists of [['a','b','c']], [['a','b','c'],['a','b','c']], [['a','b','c'],['a','b','c'],['a','b','c']].
These are feed into expand.grid to produce the permutations.
Each row of the grid is pasted together with no gaps in the do.call.
As it is still in a list we apply unlist so that cat will be able to output it.
Charcoal, 17 bytes
FEθXLθ⊕κEι✂⍘⁺ικθ¹
Try it online! Link is to verbose version of code. Explanation:
FEθXLθ⊕κ
Loop over the substring lengths and raise the length to each power in turn.
Eι✂⍘⁺ικθ¹
Loop from each power to double its value and perform base conversion using the input string as the alphabet, then slice off the first character.
JavaScript (ES7), 90 bytes
Returns a Set.
s=>new Set([...Array(n=(L=-~s.length)**~-L)].map(_=>(g=n=>n?[s[n%L-1]]+g(n/L|0):'')(n--)))
Commented
s => new Set( // build a set from
[...Array( // an array of
n = // n entries, with:
(L = -~s.length) // n = L ** (L - 1)
** ~-L // where L is the length of s + 1
)] //
.map(_ => // for each entry:
( g = n => // g is a recursive function taking n
n ? // if n is not equal to 0:
[s[n % L - 1]] // output s[(n mod L) - 1]
// or an empty string if it's undefined
+ g(n / L | 0) // recursive call with floor(n / L)
: // else:
'' // stop recursion
)(n--) // initial call to g; decrement n afterwards
) // end of map()
) // end of Set()
Haskell, 34 bytes
f s=init$mapM(\_->s)=<<scanr(:)[]s
Here's how it works, using input s="abc":
scanr(:)[]s
Produces the suffixes of s, ["abc","bc","c",""], by prepending each character in turn to the front and tracking the intermediate results.
mapM(\_->s)
Uses the list monad to map each element to s, that is, 'xy'-> ["abc","abc"], and take multiply them as a Cartesian product, here giving ["aa","ab","ac","ba","bb","bc","ca","cb","cc"].
mapM(\_->s)=<<scanr(:)[]s
Uses =<< as concatMap to take the function above that uses mapM and apply it to each of the suffixes, thereby producing the Cartesian products of copies of s numbering from 0 to its length, in a single list.
init$
Removes the empty string, produces from the suffix of length 0.
f s=
Declares the function.
Python 2, 69 68 bytes
f=lambda s,A={''}:s in A and A or f(s,A|{a+c for a in A for c in s})
Outputs a set; includes the empty string.
Python 2, 71 bytes
f=lambda s,A=[]:s in A and A or f(s,set(s)|{a+c for a in A for c in s})
If empty string is not allowed...
Jelly, 2 bytes
ṗJ
A monadic Link which accepts a list of characters and returns a list of lists of lists of characters.
Try it online! (footer formats as a grid)
How?
ṗJ - list, S
J - range of length of S
ṗ - Cartesian power (vectorises)
If we must output a flat list of "strings" (lists of characters) we can add Ẏ (tighten) for the cost of a byte.
J, 16 bytes
a:-.~[:,#\{@#"{<
a:-.~Remove empty boxes from...[:,The flatten of...{@#"{The Catalog (cross prod) of{@...#\{@#"{<<The boxed input...#"{Copied this many times...#\1, 2, ... N, where N is the input length. That is, we copy the input once, then twice, ... then N times, taking the Catalog of each of those.
Perl 6, 32 bytes
{flat [\X~] '',|[xx] .comb xx 2}
Anonymous code block that takes a string and returns a list of string including the length zero permutation.
05AB1E, 6 bytes
gENIã)
Explanation
gENIã)
E # foreach in...
g # the input
ã # find the cartesian product of...
I # the input...
N # repeat N
) # wrap the final stack to an array
# implicit output of the top element
Python 3, 95 bytes
import itertools as i;lambda s:[''.join(p)for l in range(len(s))for p in i.product(s,repeat=l)]



