How many characters are there on the icon of a Stack Exchange site?

19

1

Given the name of a Stack Exchange site which doesn't have their own design yet, decide how many ASCII characters (non-ASCII ones are counted separately) are there on their icons. Your code should distinguish these 4 cases:

1 character:

Astronomy
Beer
Freelancing
Health
History
Law
Music: Practice & Theory
Parenting
The Great Outdoors
Writers

2 characters:

3D Printing
Amateur Radio
Biblical Hermeneutics
Bitcoin
Board & Card Games
Buddhism
Chinese Language
Coffee
Community Building
Computational Science
Computer Graphics
Data Science
Earth Science
Ebooks
Economics
Emacs
Engineering
Expatriates
French Language
Gardening & Landscaping
Genealogy & Family History
German Language
Hardware Recommendations
Hinduism
Homebrewing
Islam
Italian Language
Japanese Language
Joomla
Lifehacks
Martial Arts
Mathematics Educators
Motor Vehicle Maintenance & Repair
Music Fans
Mythology
Open Data
Personal Productivity
Pets
Philosophy
Physical Fitness
Politics
Portuguese Language
Project Management
Puzzling
Quantitative Finance
Reverse Engineering
Robotics
Russian Language
Software Quality Assurance & Testing
Software Recommendations
Sound Design
Space Exploration
Spanish Language
Sports
Startups
Sustainable Living
Tridion
Vi and Vim
Video Production
Windows Phone
Woodworking
Worldbuilding

3 characters:

Cognitive Sciences
elementary OS
Ethereum
History of Science and Mathematics
Linguistics
Open Source
Programming Puzzles & Code Golf
Signal Processing
Tor

Non-ASCII:

Anime & Manga
Arduino
Aviation
Chess
CiviCRM
Poker

Excluded in this challenge for having non-ASCII characters in their names:

LEGO® Answers
Русский язык

Your code should output a consistent distinct value for each of the 4 sets. Each output (or its string representation for non-string values returned from a function) should be no more than 10 bytes, not counting the optional trailing newline.

You can create multiple pieces of code in the same language. The output of your submission is considered to be the output of each piece of code concatenated in a fixed order (so you can use Regex).

Shortest code wins.

jimmy23013

Posted 2016-03-03T12:05:29.213

Reputation: 34 042

This seams like regex golf – HEGX64 – 2016-03-03T12:33:58.733

Or could be image analysis using the favicon, given that "Anime and Manga" has a Japanese character in that logo - hence being on the "Non-ASCII" list. – Chris J – 2016-03-03T12:50:38.693

@ChrisJ You are not supposed to access Internet for the purpose of this challenge. That might be another question... – jimmy23013 – 2016-03-03T12:59:59.807

The character on Anime & Manga is obviously a . But it's not easy to argue whether the thing on Aviation is a . So I decided to follow the easiest way. – jimmy23013 – 2016-03-03T13:13:59.107

So we input the name and output the amount of ascii characters? – GamrCorps – 2016-03-03T13:16:38.510

@GamrCorps Basically yes. You can also output something else that has no more than 6 characters, as long as each identifies one group. – jimmy23013 – 2016-03-03T13:18:23.503

What defined as 6 characters in the return? For example, what if I return undefined (the value) or an [0,0,0] (array) in JavaScript? – Mwr247 – 2016-03-03T16:07:48.890

The LEGO® Answers shouldn't be excluded, since all characters are present in the Extended ASCII supersets. One of them is the (currently, the most comon single-byte encoding) ISO-8859-1 which is also known as Latin-1 and is the default for MySQL. In that encoding, it is the character ® has the decimal code 174.

– Ismael Miguel – 2016-03-03T18:06:00.333

@Mwr247 I didn't think of that. I'm considering also allowing values stored with less than k bytes internally, and relax k to 8 or 10. But the problem is we don't know how a value exactly is stored internally in many languages. So I'm not sure it fixes the problem. The purpose was to not encourage printing a lot of temporary data. – jimmy23013 – 2016-03-03T19:00:46.687

