New answers tagged

0

Excel (Ver. 1911), 199 Bytes Using iterative calculation (max iterations set to 1024) B2 'Input B3 =IF(B3=4^5,1,B3+1) B4 =B3-1 C2 =SEQUENCE(LEN(B2)) D2 =ROW(C2#:C1)-1 E2 =IF(B4,IF(C2#=B4,IF(F2#=">",@SORT(G2#,,-1),G2),E2#),-C2#) F2 =MID(B2,C2#,1) G2 =FILTER(D2#,NOT(MMULT(N(D2#=TRANSPOSE(E2#)),C2#/C2#))) H2 =CONCAT(E2#:F2#,G2) ' Output Explanation B2 '...


2

T-SQL, 267 bytes SQL queries was totally made to solve this type of question SELECT top 1WITH TIES x FROM(SELECT(SELECT a FROM(SELECT top 999substring(x,number+1,1)a,*FROM @,spt_values WHERE type='P'and number<len(x)ORDER BY a)c WHERE x=t.x for xml path(''),type).value('.','char(9)')v,x FROM @ t)z ORDER BY-count(*)over(PARTITION BY v),-len(x) Try it ...


0

Clojure, 54 bytes #(some val(sort-by(comp count val)>(group-by sort %))) Returns nil for empty input. Try it online!


1

J, 19 bytes 0({>\:#&>)/:~&></.] Try it online! -2 bytes thanks to FrownyFrog Similar approach to Grimmy's answer.


1

Python 2, 79 77 bytes lambda A,S=sorted:A and max([[y for y in A if S(x)==S(y)]for x in A],key=len) Try it online! 2 bytes thx to wilkben. The A and... is only required to deal with the empty input.


1

Perl 6, 36 bytes {max .classify(~*.comb.sort){*}||''} Try it online! Output an empty string for an empty input. If we could output something else, for example -Inf, then this could be: Perl 6, 31 bytes *.classify(~*.comb.sort){*}.max Try it online!


1

Japt -h, 6 5 bytes üñ ñl Try it üñ ñl :Implicit input of array ü :Sort & group by ñ : Sorted strings ñ :Sort by l : Length :Implicit output of last element


3

05AB1E, 6 bytes .¡{}éθ Try it online! .¡ } # group the input strings by: { # sort (all permutations of each other will be identical when sorted) é # sort the groups by length θ # output the last (longest) group


0

Keg, 8 bytes `.,:`:,. Try it online! A rearrangement of the usual quine.


1

W, 2 bytes 1- Explanation a % (Implicit) argument of the input % The input is automatically set to 0 % if it isn't specified 1- % Minus 1 over the input (i.e. 0-1 = -1) Output: -1


0

GolfScript, 8 bytes {}*{.*}. Output is {.*}{.*} Works because the first three characters are garbage to find a way to get another set of braces in the program that don't show up. If you don't care about whitespace, then {+}{.}+. outputs {+ .}{+ .}, which was my first attempt. Try it online!


0

Perl 5 -lF, 48 bytes $"=',';map$k{$_}++||say,glob"{@F}"."{@F,''}"x$#F Try it online!


1

Ruby, 60 bytes ->s{a,*z=s.chars,'';z.product(*a.map{a+z}).map(&:join)-z|[]} Try it online!


0

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,'')))))) Try it online! Things that make you go Argh, strings in R. Expands out to the following cat( # output the results unlist( # collapse the list ...


2

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.


2

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--))) Try it online! Commented s => new Set( // build a set from [...Array( // an array of n = // n entries, with: (L = -~s.length) // n = L ** (L - 1) ...


3

PowerShell, 42 bytes ($a=$args)|%{($p=$p|%{$t=$_;$a|%{$t+$_}})} Try it online. Expects input via splatting.


12

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 ...


2

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}) Try it online! 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}) Try it online! If empty string is not allowed...


6

Haskell, 34 bytes f s=init$mapM(\_->s)=<<scanr(:)[]s Try it online! 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 ...


3

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',';} Try it online! -4 bytes thanks to @Ismael Miguel. Method: simply count in base N, where N is the number of unique characters in the input string.


2

Burlesque,  5  4 bytes sacb Try it online! -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


7

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.


1

Pyth, 5 bytes ^LQSl Try it here!


3

J, 16 bytes a:-.~[:,#\{@#"{< Try it online! 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.


8

05AB1E, 4 3 bytes -1 byte thanks to a'_' ā€ã Try it online!


1

Perl 6, 32 bytes {flat [\X~] '',|[xx] .comb xx 2} Try it online! Anonymous code block that takes a string and returns a list of string including the length zero permutation.


5

05AB1E, 6 bytes gENIã) Try it online! 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


2

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)] Try it online


1

Pyth, 18 numbers 579 t Another challenge where being infix rather than prefix would be nice. This uses the space to "hide" some of the numbers and the decrement to get more numbers. Here's all of the outputs. [ 57 t9 ] => '57' [ 57t 9 ] => '57\n8' [ 59 t7 ] => '59' [ 59t 7 ] => '59\n6' [ 5 7t9 ] => '5\n8' [ 5 9t7 ] => '5\n6' [ 5 t79 ] =&...


Top 50 recent answers are included