21
\$\begingroup\$

Help! My Completely Automated Lights From Darks Separator V3001.01 broke! :(

Guidelines


Task

Write a program that will take an input of an array (or a list in some languages) of any amount of strings that are either the letter L or the letter D (representing lights or darks) and output an array that contains two arrays, one with all the L's, and one with all the D's.


Rules

  • It's code golf so the shortest answer in bytes wins
  • Input will only ever contain capitals
  • There must be the same number of L's in the output as there is in the input, same goes for the D's
  • The input may only have one element (or maybe even zero elements)
  • If one or both of the output arrays contain no elements, output an empty list (in some languages this may mean you need to output a string)
  • Always have the first array be the array of L's

Example output:

["L","D","L","D","D"] -> [["L","L"],["D","D","D"]]

["L","L","L"] -> [["L","L","L"],[]]

["D","D"] -> [[],["D","D"]]

[] -> [[],[]]

\$\endgroup\$
  • 3
    \$\begingroup\$ Can we input/output as a string? For example: "LDLDD" -> "LL DDD" or something like that? \$\endgroup\$ – Comrade SparklePony Jul 11 '17 at 4:54
  • 3
    \$\begingroup\$ Or output perhaps as a list of the two strings, e.g. `"LDLDD" -> ["LL", "DDD"] \$\endgroup\$ – Comrade SparklePony Jul 11 '17 at 7:27
  • \$\begingroup\$ Would also like an answer, as my answer depends on this \$\endgroup\$ – Skidsdev Jul 11 '17 at 8:46
  • \$\begingroup\$ How about mixed output? As in an array containing one string and one array of strings? e.g., ["L","L",["D","D","D"]]. \$\endgroup\$ – Shaggy Jul 11 '17 at 8:59
  • \$\begingroup\$ No, the output must be an array/list. @ComradeSparklePony \$\endgroup\$ – Amorris Jul 11 '17 at 9:04

34 Answers 34

0
\$\begingroup\$

J, 13 bytes

<@-."1 0&'DL'

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Javascript, 38 bytes

q=>['L','D'].map(x=>q.filter(y=>x==y))
\$\endgroup\$
  • 2
    \$\begingroup\$ Hello and welcome to the site! We do not allow answers that assume a variable as input, we call these snippets. Instead format your answer as a function (named on unnamed), or a full program with IO. \$\endgroup\$ – Wheat Wizard Oct 2 '17 at 6:47
  • \$\begingroup\$ Thanks @FunkyComputerMan. I edited it, let me know if it is correct. \$\endgroup\$ – Coert Grobbelaar Oct 2 '17 at 11:10
0
\$\begingroup\$

Retina, 21 11 bytes

-10 bytes thanks to CalculatorFeline

O^`.
LD
L D

Try it online!

\$\endgroup\$
  • \$\begingroup\$ The 21 byte version can be O^`. LD L D. \$\endgroup\$ – CalculatorFeline Jul 12 '17 at 3:02
0
\$\begingroup\$

Ruby, 20 bytes

->l{[l-[?D],l-[?L]]}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.