That is a tough one to figure out... Perhaps relax it, but make the phrasing more like: "The output, when stringified, should be no longer than X characters." – Mwr247 – 2016-03-03T19:45:16.987

I knew SQA had a long official name, but I didn't realize it was the longest name out there... wow... – corsiKa – 2016-03-03T20:47:50.257

Answers

6

CJam, 50 48 45 bytes

l22b391"þÁ "+{i%}/"Yª>Þÿ9cîÂcVáòe~"322b4b=

There's unprintable characters in the strings above, which can be obtained by the snippets

[254 193 160]:c
[89 170 62 222 30 255 20 57 99 238 194 99 86 225 242 101 126 20]:c

This also shows that the code points are all below 256. Output is 0 for 1 letter, 1 for 2 letters, 2 for 3 letters and 3 for non-ASCII.

The program simply converts the input string to a base 22 number, performs a series of modulos to reduce the number down, before performing a lookup from a base-4 encoded table.

Try it online | Test suite

Sp3000

Posted 2016-03-03T12:05:29.213

Reputation: 58 729

1

You lie! Open Source has 3 letters! How could you do this to my site! I'm... I'm... I'm heartbroken!

– Zizouz212 – 2016-03-04T01:10:59.040

@Zizouz212 The 0123 outputs don't correspond to the number of letters each. By "respectively" I was referring to the order listed in the OP, so 0 is 1 letter, 1 is 2 letters, 2 is 3 letters and 3 is non-ASCII. Confusing, yes, but it was the golfiest output choice. – Sp3000 – 2016-03-04T03:00:43.307

4

Retina, 146 136 134 130 124 107 102 bytes

A\w*i|Che|CR|ke
4
my|Be|lan|^H.*y$|lt|aw|:|Pa|Ou|Wr
1
gn.|^e|Et|^H.*S|gui|rc|lf|To
2
.*(\d).*
$1
..+
3

Thanks @Sp3000 for golfing off 4 bytes!
Thanks @Mwr247 for golfing off 17 bytes by letting me use regexes from his answer!
Thanks @jimmy23013 for golfing off 5 bytes by reminding me that I can change output values!

The output is 1, 3, 2, and 4 for 1-char, 2-char, 3-char, and non-ASCII, respectively.

Version with all testcases has edits in few places to make it work with multiple lines.

Try it online!
Try it online with all testcases!

daavko

Posted 2016-03-03T12:05:29.213

Reputation: 824

@Sp3000 Oh...yeah, thanks! Didn't notice that. That's what happens when you type too fast and don't check it properly afterwards, I guess. I can even i?(ni|vi) -> [nv]?i now. – daavko – 2016-03-03T15:22:06.940

1I have some pretty compact regexes in my JS answer. Feel free to use them if they'll help ;) – Mwr247 – 2016-03-03T16:18:05.623

1@Mwr247 Thanks, I think I'll use them. – daavko – 2016-03-03T17:35:06.803

1I think you can output 3 for 2-char to get rid of the (?!D). – jimmy23013 – 2016-03-03T19:03:49.387

@jimmy23013 That makes sense... I somehow forgot I can move the output values around. – daavko – 2016-03-03T19:10:06.773

@jimmy23013 Yeah, that's also true now. (EDIT: Not even all 5, first 3 seems enough EDIT2: now) Before it was a bit broken by that 3D Printing. Silly me doesn't remember rules of the challenge for too long. – daavko – 2016-03-03T19:16:44.697

You lie too! Open Source has 3 letters! I can feel my heart falling from the sky! – Zizouz212 – 2016-03-04T01:11:41.793

@Zizouz212 The output is 2 for 3-char and 3 for 2-char. It's confusing, I know, but it's shorter this way. Your heart needn't fall, for I'd never commit treason against Open Source. – daavko – 2016-03-04T06:56:18.583

2

Javscript ES6, 342 339 330 327 bytes

