| Bytes | Lang | Time | Link |
|---|---|---|---|
| 050 | AWK | 241106T201239Z | xrs |
| 019 | Ruby | 180111T143908Z | G B |
| 008 | Uiua | 241023T011203Z | nyxbird |
| 008 | Japt | 170711T101848Z | Shaggy |
| 6625 | Vyxal | 230819T133138Z | lyxal |
| 008 | Thunno 2 | 230818T144306Z | The Thon |
| 011 | Retina | 170711T184114Z | ovs |
| 038 | Javascript | 171002T063626Z | Coert Gr |
| 013 | J | 171002T075507Z | FrownyFr |
| 070 | Perl 5 | 170805T042243Z | Xcali |
| 037 | Prolog SWI | 170711T070447Z | Tessella |
| 026 | Julia | 170712T041031Z | Tanj |
| 014 | CJam | 170716T043508Z | Esolangi |
| 018 | Mathematica | 170712T025628Z | Not a tr |
| 048 | Racket | 170711T201102Z | Majora32 |
| 035 | R | 170711T175406Z | Giuseppe |
| 021 | Octave | 170711T165220Z | beaker |
| 026 | Ruby | 170711T142010Z | Kaia Lea |
| 106 | Java 8 | 170711T073334Z | Kevin Cr |
| 065 | Common Lisp | 170711T073415Z | Renzo |
| 007 | Husk | 170711T131705Z | Leo |
| 021 | Perse | 170711T131146Z | faso |
| 045 | PHP7 | 170711T094348Z | Ezenhis |
| 010 | Jelly | 170711T094257Z | Erik the |
| 037 | F# | 170711T092828Z | user2015 |
| 061 | C# | 170711T083748Z | TheLetha |
| 027 | PowerShell | 170711T061720Z | Tessella |
| 028 | Haskell | 170711T072700Z | xnor |
| 037 | Javascript ES6 | 170711T071334Z | Endenite |
| 008 | 05AB1E | 170711T060821Z | kalsower |
| 032 | Haskell | 170711T050202Z | nimi |
| 046 | PHP | 170711T040018Z | ScottMcG |
| 041 | Haskell Lambdabot | 170711T033635Z | ბიმო |
| 027 | Mathematica | 170711T032737Z | Greg Mar |
| 009 | Pyth | 170711T032805Z | Leaky Nu |
| 008 | APL | 170711T032819Z | marinus |
| 037 | Python 3 | 170711T032303Z | Leaky Nu |
Uiua, 8 bytes
⊃↘↙⊸⊗@L⍆
Takes input as a string (array of characters), and outputs as two strings.
⍆ sort, then ⊃↘↙ split (reversed) ⊸ by the ⊗ indexof L.
Japt, 13 12 10 8 bytes
"DL"£kX
"DL"£kX :Implicit input of array U
"DL" :Literal string
¬ :Split
£ :Map each X
kX : Remove all occurrences of X from U
Vyxal, 53 bitsv2, 6.625 bytes
‛LDƛ?Oẋf
Ports Thonnu 2
Explained
‛LDƛ?Oẋf
‛LDƛ # To each character in the string "LD":
?O # Count the character in the input
ẋ # And list repeat it that many times
f # flatten that
💎
Created with the help of Luminespire.
Thunno 2, 8 bytes
`LDdẊcx×
Explanation
`LDdẊcx× # Implicit input -> ["L","D","L","D","D"]
`LD # Push the string "LD" -> ["L","D","L","D","D"] "LD"
d # Split it into characters -> ["L","D","L","D","D"] ["L","D"]
Ẋ # Store it in x without popping -> ["L","D","L","D","D"] ["L","D"]
c # Count occurrences in the input -> [2,3]
x× # Multiply by x elementwise -> [["L","L"],["D","D","D"]]
# Implicit output
Javascript, 38 bytes
q=>['L','D'].map(x=>q.filter(y=>x==y))
Perl 5, 70 bytes
$"='","';@L=(L)x y/L//;@D=(D)x y/D//;$_="[[\"@L\"],[\"@D\"]]";s/""//g
Prolog (SWI), 42, 37 bytes
l('L').
w(L,D,W):-partition(l,W,L,D).
Given that W is a list of washing, w/3 will unify L and D into lists of Lights and Darks respectively, by partitioning the washing against a predicate which succeeds if an item is a Light.
[Edit: golfed -5 thanks to Fatalize]
Julia, 26 bytes
g(s)=s[s.=="L"],s[s.=="D"]
CJam, 14 bytes
"LD"qf{1$e=*}`
Input is a list of characters (string), output is a list of lists of characters (list of strings).
Explanation:
"LD" e# Push the string "LD" | "LD"
q e# Push the input | "LD" "LDLLDLDDL"
f{ e# Foreach char in "LD", push input and: | ['L "LDLLDLDDL"
1$ e# Copy from 1 back | ['L "LDLLDLDDL" 'L
e= e# Count occurences | ['L 5
* e# Repeat character | ["LLLLL"
} e# End | ["LLLLL" "DDDD"]
` e# Stringify: | "[\"LLLLL\" \"DDDD\"]"
e# Implicit output: ["LLLLL" "DDDD"]
Mathematica, 22 18 bytes
4 bytes saved by the genius of CalculatorFeline!
Cases@@@{#|L,#|D}&
Try it online, or at the Wolfram sandbox!
Input is a list of the symbols L and D — not strings, just the letters on their own, like in Greg Martin's answer. The syntax #|L is shorthand for Alternatives[#,L], but the @@@ syntax replaces the head Alternatives with Cases, so this code is equivalent to {Cases[#,L],Cases[#,D]}&.
Racket, 48 bytes
(compose list((curry partition)(λ(x)(eq? x'L))))
Just apply this anonymous function to, e.g., '(L D L D D L)
Octave, 21 bytes
@(A){A(a=A>72),A(~a)}
Input is an array of characters, output is a cell array. Recycled from my answer here.
Sample execution on ideone.
Java 8, 110 106 bytes
a->{String[]r={"",""};for(char c:a)r[c/69]+=c;return new char[][]{r[1].toCharArray(),r[0].toCharArray()};}
-4 bytes thanks to @Nevay.
Explanation:
a->{ // Method with char-array parameter and 2D char-array return-type
String[]r={"",""}; // Two Strings in an array
for(char c:a) // Loop over the characters of the input
r[c/69]+=c; // Append either of the two String with the character
// c/69 will result in 0 for 'D' and 1 for 'L'
// End of loop (implicit / single-line body)
return new char[][]{ // Return a 2D character-array
r[1].toCharArray(), // With the String for L's converted to a char-array
r[0].toCharArray()}; // and String D's converted to a char-array
} // End of method
Common Lisp, 66 65 bytes
(defun f(x)`(,(remove"D"x :test'equal),(remove"L"x :test'equal)))
If, instead of strings, we use symbols, then it is much shorter:
Common Lisp, 42 41 40 bytes
(defun f(x)(mapcar'remove'(D L)`(,x,x)))
(f '(D D L L D L D)) ; => ((L L L) (D D D D))
Husk, 7 bytes
Mof-"DL
Explanation
Mof-"DL
M "DL For each character in ['D','L']:
of- keep only those strings that are not empty if that character is removed
Perse, 21 bytes
part(i,fn(x){x=="L"})
I may or may not have implemented the list partition function specifically for this challenge. Takes the input as an array of strings.
PHP7, 52 45 bytes
-7 bytes thanks to @Jörg Hülsermann
foreach($argv as$a)$$a[]=$a;print_r([$L,$D]);
Use with CLI as php -r a.php L L L D D L D
The script goes through the provided arguments and appends them to an array based on its value.
Jelly, 10 bytes
ẎfЀ⁾LDW€€
In Jelly a string is a list of 1-char Python strings, e.g. ['a', 'b', 'c']. That's why you get output such as [[['L'], ['L']], [['D'], ['D'], ['D']]], since 1-char Jelly strings behave the same.
Doesn't work as a full program, hence the ÇŒṘ at the bottom.
F#, 37 bytes
let f s=List.partition(fun a->a="L")s
Takes input as a list of strings, and returns two lists, the first with elements where fun a -> a="L" is true and the other with elements that result in false.
C#, 61 bytes
using System.Linq;a=>new[]{a.Where(c=>c<69),a.Where(c=>c>68)}
Full/Formatted Version:
using System;
using System.Linq;
class P
{
static void Main()
{
Func<char[], System.Collections.Generic.IEnumerable<char>[]> f =
a => new[] { a.Where(c => c < 69), a.Where(c => c > 68) };
Console.WriteLine(string.Join(", ", f(new[]{ 'L', 'D', 'L', 'D', 'D' }).SelectMany(a => a.Select(c => c))));
Console.ReadLine();
}
}
PowerShell, 27 bytes
($args-eq'L'),($args-eq'D')
Edit: previously $args.where({$_-eq'L'},'sp') for 28 bytes. Could be $args.where({+"0x$_"},'sp') for 27 if not for the rule that L's must come first.
Haskell, 28 bytes
f l=[filter(==[c])l|c<-"LD"]
If the input can be a list of characters, the [] around c can be removed.
Javascript (ES6), 37 bytes
This is based on a (now deleted) Javascript (ES6) answer.
a=>[(b=c=>a.filter(d=>c==d))`L`,b`D`]
Ungolfed version:
function(array) {
function filter(character){
return array.filter(function(d) {
return character == d;
});
}
return [filter("L"), filter("D")];
}
Example code snippet:
f=
a=>[(b=c=>a.filter(d=>c==d))`L`,b`D`]
console.log(f(["L", "D", "L", "D", "D"]))
PHP, 46 bytes
Assumed given list is:
$arr = ['L','L','D','D','L','D','D','D','D','L'];
foreach($arr as $b){$a[$b][]=$b;};print_r($a);
Mathematica, 27 bytes
Rest/@Gather[{L,D}~Join~#]&
Pure function taking a list of Ls and Ds (symbols, not characters/strings) as input and returning a list of two lists. For example,
Rest/@Gather[{L,D}~Join~#]& @ {D, L, L, D, L}
returns {{L, L, L}, {D, D}}. Try it online!
Gather by itself is close to what we want, but fails to meet the spec in two ways: it doesn't produce empty lists if the input is missing Ls or Ds, and it doesn't always sort Ls to the left. Replacing the input # with {L,D}~Join~# solves both problems at once: it means there will be at least one L and at least one D, and the Ls will be returned first since an L was encountered first. Rest/@ then removes the initial L and D.
(I tried a solution using Count, but due to currying issues, it didn't seem to be shorter: ±q_:=#~Table~Count[q,#]&/@{L,D} is 31 bytes.)
APL, 8 bytes
'DL'~⍨¨⊂
Explanation:
⊂: enclosed input~⍨¨: without each'DL': 'D' and 'L'
Examples:
('DL'~⍨¨⊂) 'LDLDD'
┌──┬───┐
│LL│DDD│
└──┴───┘
('DL'~⍨¨⊂) 'LLL'
┌───┬┐
│LLL││
└───┴┘
('DL'~⍨¨⊂) 'DD'
┌┬──┐
││DD│
└┴──┘
('DL'~⍨¨⊂) ''
┌┬┐
│││
└┴┘