19
\$\begingroup\$

Challenge

Given a quark composition of a particle as input, output the corresponding hadron's name.

Quarks will be represented by a capital letter and antiquarks by a lowercase letter.

The quarks may be in any order, not necessarily the order given below.

Built-in functions the access data about particles and/or quarks are disallowed.

The only quarks you will be given are U (up), u (antiup), D (down), d (antidown), S (strange), s (antistrange), C (charm), c (anticharm), B (bottom or beauty), b(antibottom or antibeauty).

List of Hadrons and their quark compositions

Note that although there are various other hadrons such as pentaquarks and glueballs etc., you only need to support the hadrons given in the following lists

Baryons (QQQ) and Antibaryons (qqq)

The names in brackets are alternative names for the particles. You may output either name.

Input - Output

UUU - delta++
uuu - antidelta++
UUD - delta+ (proton)
uud - antidelta+ (antiproton)
UDD - delta0 (neutron)
udd - antidelta0 (antineutron)
DDD - delta-
ddd - antidelta-
UUS - sigma+
uus - antisigma+
UDS - sigma0
uds - antisigma0
DDS - sigma-
dds - antisigma-
USS - xi0
uss - antixi0
DSS - xi-
dss - antixi-
SSS - omega-
sss - antiomega-

UUC - charmed sigma++
uuc - charmed antisigma++
UDC - charmed sigma+
udc - charmed antisigma+
DDC - charmed sigma0
ddc - charmed antisigma0
UUB - bottom sigma+
uub - bottom antisigma+
UDB - bottom sigma0
udb - bottom antisigma0
DDB - bottom sigma-
ddb - bottom antisigma-
USC - charmed xi+
usc - charmed antixi+
DSC - charmed xi0
dsc - charmed antixi0
UCC - double charmed xi++
ucc - double charmed antixi++
DCC - double charmed xi+
dcc - double charmed antixi+
USB - bottom xi0
usb - bottom antixi0
DSB - bottom xi-
dsb - bottom antixi-
UBB - double bottom xi0
ubb - double bottom antixi0
DBB - double bottom xi-
dbb - double bottom antixi-
UCB - charmed bottom xi+
ucb - charmed bottom antixi+
DCB - charmed bottom xi0
dcb - charmed bottom antixi0
SSC - charmed omega0
ssc - charmed antiomega0
SSB - bottom omega-
ssb - bottom antiomega-
SCC - double charmed omega+
scc - double charmed antiomega+
SCB - charmed bottom omega0
scb - charmed bottom antiomega0
SBB - double bottom omega-
sbb - double bottom antiomega-
CCB - double charmed bottom omega+
ccb - double charmed bottom antiomega+
CBB - charmed double bottom omega0
cbb - charmed double bottom antiomega0
CCC - triple charmed omega++
ccc - triple charmed antiomega++
BBB - triple bottom omega-
bbb - triple bottom antiomega-

Mesons (Qq)

Input - Output

Ud - pion+
Uu - pion0
Dd - pion0
Du - pion-
Us - kaon+
Ds - kaon0
Sd - antikaon0
Su - kaon-
Ss - phion0
Cd - D meson+
Dc - D meson-
Cu - D meson0
Uc - antiD meson0
Cs - strange D meson+
Sc - strange D meson-
Cc - psion0
Bu - B meson-
Ub - B meson+
Db - B meson0
Bd - antiB meson0
Sb - strange B meson0
Bs - strange antiB meson0
Bb - upsilon0

Winning

Shortest code in bytes wins.

\$\endgroup\$
  • 11
    \$\begingroup\$ Built-in functions the access data about particles and/or quarks are disallowed. I'm looking at you, Mathematica. \$\endgroup\$ – Okx May 14 '17 at 14:42
  • \$\begingroup\$ So, this challenge is essentially to compress aa look up table? \$\endgroup\$ – Rohan Jhunjhunwala May 14 '17 at 15:32
  • 3
    \$\begingroup\$ Mathematica does have a ParticleData function with a QuarkContent option. \$\endgroup\$ – Ian Miller May 14 '17 at 15:36
  • 1
    \$\begingroup\$ Doesn't look hard. I mean, each quark has its own electric charge, you only have to handle the name, not the charge. \$\endgroup\$ – Matthew Roh May 14 '17 at 17:39
  • 1
    \$\begingroup\$ 1. It seems the baryons can be any combination of 3 quarks of the same case. Mesons are combinations of 2 quarks of opposite case, but for mesons Cb and Bc are missing. Is this intentional? 2. Ordering the letters differently would mean the same thing - must our program be able to handle different orders of letters, or will they always be ordered as shown? (i.e. will it always be UDS for example or could it be SUD or DSU for example?) Similarly for mesons could we have uD? \$\endgroup\$ – Level River St May 15 '17 at 0:56
5
\$\begingroup\$

SOGL 0.11, 341 339 333 310 305 305 300 bytes