a=>{for(c of "9As4BebFr6He7Hi3LaoMu9PaiTh7Wrzb3DdAmlBi7BiiBo8BugCh6CoiColCohCocDadEa6Eb9Ec5EmbEnbExfFrnGaqGefGeoHa8HibHo5IsgIthJa6Jo9LicMalMayMoaMu9My9OplPe4PeaPhgPh8PojPoiPr8PukQujRe8RogRu10SooSocSohSpgSp6Sp8StiSu7TraVigVidWibWodWoziCodel8EtyHibLibOpvPrhSi3To".split`z`)if(~c.indexOf(a.length.toString(36)+a[0]+a[1]))return c}

Returns a long string starting with 9 for one character, a different long string starting with b for two, a third string starting withi for three, and simply undefined for non-ascii.

SuperJedi224

Posted 2016-03-03T12:05:29.213

Reputation: 11 342

Is there anywhere to test it out? I've detected a series of acts of treason against Open Source... – Zizouz212 – 2016-03-04T01:12:19.050

@Zizouz212 here's a fiddle: https://jsfiddle.net/fpt60bpg/

– SuperJedi224 – 2016-03-04T01:14:07.817

Is it just me, or can I not make it work? – Zizouz212 – 2016-03-04T01:20:17.290

It seems to be working for me. – SuperJedi224 – 2016-03-04T01:33:30.333

1

PowerShell, 212 181 bytes

$a=-join$args[0][0,2,-1];$b="Aty,Ber,Feg,Hah,Hsy,Lww,Msy,Prg,Tes,Wis,Cgs,eeS,Ehm,Hss,Lns,Oee,Pof,Sgg,Trr,Aia,Ado,Ain,Ces,CvM,Pkr".IndexOf($a);(((1,3)[$b-ge40],4)[$b-ge76],2)[$b-lt0]

I found that if you take the first, third, and last characters of each of the possible entries ([0,2,-1] when zero-indexed), we obtain a unique three-letter string for each entry. We then are simply using a string-based lookup to determine which one we have.

Takes input $args[0], and applies the above unique-ness function, saves as $a.

This is then sent through our lookup list via .IndexOf($a) and the result stored in $b. Then, we go through a pseudo-ternary that indexes based on the value of $b to output the appropriate value.

Outputs 1, 2, 3, and 4 for one-character, two-character, three-character, non-ASCII, respectively.

Edit - discovered that [0,2,-1] creates a unique three-character string for each entry, saving 31 bytes

AdmBorkBork

Posted 2016-03-03T12:05:29.213

Reputation: 41 581

2I see that you've got "coffee" hardcoded. My brain does, too. – dotancohen – 2016-03-03T14:51:27.447

Is there a place where I can test it out? – Zizouz212 – 2016-03-04T01:20:39.543

@Zizouz212 Any Windows computer. There's also this, but it doesn't seem to be working and apparently it's PASH, not PowerShell proper.

– Bob – 2016-03-04T03:17:26.807

@Zizouz212 PowerShell is pseudo-proprietary, in that it's Windows-only. There are free ways to install virtualized Windows (evaluation versions, developer editions, etc.) if you're a FOSS user. PASH is an open-source blend of PowerShell and BASH, but it's reverse-engineered rather than direct, and only implements about 40% of the PowerShell v1 features, so it is rather limited.

– AdmBorkBork – 2016-03-04T13:28:48.530

1

JavaScript (ES6), 108 bytes

a=>[/A\w*i|Che|CR|ke/,/my|Be|lan|^H.*y$|lt|aw|:|Pa|Ou|Wr/,/gn.|^e|Et|^H.*S|gui|rc|lf|To/].map(b=>+b.test(a))

Creates an array composed of regex matches unique to each of the three smallest groups (1 character, 3 character, and non-ascii), then maps a test on the data for each array. When the output is stringified, it evaluates to 1,0,0 for non-ascii, 0,1,0 for 3 characters, 0,0,1 for 1 character, and 0,0,0 for 2 characters.

Mwr247

Posted 2016-03-03T12:05:29.213

Reputation: 3 494