Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
This seams like regex golf – HEGX64 Mar 3 at 12:33
    
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 Mar 3 at 12:50
    
@ChrisJ You are not supposed to access Internet for the purpose of this challenge. That might be another question... – jimmy23013 Mar 3 at 12:59
    
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 Mar 3 at 13:13
    
So we input the name and output the amount of ascii characters? – GamrCorps Mar 3 at 13:16
up vote 6 down vote accepted

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

share|improve this answer
1  
You lie! Open Source has 3 letters! How could you do this to my site! I'm... I'm... I'm heartbroken! – Zizouz212 Mar 4 at 1:10
    
@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 Mar 4 at 3:00

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!

share|improve this answer
    
@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 Mar 3 at 15:22
1  
I have some pretty compact regexes in my JS answer. Feel free to use them if they'll help ;) – Mwr247 Mar 3 at 16:18
1  
@Mwr247 Thanks, I think I'll use them. – daavko Mar 3 at 17:35
1  
I think you can output 3 for 2-char to get rid of the (?!D). – jimmy23013 Mar 3 at 19:03
    
@jimmy23013 That makes sense... I somehow forgot I can move the output values around. – daavko Mar 3 at 19:10

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.

share|improve this answer
    
Is there anywhere to test it out? I've detected a series of acts of treason against Open Source... – Zizouz212 Mar 4 at 1:12
    
@Zizouz212 here's a fiddle: jsfiddle.net/fpt60bpg – SuperJedi224 Mar 4 at 1:14
    
Is it just me, or can I not make it work? – Zizouz212 Mar 4 at 1:20
    
It seems to be working for me. – SuperJedi224 Mar 4 at 1:33

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

share|improve this answer
2  
I see that you've got "coffee" hardcoded. My brain does, too. – dotancohen Mar 3 at 14:51
    
Is there a place where I can test it out? – Zizouz212 Mar 4 at 1:20
    
@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 Mar 4 at 3:17
    
@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. – TimmyD Mar 4 at 13:28

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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