‘θw±
on”≥
0c{≤
”=?"▒
on0”←"█
c SW?"▲
?ļ0←j ►
?"anti”o}▼
SD”;W¡+}□
=?ļ-←ļ+←■
‘B≤a=+}:?"⁽¬Τk⅜K±l?@+}ob@+o}▓
UCl2-? CA"K¼⁶▓ BA"δ╬▓cd≠▼≤: U=; D=++}"8}↕x╔:⁵F┘¹±o≤"B□"κ§)Ƨ7%s±p←"Ss▒phi█Cc▒psi█Bb▒upsil█SdUcBd”2n{=▼}≤"U□1>?▲ka≥pc DW►S■"pi≥Pcρ►D■▲)»β⁴‘o}ƧBs=▼ Dc BW?X B}" mes≥+p"D═S┐╔¬ν↑FνF⌠V3╗βstA\≈²‘:cW2+Wp
\$\endgroup\$
12
\$\begingroup\$

JavaScript (ES6), 456 448 431 420 bytes

This code is using only two small lookup tables:

  • one to identify the quarks: 'CUBDScubds'
  • another one to detect the 'anti' prefix of Mesons: 'SdUcBdBs'

Everything else is deduced from the quarks.

(s,[a,b]=[...s].map(c=>(i='CUBDScubds'.search(c)%5,m|=1<<i,j+=i<2,k+=i&1,p+=i?i-2?'':'bottom ':'charmed ',i),m=j=k=0,p=''))=>s[2]?p.replace(/(\w+) \1( \1)?/,(_,a,b)=>b?'triple'+b:'double '+a)+(s>'Z'?'anti':'')+['omega','xi','sigma','delta'][k]+('-0+'[j]||'++'):(m&16&&m&5?'strange ':'')+(~'SdUcBdBs'.search(s)?'anti':'')+(m&1?m^1?'D mes':'psi':m&4?m^4?'B mes':'upsil':m&16?m^16?'ka':'phi':'pi')+'on'+'-0+'[(a<2)-(b<2)+1]

let f =

(s,[a,b]=[...s].map(c=>(i='CUBDScubds'.search(c)%5,m|=1<<i,j+=i<2,k+=i&1,p+=i?i-2?'':'bottom ':'charmed ',i),m=j=k=0,p=''))=>s[2]?p.replace(/(\w+) \1( \1)?/,(_,a,b)=>b?'triple'+b:'double '+a)+(s>'Z'?'anti':'')+['omega','xi','sigma','delta'][k]+('-0+'[j]||'++'):(m&16&&m&5?'strange ':'')+(~'SdUcBdBs'.search(s)?'anti':'')+(m&1?m^1?'D mes':'psi':m&4?m^4?'B mes':'upsil':m&16?m^16?'ka':'phi':'pi')+'on'+'-0+'[(a<2)-(b<2)+1]

res = [
  "UUU", "uuu", "UUD", "uud", "UDD", "udd", "DDD", "ddd", "UUS", "uus", "UDS", "uds", "DDS", "dds", "USS", "uss",
  "DSS", "dss", "SSS", "sss", "UUC", "uuc", "UDC", "udc", "DDC", "ddc", "UUB", "uub", "UDB", "udb", "DDB", "ddb",
  "USC", "usc", "DSC", "dsc", "UCC", "ucc", "DCC", "dcc", "USB", "usb", "DSB", "dsb", "UBB", "ubb", "DBB", "dbb",
  "UCB", "ucb", "DCB", "dcb", "SSC", "ssc", "SSB", "ssb", "SCC", "scc", "SCB", "scb", "SBB", "sbb", "CCB", "ccb",
  "CBB", "cbb", "CCC", "ccc", "BBB", "bbb", "Ud",  "Uu",  "Dd",  "Du",  "Us",  "Ds",  "Sd",  "Su",  "Ss",  "Cd",
  "Dc",  "Cu",  "Uc",  "Cs",  "Sc",  "Cc",  "Bu",  "Ub",  "Db",  "Bd",  "Sb",  "Bs",  "Bb"
]
.map(s => s + ' - ' + f(s)).join("\n");

console.log(res);

\$\endgroup\$
2
\$\begingroup\$

Perl 5, 318 bytes

$_=<>;$h=qw/- ++ + 0/[y/uc//*2*($i=3-map{${lc;}++}/./g)-$u-$c-$i];$a=($i?!$h&&/[dUB]/:/[a-z]/)&&anti;map{/(.)/;$q.=("","$_ ","double $_ ","triple $_ ")[$$1]}charmed,bottom;print(($i?($u+$d>1?pi:$s>1?phi:$c>1?psi:$b>1?upsil:$c+$b?($s?"strange $a":$a).($b?B:D).' mes':$a.ka).on:$q.$a.qw/omega xi sigma delta/[$u+$d]).$h)

Newlines added for readability (slightly):

$_=<>
$h=qw/- ++ + 0/[y/uc//*2*($i=3-map{${lc;}++}/./g)-$u-$c-$i]
$a=($i?!$h&&/[dUB]/:/[a-z]/)&&anti
map{/(.)/;$q.=("","$_ ","double $_ ","triple $_ ")[$$1]}charmed,bottom;
print(($i?($u+$d>1?pi:$s>1?phi:$c>1?psi:$b>1?upsil:$c+$b?($s?"strange $a":$a).($b?B:D).' mes':$a.ka).on:$q.$a.qw/omega xi sigma delta/[$u+$d]).$h)
\$\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.