| Bytes | Lang | Time | Link |
|---|---|---|---|
| 047 | Raku Perl 6 rakudo | 241213T192605Z | xrs |
| 061 | AWK | 241213T190102Z | xrs |
| 013 | Uiua 0.8.0 | 231227T222601Z | Tbw |
| 115 | Scala | 231231T065600Z | 138 Aspe |
| 044 | JavaScript Node.js | 231219T004414Z | l4m2 |
| 026 | Ruby | 231221T115228Z | G B |
| 064 | Google Sheets | 231218T180831Z | doubleun |
| 037 | Bash + core utilities | 231221T003117Z | 0x2b3bfa |
| 050 | Python | 231220T225512Z | Karl Kne |
| 063 | Excel ms365 | 231220T094051Z | JvdV |
| nan | JavaScript ES6 | 231218T194630Z | Arnauld |
| 015 | APLDyalog Unicode | 231219T001451Z | Tbw |
| 006 | 05AB1E | 231219T150347Z | Kevin Cr |
| 009 | Charcoal | 231219T093853Z | Neil |
| 006 | Nekomata | 231219T063003Z | alephalp |
| 016 | Retina 0.8.2 | 231219T005521Z | Neil |
| 006 | Jelly | 231218T191921Z | Nick Ken |
| 007 | Jelly | 231218T191454Z | Jonathan |
| 054 | Python 3.8 prerelease | 231218T192259Z | spooky_s |
| 028 | Perl 5 p | 231218T185309Z | Xcali |
Raku (Perl 6) (rakudo), 47 bytes
{$_.subst(/[' '|B][' '|B]?/,"").comb.sort.join}
{$_.subst(/[' '|B][' '|B]?/,"") # get rid of a space or B
.comb # chars to array
.sort # sort
.join} # back together
AWK, 61 bytes
{sub(/B/,"");l=split($0,a,X);for(asort(a);i++<l;)printf a[i]}
{sub(/B/,""); # delete one B
l=split($0,a,X); # convert to array
for(asort(a) # sort it
;i++<l;) # til end of array
printf a[i]} # print char
Scala, 115 bytes
A Port of @spooky_simon's Python answer in Scala.
Golfed version. Attempt This Online!
def g(x:Boolean)=if(x)1 else 0
def f(s:String)={val x=s.contains("C");"A"*g(x)+"B"*g(s.count(_=='B')>1)+"CWY"*g(x)}
Ungolfed version. Attempt This Online!
object Main {
def main(args: Array[String]): Unit = {
def f(s: String): String = {
val hasC = s.contains("C")
val bCount = s.count(_ == 'B') > 1
("A" * (if (hasC) 1 else 0)) +
("B" * (if (bCount) 1 else 0)) +
("CWY" * (if (hasC) 1 else 0))
}
println(f("ABCWY B"))
println(f("ABCWY"))
println(f("B"))
println(f("B B"))
println(f("ACWY B B"))
println(f("ACWY B"))
}
}
JavaScript (Node.js), 44 bytes
s=>s.sort().filter(x=>!~(s[x]=~-s[x]),s.B=1)
JavaScript (Node.js), 49 bytes
s=>[...'ABCWY'].filter(x=>s.split(x)[x=='B'?2:1])
+4 bytes if a trailing delimited is not allowed.
Worse than Arnauld's solution (41, if it use no delimit and output array)
Google Sheets, 64 bytes
=join(,ifna(filter({"A","B","CWY"},search({"A","B*B","A"},A1))))
Put the input in cell A1 and the formula in cell B1.
Uses the search() with * wildcard method of JvdV's Excel answer.
The same can be done without arrays using simple string concatenation and regexes (81 bytes):
=let(a,regexmatch(A1,"A"),if(a,"A",)&if(regexmatch(A1,"B.*B"),"B",)&if(a,"CWY",)
Implementation of the same in JavaScript (62 bytes):
t=>(a=/A/.test(t)?'A':'')+(/B.*B/.test(t)?'B':'')+(a?'CWY':'')
(-4 bytes thanks to noodle man)
Bash + core utilities, 37 bytes
sed s/B//|grep -o .|sort -u|tr -d \\n
Explanation
sed s/B// | # remove the first occurrence of B
grep -o . | # insert a newline after every character
sort -u | # sort lines and remove duplicates
tr -d \\n | # remove newlines inserted for sorting
Python, 50 bytes
lambda s:''.join(sorted(set(s.replace('B','',1))))
Another port of @NickKennedy's answer, approximately. Python doesn't have a built-in multiset or corresponding set-difference operator; it does have collections.Counter, but that takes way too much setup. Instead, I just remove up to one B from the input before uniquifying and sorting (and producing a string from the resulting list). This works in both Python 2 and Python 3. The count argument for the replace method of strings is not commonly discussed, but it's clearly documented.
Excel ms365, 6463 bytes
New:
=CONCAT(IFERROR(MID(A1,SEARCH({"A","B*B","C"},A1),{1,1,3}),""))
Old:
=CONCAT(REPT({"A","B","CWY"},COUNTIF(A1,{"*A*","*B*B*","*A*"})))
JavaScript (ES6), 55 / 48 / 41 bytes
Expects a space-separated string.
s=>[...new Set(s.replace("B",""))].sort().join``.trim()
Or 48 bytes if we take a string with no delimiter.
Or 41 bytes if we return an array.
Method
Given the input string, e.g. "ABCWY ACWY B":
- remove the first "B" →
"ACWY ACWY B" - turn the string into a set →
Set { 'A','C','W','Y',' ','B' } - turn the set into an array →
[ 'A','C','W','Y',' ','B' ] - sort it in lexicographical order →
[ ' ','A','B','C','W','Y' ] - turn it back into a string →
" ABCWY" - remove the leading space, if any →
"ABCWY"
APL(Dyalog Unicode), 1715 bytes SBCS
⎕A∩⊢(/⍨)≠⍲'B'=⊢
A tacit function which takes a string on the right using no delimiter or any delimiter that is not a capital letter.
The test cases use spaces.
(The test case B is written as (⍬,'B') because single characters in quotes are not treated as strings in APL)
⎕A∩⊢(/⍨)≠⍲'B'=⊢
'B'=⊢ # Boolean mask for all Bs
⍲ # NAND
≠ # Boolean mask for all first instances
⊢(/⍨) # apply Boolean mask (removes first B)
∩ # intersection
⎕A # capital letter alphabet
💎
Created with the help of Luminespire.
Taking the intersection with the alphabet helpfully removes any delimiters and sorts alphabetically.
This solution doesn't work on any of the APL versions on TIO, as @att describes.
05AB1E, 6 bytes
'Bõ.;ê
Port of @NickKennedy's Jelly answer.
Try it online or verify all test cases.
Explanation:
.; # In the (implicit) input-string, replace the first
'B '# "B"
õ # with an empty string ""
ê # Then sort and uniquify the characters of the string
# (which is output implicitly)
Charcoal, 9 bytes
Φα›№θι⁼κ¹
Try it online! Link is to verbose version of code. Accepts any character that's not an uppercase letter as a delimiter (some characters may need extra quoting). Explanation:
α Predefined variable uppercase alphabet
Φ Filtered where
№ Count of
ι Current letter
θ In input string
› Is greater than
κ Current index
⁼ Equals
¹ Literal integer `1`
Implicitly print
Nekomata, 6 bytes
"B"∕uo
A port of @Nick Kennedy's Jelly answer.
"B"∕uo
"B"∕ Set difference with "B"
u Uniquify
o Sort
Retina 0.8.2, 16 bytes
\W
1`B
O`.
D`.
Try it online! Link includes test cases. Accepts any non-\w characters as a delimiter. Explanation:
\W
Join the words together.
1`B
Delete the first B, if any.
O`.
Sort the letters.
D`.
Deduplicate the letters.
Jelly, 6 bytes
œ-”BQṢ
A monadic link taking a string with no delimiter and returning a string.
Explanation
œ-”B | Set difference with "B"
Q | Uniquify
Ṣ | Sort
Jelly, 8 7 bytes
Note while I did eventually think of using œ- to avoid a byte, I now see that Nick Kennedy actually got there first!
Fœ-”BQṢ
A monadic Link that accepts a list of lists of characters (the vaccines) and yields a list of characters (the fully vaccinated).
Try it online! Or see the test-suite.
How?
Fœ-”BQṢ - Link: list of strings (from "B", "ACWY", "ABCWY"), Vaccinations
F - flatten
œ-”B - multiset difference with 'B'
Q - deduplicate
Ṣ - sort
Alternative TIO:
Taking a non [A-Z] separating string (like " " or ", ", etc):
œ-”BØAf
œ-”B - multiset difference with 'B'
ØAf - "ABC...XYZ" filter keep
Python 3.8 (pre-release), 54 bytes
lambda s:"A"*(x:="C"in s)+"B"*(s.count("B")>1)+"CWY"*x
Python 3, 59 bytes
def f(s):x="C"in s;return"A"*x+"B"*(s.count("B")>1)+"CWY"*x