title: Creating a 16x16(NxN) grid

text:
# Question
Title: Creating a 16x16(NxN) grid
This is my first question in `Code golf` I found it in stack-overflow (originally in JavaScript however all languages are acceptable):

*Render on screen NxN (where N in range 1-16) grid where each cell have black boundary and red number inside - cells are numerated in hex starting from left-upper corner to bottom-right. Example output (for N=16) shows how result should looks like (font can be different than in picture):*

The image in text uri form (which works on major browsers) in output is also acceptable - a as example blow:

```
<img src="data:image/png;base64,[encoded data, 35788 characters]"/>
```

This is my (not optimised) attempt to this task

```
document.write('<style>.row { display: flex; font-size: 9.5px; text-align: center; color: red } .cell { width: 10px; height: 10px; margin: 1px; border: 1px solid black;}</style><div id="container"></div>')

let n=10, s='';

for(let i=0; i<n; i++) {
  s+= '<div class="row">'
  for(let j=0; j<n; j++) s+= `<div class="cell"> ${(i*n+j).toString(16)} </div>`;
  s+= '</div>'
}

container.innerHTML = s;
```

but I wonder how small code can produce similar effect?

# Answer
Could go smaller, but here's a quick one:

```
let n=10;container.innerHTML=(d='<div class="')+'grd" style="width:'+n*14+'px">'+[...Array(n*n)].reduce((a,b,i)=>a+d+'cell">'+i.toString(16)+(e='</div>'),'')+e;
```

```
.grd { display: inline-block; font-size: 9.5px; text-align: center; color: red;}
.cell { display:inline-block; width: 10px; height: 10px; margin: 1px; border: 1px solid black;}
```

```
<div id="container"></div>
```
> 4 votes

# Answer
# Red, 131 bytes

```
n: -1 view collect[loop 16[keep 'across
loop 16[keep compose[field 20x20 font-color red(to""to-hex/size n: n + 1 2)]]keep 'return]]

```

## If the leading zeroes need to be discarded:

# Red, 154 bytes

```
n: -1 view collect[loop 16[keep 'across
loop 16[s: to""to-hex/size n: n + 1 2 parse s[remove"0"]keep
compose[field 20x20 font-color red(s)]]keep 'return]]

```

Note: The first screenshot is taken on my Win 10 PC, the second one - on my Win 8.1 laptop, hence the difference.
> 3 votes

# Answer
# PowerShell, 319 bytes

```
-1..15|%{If($_-lt0){$s="┌──";0..14|%{$s=$s+"┬──"};Write-Host "$s┐";}Else{$i=$_;0..15|%{Write-Host "│"-NoNewline;Write-Host ("{0:X2}"-f($i*16+$_))-f 12 -NoNewline;};Write-Host "│";$s=("├","└")[$_-eq15]+"──";0..14|%{$s=$s+(("┼","┴")[$i-eq15]+"──")};Write-Host("$s┤","$s┘")[$_-eq15]}}

```

Screenshot of the output:

Only my second PowerShell answer, so can definitely be golfed substantially.. Also, is it possible to create and use an Alias for the `Write-Host`?

**Explanation:**

*TODO: Will add one later.*

The `X2` could be `x2` to format the hexadecimal as lowercase letters.
> 2 votes

# Answer
# Japt, ~~51~~ 49 bytes

Wrong tool for the job, but I got it working eventually with a little help from my solution to *Little Boxes on the Hillside*. The spec doesn't include any details on margins, padding & border width so this won't look *exactly* like the reference image.

```
G²ÇsG ici%Ãú òG
£OlX¬,$...$¡`Þ:so¦d #000;¬l:d

```

Test it (Open your browser's console)

If input *is* required then this should work for ~~50~~ 48 bytes.
> 2 votes

# Answer
# PHP, 157 bytes

```
<?php for(;$i++<$n=$_GET[n];)for(print'<p>';$$i++<$n;)echo'<x style="color:red;border:1px solid #000;display:inline-block;width:25px">'.dechex($x++).'</x> ';

```

This should be run as a webpage, not from CLI. Pass input as a URL query string named `n`. For example: `grid.php?n=16`

**Sample output for `n=8`:**

```
<p><x style="color:red;border:1px solid #000;display:inline-block;width:25px">0</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">1</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">2</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">3</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">4</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">5</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">6</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">7</x> <p><x style="color:red;border:1px solid #000;display:inline-block;width:25px">8</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">9</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">a</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">b</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">c</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">d</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">e</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">f</x> <p><x style="color:red;border:1px solid #000;display:inline-block;width:25px">10</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">11</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">12</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">13</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">14</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">15</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">16</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">17</x> <p><x style="color:red;border:1px solid #000;display:inline-block;width:25px">18</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">19</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">1a</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">1b</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">1c</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">1d</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">1e</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">1f</x> <p><x style="color:red;border:1px solid #000;display:inline-block;width:25px">20</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">21</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">22</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">23</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">24</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">25</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">26</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">27</x> <p><x style="color:red;border:1px solid #000;display:inline-block;width:25px">28</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">29</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">2a</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">2b</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">2c</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">2d</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">2e</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">2f</x> <p><x style="color:red;border:1px solid #000;display:inline-block;width:25px">30</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">31</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">32</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">33</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">34</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">35</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">36</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">37</x> <p><x style="color:red;border:1px solid #000;display:inline-block;width:25px">38</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">39</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">3a</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">3b</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">3c</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">3d</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">3e</x> <x style="color:red;border:1px solid #000;display:inline-block;width:25px">3f</x>
```

TIO link to get raw outputs (you have to save them as HTML to see the result): Try it online!
> 1 votes

# Answer
# JavaScript (web browser console), 160 bytes

I think a JavaScript golfer should be able to golf this idea a lot more (I'm not one!).

```
function(n){for(x=i=0;i++<n;console.log(...a))for(j=0,a=[''];j++<n;a.push('float:left;border:1px solid #000;color:red'))a[0]+='%c'+(x++).toString(16).padEnd(2)}

```

A **155 bytes** version, but it prints some noises on top and right of the grid:

```
function(n,a=[]){for(x=0;x<n*n;a.push('float:left;border:1px solid #000;color:red'),a[0]+='%c'+(x++).toString(16).padEnd(2))x%n?0:console.log(...a,a=[''])}

```

This only works in modern browsers console.

Sample usage in console: `f=...code above...;` and then `f(16);`

Or open your browser's console and then click on **Run code snippet** button.

```
f=function(n){for(x=i=0;i++<n;console.log(...a))for(j=0,a=[''];j++<n;a.push('float:left;border:1px solid #000;color:red'))a[0]+='%c'+(x++).toString(16).padEnd(2)};
f(16);
```

### Explanation:

In a modern browser console, you can use this format to apply CSS to your values printed in the console:

```
console.log('%c Value', 'color: red; font-size: 10px;');

```

For every `%c` you have to add a new argument with your styles and those styles will be applied until the next `%c`. So to style and print two values in same line, we can use something like this:

```
console.log('%c Value %c Value2', 'color: red; font-size: 10px;', 'font-weight: bold;');

```

In the function above, I'm collecting arguments for each row in an array called `a` and each row gets a single `console.log` for itself.
> 1 votes

---
Tags: code-golf, graphical-output
---


title: Codegolf : the HEX

text:
# Question
Title: Codegolf : the HEX
## INTRODUCTION

I like Karma Fields : he's a music producer that creates original music tracks. His artwork also matches up really well his style.

He has a logo witch I find really interessing :

## GOAL

Your goal will be to reproduce that logo, graphically or in ASCII.

**Edit**

@NahuelFouilleul managed to provide a readable ascii version of this :

```
     / \
   /|   |\
 /  |   | |\
|\ /|\ / \|/|
| | \ |     |
|/ \ / \    |
| \ | / |   |
 \|/ \|/ \ /
   \  |  /
     \|/

```

## RULES

* The logo can be any size BUT has to be recognisable (each hexagon part has to be visible).
* Colors don't matter, only the drawing counts.
* Each line can be the same thickness, and you can forget about the 2 dots.
* This is a codegold challenge, so the least amount of bytes wins.
* The usual loopholes are forbidden.

# Answer
> 5 votes
## Logo, ~~170~~ ~~168~~ 160 bytes

```
make"l[4 5 2 3 1 3 1 1 3 1 5 5 1 3 1 1 2 5 2 5 5 3 5 5 3 0 5 4 5 3 5 5 3 5 5 4 0 0 5 0 0 5 0 0 5 0 0 5 0 0 5 0 0 5 4]repeat 55[rt 60*head:l
fw 20
make"l tail:l]

```

Try it online! Edit: Saved ~~2~~ 9 bytes thanks to @Night2.

# Answer
> 3 votes
# Raw bitmap (29x35), 202 bytes

Hand drawn a small monochrome bitmap file which looks like the logo. I'm not sure if raw bitmap is accepted here, but if it is not, a HTML version is below the post too.

Please note that the image above is converted to PNG during upload, to see the original image save the hex dump as a binary file or use the HTML version.

```
000000  42 4d ca 00 00 00 00 00 00 00 3e 00 00 00 28 00  BM........>...(.
000010  00 00 1d 00 00 00 23 00 00 00 01 00 01 00 00 00  ......#.........
000020  00 00 8c 00 00 00 c3 0e 00 00 c3 0e 00 00 00 00  ................
000030  00 00 00 00 00 00 00 00 00 00 ff ff ff 00 ff fd  ................
000040  ff f8 ff f0 7f f8 ff ed bf f8 ff 9d cf f8 fe 7d  ...............}
000050  f3 f8 fd fd fd f8 f1 f8 fc 78 e6 e5 33 b8 97 5d  .........x..3..]
000060  cf c8 77 bd df f0 77 bd df f0 77 bd df f0 6f bc  ..w...w...w...o.
000070  df f0 5f bf 1f f0 3f 9f df f0 4e 67 3f f0 75 fa  .._...?...Ng?.u.
000080  ff f0 7b fd ff f0 7b f9 ff f0 7b e5 ff f0 7b dd  ..{...{...{...{.
000090  ff f0 7b dd ff f0 7b dd ff f0 64 dd fe 70 5f 52  ..{...{...d..p_R
0000a0  78 90 3f 8f a6 e8 bf df de d8 cf df de b8 f3 df  x.?.............
0000b0  de 78 fd df d9 f8 fe 5f d7 f8 ff 9f cf f8 ff cf  .x....._........
0000c0  bf f8 ff f2 7f f8 ff fd ff f8                    ..........

```

# HTML, 292 bytes

```
<img src=data:;base64,Qk3KAAAAAAAAAD4AAAAoAAAAHQAAACMAAAABAAEAAAAAAIwAAADDDgAAww4AAAAAAAAAAAAAAAAAAP///wD//f/4//B/+P/tv/j/nc/4/n3z+P39/fjx+Px45uUzuJddz8h3vd/wd73f8He93/BvvN/wX78f8D+f3/BOZz/wdfr/8Hv9//B7+f/we+X/8Hvd//B73f/we93/8GTd/nBfUniQP4+m6L/f3tjP396489/eeP3f2fj+X9f4/5/P+P/Pv/j/8n/4//3/+A
```

# Answer
> 3 votes
JavaScript, 420 407 bytes

```
document.write('<svg id="pic" height="255" width="255"></svg>')
v="0011120322210011343546413441045156516421646728696a52586758075b5104074848090a520a4248423a030a".split``.map((x,i)=>(i%2?[43,88,175,220,100,72,58,131,144,162,190,117]:[129,206,52,179,154,103,77])[+('0x'+x)])
for(i=1;i<46;i++) pic.innerHTML+=`<line x1=${v[2*i-2]} y1=${v[2*i-1]} x2=${v[2*i]} y2=${v[2*i+1]} style="stroke:red;stroke-width:2" />`
```

Point coordinates coding

```
let c=[129, 43, 206, 88, 206, 175, 129, 220, 52, 175, 52, 88,129, 43, 206, 88, 179, 100, 179, 72, 154, 58, 154, 88, 179, 100, 154, 88,129, 100, 103, 88, 103, 58,103, 88,77, 100, 52, 88,77, 100, 77, 131, 52, 144, 77, 162, 77, 190, 103, 175, 103, 144, 77,  131, 103, 144,129, 131, 103, 117, 103, 88,129, 100, 129, 131,154, 144, 154, 144,129, 162, 129, 190, 103, 175,129, 190,154, 175,154, 144,154, 175, 179, 190,129, 220,129, 190
]

a=[... new Set(c.filter((x,i)=> i%2))] // remove duplicates for X
b=[... new Set(c.filter((x,i)=> i%2-1))] // remove duplicates for Y
d=c.map((x,i)=> (i%2?a:b).indexOf(x).toString(16)).join``

console.log({a,b,d});
```

# Answer
> 2 votes
# PHP, 71 bytes

I have used a compressed version of the string created by Nahuel Fouilleul in the OP comments.

Uses raw output of gzdeflate and contains unprintable binary data, so the code itself and direct TIO link cannot be posted here, but here is a hex dump of it:

```
000000  3c 3f 3d 67 7a 69 6e 66 6c 61 74 65 28 22 15 c7  <?=gzinflate("..
000010  47 01 43 01 14 02 b0 73 97 87 38 c0 10 52 10 df  G.C....s..8..R..
000020  ff 36 01 d1 df 1b 19 76 39 0c 73 5a e5 56 97 3d  .6.....v9.sZ.V.=
000030  34 35 70 8c ba c5 51 4d 8c a3 2e b7 2a 8f 28 73  45p...QM....*.(s
000040  19 74 f9 03 22 29 3b                             .t..");

```

Save it as a binary file then execute it like this: `php hex.php`

TIO which uses bash to create and run this file: Try it online!

Base64 of deflated string for anyone who might need it:

```
FcdHAUMBFAKwc5eHOMAQUhDf/zYB0d8bGXY5DHNa5VaXPTQ1cIy6xVFNjKMutyqPKHMZdPkD

```

---
Tags: code-golf, ascii-art, graphical-output
---


title: Simulate a 1D Game-of-Life-ish Model

text:
# Question
Title: Simulate a 1D Game-of-Life-ish Model
This question just trended over on code-review and I figured you might like it adapted as a codegolf challenge:

You are given a non-empty list of x houses represented as booleans. Each day, the houses compete with adjacent ones. 1 represents an "active" house and 0 represents an "inactive" house. If the neighbors on both sides of a given house are either both active or both inactive, then that house becomes inactive on the next day. Otherwise it becomes active.

```
def get_state_as_pos(thelist, pos):
    if thelist[pos-1] == thelist[pos+1]:
        return 0
    else:
        return 1

```

For example, if we had a group of neighbors \[0, 1, 0\] then the house at \[1\] would become 0 since both the house to its left and right are both inactive. The cells at both ends check the opposite side as well, so the neighbors at index 0 are at index `length-1` and indexn1 and vice versa. Even after updating the cell, you have to consider its prior state when updating the others so that the state information of each cell is updated simultaneously.

The function takes the array of states and a number of steps and should output the state of the houses after the given number of steps.

```
    input: states = [1, 0, 0, 0, 0, 1, 0, 0], steps = 1
   output should be [0, 1, 0, 0, 1, 0, 1, 1]

    input: states = [1, 1, 1, 0, 1, 1, 1, 1], steps = 2
intermediate state= [0, 0, 1, 0, 1, 0, 0, 0]
   output should be [0, 1, 0, 0, 0, 1, 0, 0]

    input: states = [1], steps=1
    output: states= [0]

```

Take the list and steps however you like and output the resulting list via default I/O. Standard loopholes are forbidden. This is codegolf, shortest answer in bytes wins!

# Answer
# 05AB1E, ~~14~~ ~~13~~ ~~10~~ ~~9~~ 6 bytes

*Based on Shaggy's Japt solution*

```
F©Á®À^

```

Try it online!

```
F                  # repeat n times:
 ©Á                #  the list, rotated right
   ®À              #  the list, rotated left
     ^             #  xor (vectorizes)

```

---

Unnecessarily clever 9-byte solution:

```
F¥DO.øü+É

```

Try it online!

```
F                  # repeat n times:
                   #  (examples given for the initial state [0, 1, 1, 0, 1])
 ¥                 #  deltas of the list ([1, 0, -1, 1])
  D                #  duplicate
   O               #  sum (1)
    .ø             #  surround ([1, 1, 0, -1, 1, 1])
      ü+           #  pairwise addition ([2, 1, -1, 0, 2])
        É          #  modulo 2 ([0, 1, 1, 0, 0])

```
> 8 votes

# Answer
# Python 2, 72 bytes

```
f=lambda s,n:n and f([a^b for a,b in zip(s[-1:]+s,s[1:]+s[:1])],n-1)or s

```

Try it online!
> 5 votes

# Answer
# Wolfram Language (Mathematica), 31 bytes

```
CellularAutomaton[90,#,{{#2}}]&

```

Try it online!

`CellularAutomaton` assumes the input list is cyclic.
> 5 votes

# Answer
# JavaScript (ES6), 57 bytes

Takes input as `(steps)(array)`.

```
s=>g=a=>s--?g(a.map(_=>a[~-i++%l]^a[i%l],i=l=a.length)):a

```

Try it online!
> 2 votes

# Answer
# Japt `-mh`, ~~11~~ ~~10~~ 9 bytes

I/O of states as singleton 2D arrays.

```
VÇí^Zé2)é

```

Try it

```
VÇí^Zé2)é     :Implicit input of integer U=steps & array V=[states]
VÇ            :Modify the last element Z in V
  í           :Interleave with
    Zé2       :  Z rotated right twice and
   ^          :  Reduce each pair by XOR
       )      :End interleave
        é     :Rotate right once
              :Repeat U times and implicitly output V

```
> 2 votes

# Answer
# Retina, 51 bytes

```
1A`
"$+"{`(.).*(.)
$2$&$1
(.)(?=.(\1|(.)))?
$#2*$#3

```

Try it online! Takes the number of steps on the first line and a string of `0`s and `1`s on the second line. Explanation:

```
1A`

```

Delete the number of steps from the input.

```
"$+"{

```

Repeat that number times.

```
`(.).*(.)
$2$&$1

```

Copy the end digits to the other ends to simulate wrapping.

```
(.)(?=.(\1|(.)))?
$#2*$#3

```

Perform the XOR operation.
> 2 votes

# Answer
# APL (Dyalog Extended), 12 bytesSBCS

Full program. Prompts stdin for array of states and then for number of steps. Prints to stdout.

```
1(⌽≠⌽⍢⌽)⍣⎕⊢⎕

```

Try it online!

get evaluated input from console (array of states)

on that, apply…

`1(``)⍣⎕` the following tacit function, input number of times, each time with `1` as left argument:

`⌽⍢⌽` rotate the right argument 1 step left while reversed (i.e. rotate one step right)

`⌽≠` XOR with the argument rotated 1 step left
> 2 votes

# Answer
# Python 2, 71 bytes

```
f=lambda a,n:n and f([a[i-1]^(a+a)[i+1]for i in range(len(a))],n-1)or a

```

Try it online!
> 2 votes

# Answer
# Jelly, 7 bytes

```
ṙØ+^/$¡

```

Try it online!

Full program. A singleton output is represented as `x` instead of `[x]`.
> 2 votes

# Answer
# Pyth, 24 bytes

```
AQVH=Gmxhded.:+eG+GhG3;G

```

Try it online!

```
AQ                        # G, H = Q[0], Q[1] # Q = input in the form [[states],steps]
  VH                      # for i in range(H):
    =G                    # G =
      m                   #     map(lambda d:                              )
       xhded              #                   d[0] ^ d[-1],
            .:       3    #         substrings(                 , length=3)
              +eG+GhG     #                     G[-1] + G + G[0]
                      ;   # (end for loop)
                       G  # print G

```
> 1 votes

# Answer
# Ruby, 59 bytes

```
->r,n{n.times{r=r.rotate.zip(r.rotate -1).map{|a,b|a^b}};r}

```

Try it online!
> 0 votes

---
Tags: code-golf, cellular-automata
---


title: States and Capitals

text:
# Question
Title: States and Capitals
Given a string as input, output the US state whose capital it is if it is a state capital, the capital of the state if it is a state, or `Arstotzka` if it is neither.

Examples:

```
Austin -> Texas
Alaska -> Juneau
The Nineteenth Byte -> Arstotzka

```

All the capitals and their respective states:

```
Baton Rouge, Louisiana
Indianapolis, Indiana
Columbus, Ohio
Montgomery, Alabama
Helena, Montana
Denver, Colorado
Boise, Idaho
Austin, Texas
Boston, Massachusetts
Albany, New York
Tallahassee, Florida
Santa Fe, New Mexico
Nashville, Tennessee
Trenton, New Jersey
Jefferson, Missouri
Richmond, Virginia
Pierre, South Dakota
Harrisburg, Pennsylvania
Augusta, Maine
Providence, Rhode Island
Dover, Delaware
Concord, New Hampshire
Montpelier, Vermont
Hartford, Connecticut
Topeka, Kansas
Saint Paul, Minnesota
Juneau, Alaska
Lincoln, Nebraska
Raleigh, North Carolina
Madison, Wisconsin
Olympia, Washington
Phoenix, Arizona
Lansing, Michigan
Honolulu, Hawaii
Jackson, Mississippi
Springfield, Illinois
Columbia, South Carolina
Annapolis, Maryland
Cheyenne, Wyoming
Salt Lake City, Utah
Atlanta, Georgia
Bismarck, North Dakota
Frankfort, Kentucky
Salem, Oregon
Little Rock, Arkansas
Des Moines, Iowa
Sacramento, California
Oklahoma City, Oklahoma
Charleston, West Virginia
Carson City, Nevada

```

### Rules

* No built-ins or libraries/modules that provide a mapping from states to capitals or capitals to states, or lists of capitals and/or states (for example, Mathematica's `CityData` built-in)
* Standard loopholes apply
* This is , so shortest answer in bytes wins!

# Leaderboard

The Stack Snippet at the bottom of this post generates the leaderboard from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```
## Language Name, N bytes

```

where `N` is the size of your submission. If you improve your score, you *can* keep old scores in the headline, by striking them through. For instance:

```
## Ruby, <s>104</s> <s>101</s> 96 bytes

```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the *last* number in the header:

```
## Perl, 43 + 2 (-p flag) = 45 bytes

```

You can also make the language name a link which will then show up in the snippet:

```
## [><>](http://esolangs.org/wiki/Fish), 121 bytes

```

```
<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 64254; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 45941; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>
```

# Answer
# Pyth, ~~597~~ ~~596~~ 590

```
00000000: 40 4a 63 72 58 73 40 4c 2b 62 47 6a 43 22 05 77 c6  @JcrXs@L+bGjC".w.
00000011: fa 94 29 be 77 9b 88 35 9b e0 86 05 86 8a d3 cd 53  ..).w..5........S
00000022: e6 97 c1 20 f4 bd b5 76 f3 f7 14 ab 4b fa 8e 4d 2c  ... ...v....K..M,
00000033: be 71 4d 13 ca 9c 67 3e 35 21 76 6b 74 f8 88 8b c1  .qM...g>5!vkt....
00000044: bc 2a ab da 6b ba 1f 2b a3 2c 12 bc d1 b8 c3 b6 7c  .*..k..+.,......|
00000055: b0 4d 0f 11 a2 dc 15 a2 94 45 39 1c 20 12 08 03 a3  .M.......E9. ....
00000066: 5c 71 d9 11 1c 56 f5 c2 2d cb 63 64 b3 c0 d8 e7 e3  \q...V..-.cd.....
00000077: 9b 82 28 85 57 2b e4 28 ea 8f 17 02 1d a8 8f f3 0e  ..(.W+.(.........
00000088: 31 5f 8e c4 2b b3 8f 7e b2 64 fc d2 99 dc 9d 98 e5  1_..+..~.d.......
00000099: 3a b3 8b 59 52 5f 63 5a ae c9 3d 8a 7a b6 a2 0a 8a  :..YR_cZ..=.z....
000000aa: 2f 4c 43 78 fa 56 9b 07 ce 21 3a 2f 50 5e d3 f3 a9  /LCx.V...!:/P^...
000000bb: 90 ad 21 85 75 cd 9e 07 29 a3 3d b7 c2 cd f4 b8 5f  ..!.u...).=....._
000000cc: 60 b4 72 cd 47 93 17 14 28 3e da b1 65 90 ec 5f 35  `.r.G...(>..e.._5
000000dd: 4d c6 0e b1 66 40 af 8a 67 95 47 f8 8f fd 38 66 c8  M...f@..g.G...8f.
000000ee: df fd 51 6c 5f 06 06 35 a1 77 ae 93 84 73 33 63 be  ..Ql_..5.w...s3c.
000000ff: 98 3e 1c f3 43 de ca 0a 13 6d e9 64 52 96 b8 41 e8  .>..C....m.dR..A.
00000110: db 23 a6 01 c5 60 38 db 63 9c 2a d9 5d 03 fc 38 c8  .#...`8.c.*.]..8.
00000121: 94 1e 2f 70 8e 4d 0f 93 44 4a 6c 57 e8 af cc e7 e2  ../p.M..DJlW.....
00000132: 70 82 84 a3 06 d3 2a 4f cd 8b b6 68 a5 80 98 9e 49  p.....*O...h....I
00000143: 4f bc fd 91 20 55 a6 66 12 1d c0 49 f2 3e 9e ef 5d  O... U.f...I.>..]
00000154: 89 bc b3 30 ef dd cc ca 93 70 27 2c 14 03 6a 53 32  ...0.....p',..jS2
00000165: ef af e1 b5 d3 5a cc 3e fd 1d 78 a5 b3 06 ae 67 58  .....Z.>..x....gX
00000176: ec e4 7a 99 16 f5 da a7 1e 51 0a 94 fc cd e9 e8 fe  ..z......Q.......
00000187: 5a d1 bc 0f bb 24 9d 45 9a ac 97 58 a7 9b ea f0 77  Z....$.E...X....w
00000198: 89 e8 a1 fa e7 83 2c b9 ea 5c a7 f1 b3 76 ba 97 fb  ......,..\...v...
000001a9: 41 b7 74 9a 09 2d 96 97 73 80 13 17 7a fe 15 5f c6  A.t..-..s...z.._.
000001ba: cf 89 3d 7f df 54 cd 16 fe 8a ea d7 0a 91 84 54 61  ..=..T.........Ta
000001cb: 4f 03 87 a6 d2 1c c8 a9 b8 0f 52 2e 39 13 2e 48 8b  O.........R.9..H.
000001dc: 04 ce 2d 35 5e 02 96 63 11 a7 f8 75 6d 8a e2 13 e2  ..-5^..c...um....
000001ed: d6 1b f9 43 07 3e 99 29 a9 69 7f f5 6a 72 15 7b 92  ...C.>.).i..jr.{.
000001fe: 5b 26 cb 74 48 1b c0 fc fb 64 45 05 2d 37 d6 21 6a  [&.tH....dE.-7.!j
0000020f: d9 83 88 13 fb e7 e8 f2 17 c7 54 de 48 f6 23 1e bf  ..........T.H.#..
00000220: b0 34 f5 4f 63 ce 46 40 a9 16 e7 4a 60 71 ce a3 d3  .4.Oc.F@...J`q...
00000231: 6a 15 4c 8b 52 d6 3f cb 53 dd 96 97 10 f6 e5 22 32  j.L.R.?.S......"2
00000242: 37 5c 71 64 33 62 5f 68 68 78 4a 7a                 7\qd3b_hhxJz

```

The above hexdump can be reversed with `xxd -r -c 17`. Try it online in the Pyth Compiler.

### Idea

We encode the required information as follows:

```
columbia
columbus
frankfort
⋮
kentucky
ohio
southqcarolina
arstotzka

```

All the names have been cast to lowercase, spaces have been replaced with q's, and names are separated by linefeeds.

All capitals are listed first (in an order that managed to minimize the byte count). Then the corresponding states are listed in reverse order. Finally, *Arstotzka* is appended.

This way, the capital/state at index **i** corresponds to the state/capital at index **-(x+2)**. Also, an invalid input will either have index **100** (*Arstotzka*) or **-1** (not found), and **-(100+2) ≡ -1 ≡ -(-1+2) mod 101**. This layout prevents *Arstotzka* from being a special case, without prepending or appending anything to the list.

To compress the information, we find each character's index in `"\nabc...xyz"` and convert the result from base 27 to base 256.

Decoding is straightforward: we go back from base 256 to base 27, retrieve the corresponding elements from `"\nabc…xyz"`, replace q's with spaces, and capitalize the first letter of each resulting word.

### Code

```
@JcrXs@L+bGjC"…"27\qd3b_hhxJz

            C"…"               Convert the 562-character from base 256 to integer.
           j    27             Convert the result from integer to base 27.
        +bG                    Compute "\n" + "abc…xyz".
      @L                       Retrieve the corresponding characters.
     s                         Flatten the resulting array of strings.
    X             \qd          Replace each q with a space.
   r                 3         Apply title casing.
 Jc                   b        Split at linefeeds and save in J.
                          xJz  Compute the index of the input (z) in J.
                       _hh     Increment twice and negate.
@                              Retrieve the element at that index from J.

```
> 9 votes

# Answer
# Python3, 997 bytes

```
i=input()
s="Baton Rouge,Louisiana,Indianapolis,Indiana,Columbus,Ohio,Montgomery,Alabama,Helena,Montana,Denver,Colorado,Boise,Idaho,Austin,Texas,Boston,Massachusetts,Albany,New York,Tallahassee,Florida,Santa Fe,New Mexico,Nashville,Tennessee,Trenton,New Jersey,Jefferson,Missouri,Richmond,Virginia,Pierre,South Dakota,Harrisburg,Pennsylvania,Augusta,Maine,Providence,Rhode Island,Dover,Delaware,Concord,New Hampshire,Montpelier,Vermont,Hartford,Connecticut,Topeka,Kansas,Saint Paul,Minnesota,Juneau,Alaska,Lincoln,Nebraska,Raleigh,North Carolina,Madison,Wisconsin,Olympia,Washington,Phoenix,Arizona,Lansing,Michigan,Honolulu,Hawaii,Jackson,Mississippi,Springfield,Illinois,Columbia,South Carolina,Annapolis,Maryland,Cheyenne,Wyoming,Salt Lake City,Utah,Atlanta,Georgia,Bismarck,North Dakota,Frankfort,Kentucky,Salem,Oregon,Little Rock,Arkansas,Des Moines,Iowa,Sacramento,California,Oklahoma City,Oklahoma,Charleston,West Virginia,Carson City,Nevada,Arstotzka".split(",")+[i]
print(s[1^s.index(i)])

```

I can not be bothered to do the base-conversion or binary packing that the winning version will undoubtly do, but I do want to post this to show a really cool trick.

XOR'ing a number by 1 is equivalent to adding 1 if the number is even, or subtracting 1 if the number is odd. You can make really easy and golfy bi-directional maps using this trick.
> 24 votes

# Answer
# CJam, ~~625~~ ~~609~~ ~~603~~ 599 bytes

```
00000000: 22 05 77 c6 fa 94 29 be 77 9b 88 35 9b e0 86 05 86  ".w...).w..5.....
00000011: 8a d3 cd 53 e6 97 c1 20 f4 bd b5 76 f3 f7 14 ab 4b  ...S... ...v....K
00000022: fa 8e 4d 2c be 71 4d 13 ca 9c 67 3e 35 21 76 6b 74  ..M,.qM...g>5!vkt
00000033: f8 88 8b c1 bc 2a ab da 6b ba 1f 2b a3 2c 12 bc d1  .....*..k..+.,...
00000044: b8 c3 b6 7c b0 4d 0f 11 a2 dc 15 a2 94 45 39 1c 20  ...|.M.......E9.
00000055: 12 08 03 a3 5c 71 d9 11 1c 56 f5 c2 2d cb 63 64 b3  ....\q...V..-.cd.
00000066: c0 d8 e7 e3 9b 82 28 85 57 2b e4 28 ea 8f 17 02 1d  ......(.W+.(.....
00000077: a8 8f f3 0e 31 5f 8e c4 2b b3 8f 7e b2 64 fc d2 99  ....1_..+..~.d...
00000088: dc 9d 98 e5 3a b3 8b 59 52 5f 63 5a ae c9 3d 8a 7a  ....:..YR_cZ..=.z
00000099: b6 a2 0a 8a 2f 4c 43 78 fa 56 9b 07 ce 21 3a 2f 50  ..../LCx.V...!:/P
000000aa: 5e d3 f3 a9 90 ad 21 85 75 cd 9e 07 29 a3 3d b7 c2  ^.....!.u...).=..
000000bb: cd f4 b8 5f 60 b4 72 cd 47 93 17 14 28 3e da b1 65  ..._`.r.G...(>..e
000000cc: 90 ec 5f 35 4d c6 0e b1 66 40 af 8a 67 95 47 f8 8f  .._5M...f@..g.G..
000000dd: fd 38 66 c8 df fd 51 6c 5f 06 06 35 a1 77 ae 93 84  .8f...Ql_..5.w...
000000ee: 73 33 63 be 98 3e 1c f3 43 de ca 0a 13 6d e9 64 52  s3c..>..C....m.dR
000000ff: 96 b8 41 e8 db 23 a6 01 c5 60 38 db 63 9c 2a d9 5d  ..A..#...`8.c.*.]
00000110: 03 fc 38 c8 94 1e 2f 70 8e 4d 0f 93 44 4a 6c 57 e8  ..8.../p.M..DJlW.
00000121: af cc e7 e2 70 82 84 a3 06 d3 2a 4f cd 8b b6 68 a5  ....p.....*O...h.
00000132: 80 98 9e 49 4f bc fd 91 20 55 a6 66 12 1d c0 49 f2  ...IO... U.f...I.
00000143: 3e 9e ef 5d 89 bc b3 30 ef dd cc ca 93 70 27 2c 14  >..]...0.....p',.
00000154: 03 6a 53 32 ef af e1 b5 d3 5a cc 3e fd 1d 78 a5 b3  .jS2.....Z.>..x..
00000165: 06 ae 67 58 ec e4 7a 99 16 f5 da a7 1e 51 0a 94 fc  ..gX..z......Q...
00000176: cd e9 e8 fe 5a d1 bc 0f bb 24 9d 45 9a ac 97 58 a7  ....Z....$.E...X.
00000187: 9b ea f0 77 89 e8 a1 fa e7 83 2c b9 ea 5c a7 f1 b3  ...w......,..\...
00000198: 76 ba 97 fb 41 b7 74 9a 09 2d 96 97 73 80 13 17 7a  v...A.t..-..s...z
000001a9: fe 15 5f c6 cf 89 3d 7f df 54 cd 16 fe 8a ea d7 0a  .._...=..T.......
000001ba: 91 84 54 61 4f 03 87 a6 d2 1c c8 a9 b8 0f 52 2e 39  ..TaO.........R.9
000001cb: 13 2e 48 8b 04 ce 2d 35 5e 02 96 63 11 a7 f8 75 6d  ..H...-5^..c...um
000001dc: 8a e2 13 e2 d6 1b f9 43 07 3e 99 29 a9 69 7f f5 6a  .......C.>.).i..j
000001ed: 72 15 7b 92 5b 26 cb 74 48 1b c0 fc fb 64 45 05 2d  r.{.[&.tH....dE.-
000001fe: 37 d6 21 6a d9 83 88 13 fb e7 e8 f2 17 c7 54 de 48  7.!j..........T.H
0000020f: f6 23 1e bf b0 34 f5 4f 63 ce 46 40 a9 16 e7 4a 60  .#...4.Oc.F@...J`
00000220: 71 ce a3 d3 6a 15 4c 8b 52 d6 3f cb 53 dd 96 97 10  q...j.L.R.?.S....
00000231: f6 e5 22 32 35 36 62 32 37 62 27 60 66 2b 27 60 2f  .."256b27b'`f+'`/
00000242: 7b 27 71 2f 33 32 61 66 2e 5e 53 2a 7d 25 5f 71 61  {'q/32af.^S*}%_qa
00000253: 23 7e 28 3d                                         #~(=

```

The above hexdump can be reversed with `xxd -r -c 17`. Try it online in the CJam interpreter.

### Idea

We encode the required information as follows:

```
columbia`columbus`frankfort`olympia`desqmoines`jefferson`springfield`carsonqcity`topeka`sacramento`littleqrock`saltqlakeqcity`boston`trenton`batonqrouge`indianapolis`madison`charleston`austin`denver`hartford`santaqfe`atlanta`augusta`boise`oklahomaqcity`dover`helena`tallahassee`richmond`lansing`honolulu`saintqpaul`salem`providence`raleigh`cheyenne`nashville`concord`albany`bismarck`phoenix`jackson`montpelier`montgomery`harrisburg`juneau`pierre`annapolis`lincoln`nebraska`maryland`southqdakota`alaska`pennsylvania`alabama`vermont`mississippi`arizona`northqdakota`newqyork`newqhampshire`tennessee`wyoming`northqcarolina`rhodeqisland`oregon`minnesota`hawaii`michigan`virginia`florida`montana`delaware`oklahoma`idaho`maine`georgia`newqmexico`connecticut`colorado`texas`westqvirginia`wisconsin`indiana`louisiana`newqjersey`massachusetts`utah`arkansas`california`kansas`nevada`illinois`missouri`iowa`washington`kentucky`ohio`southqcarolina`arstotzka

```

All the names have been cast to lowercase, spaces have been replaced with q's, and names are separated by backticks.

All capitals are listed first (in an order that managed to minimize the byte count). Then the corresponding states are listed in reverse order. Finally, *Arstotzka* is appended.

This way, the capital/state at index **i** corresponds to the state/capital at index **-(x+2)**. Also, an invalid input will either have index **100** (*Arstotzka*) or **-1** (not found), and **-(100+2) ≡ -1 ≡ -(-1+2) mod 101**. This layout prevents *Arstotzka* from being a special case, without prepending or appending anything to the list.

To compress the information, we subtract 97 (code point of ```) from each character in the string and convert the result from base 27 to base 256.

Decoding is straightforward: we go back from base 256 to base 27, add the resulting base-27 digits to the backtick character, replace q's with spaces, and capitalize the first letter of each resulting word.

### Code

```
"…"          e# Push a string of 562 characters.
256b27b      e# Convert it from base 256 to base 27.
'`f+         e# Add each base-27 digit to the character '`'.
'`/          e# Split at occurrences of '`'.
{            e#   For each resulting chunk:
  'q/        e#   Split at occurrences of 'q'.
  32a        e#   Push [32].
  f.^        e#   For each chunk, perform vectorized XOR with 32.
             e#   This capitalizes the first character of the chunk.
  S*         e#   Join the chunks, separating by spaces.
}%           e#
_            e# Push a copy of the resulting array.
qa           e# Read all user input and wrap it in an array.
#            e# Find its index (i) in the copy.
~(           e# Apply bitwise NOT and decrements to calculate
             e# ~i - 1 = -(i + 1) - 1 = -(i + 2).
=            e# Retrieve element at the corresponding index.

```
> 12 votes

# Answer
# JavaScript (ES6), ~~821~~ 806 bytes

Uses Base64 decode to compress strings. Live demo

```
s=>(S=(r=x=>btoa(x).replace(/\+/g," ").split`/`)`.¢²&§kò'v&§kó¡À¦Ú¯Ì¢{Z¯Â¢Z+iÚ?!Ö¡£ôÞÅ«?1«,iÈn±ëm³ó^Ãæ(®OÅâu¯Í{{£ôÞw¬±ç¿5ì>%êì{/ÌË(º¸¿V*àxý*.¶jJ-kóÞ{2ö§¯Ìj)Þýhuï²V§wðÞ¬ïÍ{jjl*ÞýW«íü*'ç-Ëü¦§±«?2)çzÊ-kð%jÉü×«$kóh®Ø~    ªè)Úýh¬rìÖjÈbhð+:'kó"r jÇk¢ó"²È¬²*iò%)èÏÒ¢ëaø&«¢X§kó¯)ZßÖÊ¢Ôµ¨ê+&¿6íàÚZü§§¶ç$Ëó«z
'ü
äj{³ò(Á¯ÂjX¢¹âkó¤¨h¯ÖzË~V*àxü×¯iÖ¿`,C=r`«hähº¿"wbjv©¢X¬ü*%ºfî³ó(Ø(êòüw¥zv¿
éïz¿Á¢+ü¬¶)ÿ-¢À¶§ËôÚV¡jË{ôÖ¾ïÍjÈoY^ý:ÞÚ'ü}êì¢ÑÈf¢w>'«ïÇjºâ±»«ð.ë-kóë¢øzwü:/z¿Â¢w(ßÌ¢{izX¯ñÚ®×èßÓ¢¤kô{~=«¥ü§y«¿.)Ü¢YÿE©^1§b²ÿ:\\¦¦&¿>,-©ìx?èénüÊ'ý*kxé]ü*%ºfâkð'ªh+?
²zyÞý&¥·âÚïÜ¿ÙZÖ¿+&j·$üZÚGè®ßÒjW¦ü¸¶W¾F$ü7¬øÊ"ë?I§+jg§¶ÎV¡¢f¾
+rü(Z®W¬¶ÿ  ªì¢Ü¿`,S[C.indexOf(s)]||C[S.indexOf(s)]||"Arstotzka")

```

Here is a hexdump; use `xxd -r filename` to reverse.

```
00000000: 733d 3e28 533d 2872 3d78 3d3e 6274 6f61  s=>(S=(r=x=>btoa
00000010: 2878 292e 7265 706c 6163 6528 2f5c 2b2f  (x).replace(/\+/
00000020: 672c 2220 2229 2e73 706c 6974 602f 6029  g," ").split`/`)
00000030: 602e 3fa2 b226 a76b f227 7626 a76b f3a1  `.?..&.k.'v&.k..
00000040: 3f8f c03f a6da 3faf cca2 7b5a 9daf c2a2  ?..?..?...{Z....
00000050: 5a2b 69da 3f21 d6a1 a3f4 dec5 ab3f 31ab  Z+i.?!.......?1.
00000060: 2c69 c86e b1eb 6db3 f35e c3e6 28ae 4fc5  ,i.n..m..^..(.O.
00000070: 3f3f e275 afcd 7b0f 3f7b 183f a3f4 de3f  ??.u..{.?{.?...?
00000080: 77ac b1e7 bf35 ec3e 25ea ec7b 2fcc 3fcb  w....5.>%..{/.?.
00000090: 28ba b8bf 562a e03f 783f fd2a 2eb6 1f3f  (...V*.?x?.*...?
000000a0: 6a4a 2d6b f3de 3f7b 323f f6a7 3faf cc6a  jJ-k..?{2?..?..j
000000b0: 29de fd18 6875 ef3f b256 a777 f0de 3fac  )...hu.?.V.w..?.
000000c0: 1aad efcd 7b0f 3f6a 6a6c 3f2a defd 57ab  ....{.?jjl?*..W.
000000d0: 3f3f edfc 2a27 9de7 2d3f cbad fca6 a7b1  ??..*'..-?......
000000e0: ab3f 3229 e77a ca2d 6bf0 256a c91a fcd7  .?2).z.-k.%j....
000000f0: 3fad ab24 6bf3 68ae d87e 09aa e83f 29da  ?..$k.h..~...?).
00000100: fd68 ac72 3fec 3f7f d66a c862 3f0b 683f  .h.r?.?..j.b?.h?
00000110: f02b 3f3a 276b f322 7218 206a 7fc7 6b06  .+?:'k."r. j..k.
00000120: a23f f322 b2c8 acb2 2a69 3ff2 253f 29e8  .?."....*i?.%?).
00000130: 3fcf d2a2 eb61 f826 aba2 58a7 6bf3 1aaf  ?....a.&..X.k...
00000140: 295a 9ddf d6ca 3fa2 3f0f d4b5 a87f 19ea  )Z....?.?.......
00000150: 2b3f 26bf 363f ed3f e0da 3f3f 5afc a7a7  +?&.6?.?..??Z...
00000160: b6e7 24cb f3ab 7a0a 27fc 0ae4 6a7b 1ab3  ..$...z.'...j{..
00000170: f228 c1af c26a 583f a2b9 e26b f3a4 3fa8  .(...jX?...k..?.
00000180: 683f afd6 7acb 7e56 2ae0 3f78 3ffc d7af  h?..z.~V*.?x?...
00000190: 69d6 bf60 2c43 3d72 6005 ab68 3fe4 68ba  i..`,C=r`..h?.h.
000001a0: 07bf 2277 626a 76a9 a258 acfc 2a25 ba66  .."wbjv..X..*%.f
000001b0: eeb3 f328 3fd8 283f eaf2 fc77 a57a 76bf  ...(?.(?...w.zv.
000001c0: 0ae9 ef7a bfc1 a22b 1efc 0bac b629 ff06  ...z...+.....)..
000001d0: 3f2d a27f c03f b6a7 cbf4 da3f 56a1 6acb  ?-...?.....?V.j.
000001e0: 1e7b f43f 3fd6 be15 efcd 6ac8 6f3f 595e  .{.??.....j.o?Y^
000001f0: fd3a de3f da27 fc3f 3f7d eaec a27f d13f  .:.?.'.??}.....?
00000200: c866 a277 7f3e 27ab adef c76a bae2 b1bb  .f.w.>'....j....
00000210: ab3f f02e 3feb 2d6b f3eb a2f8 9d7a 771e  .?..?.-k.....zw.
00000220: fc3a 2f7a bfc2 a277 28ad dfcc a27b 697a  .:/z...w(....{iz
00000230: 583f aff1 daae d7e8 addf d3a2 3fa4 6bf4  X?..........?.k.
00000240: 3f3f 7b7e 3dab a5fc 3fa7 79ab bf2e 29dc  ??{~=...?.y...).
00000250: a259 ff45 a95e 3f08 7f31 a762 b23f ff3a  .Y.E.^?..1.b.?.:
00000260: 5c5c a6a6 26bf 3e1a 1e3f 2c7f 2da9 ec3f  \\..&.>..?,.-..?
00000270: 783f 1e3f e83f e96e fc3f 3f3f ca27 fd2a  x?.?.?.n.???.'.*
00000280: 6b3f 781f 3fe9 5dfc 2a25 ba66 e26b f027  k?x.?.].*%.f.k.'
00000290: 9daa 683f 2b3f 0a17 b27a 79de fd26 a5b7  ..h?+?...zy..&..
000002a0: e2da 3fef 3f3f dcbf 02d9 5a3f d6bf 062b  ..?.??....Z?...+
000002b0: 266a b724 fc5a da3f 47e8 aedf d26a 57a6  &j.$.Z.?G....jW.
000002c0: fcb8 adb6 57be 463f 24fc 37ac f8ca 229d  ....W.F?$.7...".
000002d0: eb3f 49a7 2b6a 67a7 b68f ce3f 56a1 a266  .?I.+jg....?V..f
000002e0: be0a 2b72 fc28 5aae 57ac b63f ff09 aaec  ..+r.(Z.W..?....
000002f0: a27f 3f3f dcbf 602c 535b 432e 696e 6465  ..??..`,S[C.inde
00000300: 784f 6628 7329 5d7c 7c43 5b53 2e69 6e64  xOf(s)]||C[S.ind
00000310: 6578 4f66 2873 295d 7c7c 2241 7273 746f  exOf(s)]||"Arsto
00000320: 747a 6b61 2229                           tzka")

```
> 8 votes

# Answer
## PHP, ~~1272~~ 1239 bytes

Make sure you have enabled short\_open\_tag in php.ini:

This code uses argv\[1\] as the input.

```
<?$c=json_decode('{"Baton Rouge":"Louisiana","Indianapolis":"Indiana","Columbus":"Ohio","Montgomery":"Alabama","Helena":"Montana","Denver":"Colorado","Boise":"Idaho","Austin":"Texas","Boston":"Massachusetts","Albany":"New York","Tallahassee":"Florida","Santa Fe":"New Mexico","Nashville":"Tennessee","Trenton":"New Jersey","Jefferson":"Missouri","Richmond":"Virginia","Pierre":"South Dakota","Harrisburg":"Pennsylvania","Augusta":"Maine","Providence":"Rhode Island","Dover":"Delaware","Concord":"New Hampshire","Montpelier":"Vermont","Hartford":"Connecticut","Topeka":"Kansas","Saint Paul":"Minnesota","Juneau":"Alaska","Lincoln":"Nebraska","Raleigh":"North Carolina","Madison":"Wisconsin","Olympia":"Washington","Phoenix":"Arizona","Lansing":"Michigan","Honolulu":"Hawaii","Jackson":"Mississippi","Springfield":"Illinois","Columbia":"South Carolina","Annapolis":"Maryland","Cheyenne":"Wyoming","Salt Lake City":"Utah","Atlanta":"Georgia","Bismarck":"North Dakota","Frankfort":"Kentucky","Salem":"Oregon","Little Rock":"Arkansas","Des Moines":"Iowa","Sacramento":"California","Oklahoma City":"Oklahoma","Charleston":"West Virginia","Carson City":"Nevada"}',1);$s=array_flip($c);$z=$argv[1];echo @$c[$z]?$c[$z]:(@$s[$z]?$s[$z]:'Arstotzka');

```
> 6 votes

# Answer
# Java, ~~1062~~ 964 bytes

```
s->{String t="Arstotzka",a[]="AlabamaMontgomeryAlaskaJuneauArizonaPhoenixArkansasLittle RockCaliforniaSacrementoColoradoDenverConecticutHartfordDelawareDoverFloridaTallahasseeGeorgiaAtlantaHawaiiHonoluluIdahoBoiseIllinoisSpringfieldIndianaIndianapolisIowaDes MoinesKansasTopekaKentuckyFrankfortLouisianaBaton RougeMaineAugustaMarylandAnnapolisMassachusettsBostonMichiganLansingMinnesotaSaint PaulMississippiJacksonMissouriJefferson CityMontanaHelenaNebraskaLincolnNevadaCarson CityNew HampshireConcordNew JerseyTrentonNew MexicoSanta FeNew YorkAlbanyNorth CarolinaRaleighNorth DakotaBismarckOhioColumbusOklahomaOklahoma CityOregonSalemPennsylvaniaHarrisburgRhode IslandProvidenceSouth CarolinaColumbiaSouth DakotaPierreTennesseeNashvilleTexasAustinUtahSalt Lake CityVermontMontpelierVirginiaRichmondWashingtonOlympiaWest VirginiaCharlestonWisconsinMadisonWyomingCheyenne".split("(?<=[a-z])(?=[A-Z])");for(int k=-1;k++<99;t=s.equals(a[k])?a[k%2*-2-~k]:t);return t;}

```

*-17 bytes thanks to @KevinCruijssen.*

Try it online!

Pretty straightforward; if a match is found, then add to or subtract from the current index of the array depending on whether it is even or odd. Otherwise print "Arstotzka".

The majority of bytes saved was due to removing the 99 `:`s and splitting the string based on the regex `(?<=[a-z])(?=[A-Z])`, which uses a positive lookbehind and lookahead to check for a difference in casing.
> 5 votes

# Answer
# , ~~1023~~ 985 bytes

```
function(s){g=strsplit
y="Bat9 Rouge,Indi2apol3,Columbus,M9tgomery,Hel6a,D6ver,Bo3e,Aust1,Bost9,Alb2y,Tallah5s4,S2ta Fe,N5hville,Tr6t9,Jeffers9,Richm9d,Pierre,H7r3burg,Augusta,Provid6ce,Dover,C9c0d,M9tpelier,H7tf0d,Topeka,Sa1t Paul,Juneau,L1coln,Raleigh,Mad39,Olympia,Pho6ix,L2s1g,H9olulu,Jacks9,Spr1gfield,Columbia,Annapol3,Chey6ne,Salt Lake8,Atl2ta,B3m7ck,Fr2kf0t,Salem,Little Rock,Des Mo1es,Sacram6to,Oklahoma8,Ch7lest9,C7s98,Nevada,West Virg1ia,Oklahoma,Calif0nia,Iowa,Ark2s5,Oreg9,K6tucky,N0th Dakota,Ge0gia,Utah,Wyom1g,M7yl2d,South C7ol1a,Ill1o3,M3s3sippi,Hawaii,Michig2,Ariz9a,W5h1gt9,W3c9s1,N0th C7ol1a,Nebr5ka,Al5ka,M1nesota,K2s5,C9necticut,Verm9t,New Hampshire,Delaw7e,Rhode Isl2d,Ma1e,P6nsylv2ia,South Dakota,Virg1ia,M3souri,New Jersey,T6ness4,New Mexico,Fl0ida,New Y0k,M5sachusetts,Tex5,Idaho,Col0ado,M9t2a,Alabama,Ohio,Indi2a,Lou3i2a"
for(i in 0:9)y=gsub(i,g("or,in,an,is,ee,as,en,ar, City,on",",")[[1]][i+1],y)
x=g(y,",")[[1]]
'if'({y=match(s,x,0)},x[101-y],'Arstotzka')}

```

Try it online!

Different from the other R submission.

The code puts the capitals and states in the same vector. The states are in reverse order so that, given the index of either the state or the capital, the matching entry's index is `length(data)-index+1`, where `length(data)=100`, 50 (states) + 50 (capitals)

Also, the input data is packed as a single string and then split. The string could be compressed to golf it further.

Edit: added some unoptimized substitution of pairs of characters.
> 5 votes

# Answer
## Javascript, ~~1057~~ 1042 bytes

Answer 1: 1042

```
(()=>{for(i=0,b=prompt(),c='Baton Rouge,Louisiana,Indianapolis,Indiana,Columbus,Ohio,Montgomery,Alabama,Helena,Montana,Denver,Colorado,Boise,Idaho,Austin,Texas,Boston,Massachusetts,Albany,New York,Tallahassee,Florida,Santa Fe,New Mexico,Nashville,Tennessee,Trenton,New Jersey,Jefferson,Missouri,Richmond,Virginia,Pierre,South Dakota,Harrisburg,Pennsylvania,Augusta,Maine,Providence,Rhode Island,Dover,Delaware,Concord,New Hampshire,Montpelier,Vermont,Hartford,Connecticut,Topeka,Kansas,Saint Paul,Minnesota,Juneau,Alaska,Lincoln,Nebraska,Raleigh,North Carolina,Madison,Wisconsin,Olympia,Washington,Phoenix,Arizona,Lansing,Michigan,Honolulu,Hawaii,Jackson,Mississippi,Springfield,Illinois,Columbia,South Carolina,Annapolis,Maryland,Cheyenne,Wyoming,Salt Lake City,Utah,Atlanta,Georgia,Bismarck,North Dakota,Frankfort,Kentucky,Salem,Oregon,Little Rock,Arkansas,Des Moines,Iowa,Sacramento,California,Oklahoma City,Oklahoma,Charleston,West Virginia,Carson City,Nevada'.split(","),q="Arstotzka";i<100;i++){if(c[i]==b)q=c[i%2?i-1:i+1];}return q})()

```

Updated Answer 1 missed a zero :S, Also fixed general incorrectness Updated Answer 1 + 2 re-arranged structure a bit.

*Answer 1 is recommended to be run in a Javascript console (your browser's, for example) an unnamed function that returns to the console. You can also test it here.*

Answer 2 1049

```
alert((()=>{for(i=0,b=prompt(),c='Baton Rouge,Louisiana,Indianapolis,Indiana,Columbus,Ohio,Montgomery,Alabama,Helena,Montana,Denver,Colorado,Boise,Idaho,Austin,Texas,Boston,Massachusetts,Albany,New York,Tallahassee,Florida,Santa Fe,New Mexico,Nashville,Tennessee,Trenton,New Jersey,Jefferson,Missouri,Richmond,Virginia,Pierre,South Dakota,Harrisburg,Pennsylvania,Augusta,Maine,Providence,Rhode Island,Dover,Delaware,Concord,New Hampshire,Montpelier,Vermont,Hartford,Connecticut,Topeka,Kansas,Saint Paul,Minnesota,Juneau,Alaska,Lincoln,Nebraska,Raleigh,North Carolina,Madison,Wisconsin,Olympia,Washington,Phoenix,Arizona,Lansing,Michigan,Honolulu,Hawaii,Jackson,Mississippi,Springfield,Illinois,Columbia,South Carolina,Annapolis,Maryland,Cheyenne,Wyoming,Salt Lake City,Utah,Atlanta,Georgia,Bismarck,North Dakota,Frankfort,Kentucky,Salem,Oregon,Little Rock,Arkansas,Des Moines,Iowa,Sacramento,California,Oklahoma City,Oklahoma,Charleston,West Virginia,Carson City,Nevada'.split(","),q="Arstotzka";i<100;i++){if(c[i]==b)q=c[i%2?i-1:i+1];}return q})())
```

Answer 2 will work with the code snippet button
> 3 votes

# Answer
# Ruby, 989 bytes

```
->s{a="Baton Rouge|Louisiana|Indianapolis|Indiana|Columbus|Ohio|Montgomery|Alabama|Helena|Montana|Denver|Colorado|Boise|Idaho|Austin|Texas|Boston|Massachusetts|Albany|New York|Tallahassee|Florida|Santa Fe|New Mexico|Nashville|Tennessee|Trenton|New Jersey|Jefferson|Missouri|Richmond|Virginia|Pierre|South Dakota|Harrisburg|Pennsylvania|Augusta|Maine|Providence|Rhode Island|Dover|Delaware|Concord|New Hampshire|Montpelier|Vermont|Hartford|Connecticut|Topeka|Kansas|Saint Paul|Minnesota|Juneau|Alaska|Lincoln|Nebraska|Raleigh|North Carolina|Madison|Wisconsin|Olympia|Washington|Phoenix|Arizona|Lansing|Michigan|Honolulu|Hawaii|Jackson|Mississippi|Springfield|Illinois|Columbia|South Carolina|Annapolis|Maryland|Cheyenne|Wyoming|Salt Lake City|Utah|Atlanta|Georgia|Bismarck|North Dakota|Frankfort|Kentucky|Salem|Oregon|Little Rock|Arkansas|Des Moines|Iowa|Sacramento|California|Oklahoma City|Oklahoma|Charleston|West Virginia|Carson City|Nevada".split(?|)
i=a.index(s)
i ?a[i^1]:"Arstotzka"}

```

Split the data into a single array. Find the index of the input in the array (`index` returns a falsy value of `nil` if the input is not there)

If falsy, return "Arstotzka" otherwise XOR the index with 1 to find the other member of the pair

**In test program:**

```
f=->s{a="Baton Rouge|Louisiana|Indianapolis|Indiana|Columbus|Ohio|Montgomery|Alabama|Helena|Montana|Denver|Colorado|Boise|Idaho|Austin|Texas|Boston|Massachusetts|Albany|New York|Tallahassee|Florida|Santa Fe|New Mexico|Nashville|Tennessee|Trenton|New Jersey|Jefferson|Missouri|Richmond|Virginia|Pierre|South Dakota|Harrisburg|Pennsylvania|Augusta|Maine|Providence|Rhode Island|Dover|Delaware|Concord|New Hampshire|Montpelier|Vermont|Hartford|Connecticut|Topeka|Kansas|Saint Paul|Minnesota|Juneau|Alaska|Lincoln|Nebraska|Raleigh|North Carolina|Madison|Wisconsin|Olympia|Washington|Phoenix|Arizona|Lansing|Michigan|Honolulu|Hawaii|Jackson|Mississippi|Springfield|Illinois|Columbia|South Carolina|Annapolis|Maryland|Cheyenne|Wyoming|Salt Lake City|Utah|Atlanta|Georgia|Bismarck|North Dakota|Frankfort|Kentucky|Salem|Oregon|Little Rock|Arkansas|Des Moines|Iowa|Sacramento|California|Oklahoma City|Oklahoma|Charleston|West Virginia|Carson City|Nevada".split(?|)
i=a.index(s)
i ?a[i^1]:"Arstotzka"}

puts f[gets.chop]

```
> 2 votes

# Answer
# PHP, 674 bytes

```
<?php $a=explode("\n",gzinflate('=SÛŽê0.|÷WôWº =Àr.p..GÓšÆj.WN.ÛýúãÀ²R¥ÞÆžñxRkL’¾{„7L.ªƒäŽ`-™#c@X†¶ÜGñ._/0.Ÿ‡KŽ°s,°‘.:.H\'¨=^p@X.\'Ã•?.?§p#-e¢Ø.¼.G‚e‹N Î1q€.}a´.¦&À.cÄÆåH)EkzÁ0Á–îÕ?Ñ.Nè=:ƒ.Á»uä.áˆÆT½Ó.µ¡/n.¶.Ý.½\'k..=ð\'¥P..lE.i‚.]¯öTh9FÉÊpàÆ..Zødí80ÂžI•à(9¹jŽ½$..U9^²v°7‚8ù..l.;›É¦G..{•.·..‚ƒ“–ªeôh.çR,™“Ç;Zç™„F´}.[à0FÇöµ.8’7rø$5I©°¦kAZE &q“.œd$[á.†h...8U{ÌÞF*“.µ«..sÙP4äš.Î...úøp@OÜ9ØŠÚ„3T[xÙ ¶\¬9sl$D[ÔÎOÃhSžÍ].]1sï„..A.ü-V´Æ‚ìŒ¼qÜa€….KŒÏ&þŽÌ°Â¦..^®qd8Žj5W&ßÂÒ.¹eä\'hÆö4þWV.^‘Ü N.?gŽ¦²f8O2.ö#úT.±§jÆi‚¿..ÔÉ— À..[¬ežã€Úô?cÿ,ö]1ôæq‚.KKnú©4£.vJ.É^sJžì¨Xa.ýÓô9Åj#¶q;&r/‰l.‡’6˜¡gkW²±ë-º2àSÓëÍÄ£zzdÿl·ê7w6±.õDoé†-þ.'));$b=array_search($argv[1],$a);echo $a[$b?$b%2?$b+1:$b-1:0];

```

Hex:

```
00000000: 3C 3F 70 68 70 20 24 61 - 3D 65 78 70 6C 6F 64 65 |<?php $a=explode|
00000010: 28 22 5C 6E 22 2C 67 7A - 69 6E 66 6C 61 74 65 28 |("\n",gzinflate(|
00000020: 27 3D 53 DB 8E EA 30 0C - 7C F7 57 F4 57 BA A0 3D |'=S   0 | W W  =|
00000030: C0 72 13 70 16 9D 47 D3 - 9A C6 6A 1A 57 4E 02 DB | r p  G   j WN  |
00000040: FD FA E3 C0 B2 52 A5 DE - C6 9E F1 78 52 6B 4C 92 |     R     xRkL |
00000050: BE 7B 84 37 4C 12 AA 83 - E4 8E 60 2D 99 23 63 40 | { 7L     `- #c@|
00000060: 58 86 B6 DC 47 F1 1C 5F - 2F 30 13 9F 87 4B 8E B0 |X   G  _/0   K  |
00000070: 73 2C B0 91 90 3A 19 48 - 5C 27 A8 3D 5E 70 40 58 |s,   : H\' =^p@X|
00000080: 90 5C 27 C3 95 3F 05 3F - A7 70 23 2D 65 A2 D8 0A | \'  ? ? p#-e   |
00000090: BC 09 47 82 65 8B 4E A0 - CE 31 71 80 13 7D 61 B4 |  G e N  1q  }a |
000000a0: 1F A6 26 C0 06 63 C4 C6 - E5 48 29 45 6B 7A C1 30 |  &  c   H)Ekz 0|
000000b0: C1 96 EE D5 3F D1 1E 4E - E8 3D 3A 83 10 C1 BB 75 |    ?  N =:    u|
000000c0: E4 16 E1 88 C6 54 BD D3 - 03 B5 A1 2F 6E 04 B6 18 |     T     /n   |
000000d0: DD 8D BD 5C 27 6B 1E 02 - 3D F0 5C 27 A5 50 18 0A |   \'k  = \' P  |
000000e0: 6C 45 1A 69 82 15 5D AF - F6 54 68 39 46 C9 CA 70 |lE i  ]  Th9F  p|
000000f0: E0 C6 0D 12 5A F8 64 ED - 38 30 C2 9E 49 95 E0 28 |    Z d 80  I  (|
00000100: 39 B9 6A 8E BD 24 1B 12 - 55 39 5E B2 76 B0 37 82 |9 j  $  U9^ v 7 |
00000110: 38 F9 1B 16 6C 9D 3B 9B - C9 A6 47 0E 04 7B 95 1B |8   l ;   G  {  |
00000120: B7 14 1A 82 83 93 96 AA - 65 F4 68 AD E7 52 2C 99 |        e h  R, |
00000130: 93 C7 3B 5A E7 99 84 46 - B4 7D 08 5B E0 30 46 C7 |  ;Z   F } [ 0F |
00000140: F6 B5 18 38 92 37 72 F8 - 24 35 49 A9 B0 A6 6B 41 |   8 7r $5I   kA|
00000150: 5A 45 A0 26 71 93 13 9C - 64 24 5B E1 07 86 68 2E |ZE &q   d$[   h.|
00000160: 1E 8D 38 55 7B CC DE 46 - 2A 93 17 B5 AB 1C 08 73 |  8U{  F*      s|
00000170: D9 50 34 E4 9A 8D CE 17 - 1F 2E FA F8 70 40 4F DC | P4      .  p@O |
00000180: 39 D8 8A DA 84 33 54 5B - 78 D9 20 B6 5C AC 39 73 |9    3T[x   \ 9s|
00000190: 6C 24 44 5B D4 CE 4F C3 - 68 53 9E CD 5D 0E 5D 31 |l$D[  O hS  ] ]1|
000001a0: 73 EF 84 02 7F 41 AD FC - 2D 56 B4 C6 82 EC 8C BC |s    A  -V      |
000001b0: 71 DC 61 80 85 04 4B 8C - CF 26 FE 8E CC B0 C2 A6 |q a   K  &      |
000001c0: 7F 19 5E AE 71 64 38 8E - 6A 35 57 26 DF C2 D2 1B |  ^ qd8 j5W&    |
000001d0: B9 65 E4 5C 27 68 C6 F6 - 34 FE 57 56 1D 5E 91 DC | e \'h  4 WV ^  |
000001e0: A0 4E 0F 3F 67 8E A6 B2 - 66 38 4F 32 14 F6 23 FA | N ?g   f8O2  # |
000001f0: 54 AD B1 A7 6A C6 69 82 - BF 09 1D D4 C9 97 A0 C0 |T   j i         |
00000200: 1F 12 5B AC 65 9E E3 80 - DA F4 3F 63 FF 2C F6 5D |  [ e     ?c , ]|
00000210: 31 F4 E6 71 82 0F 4B 4B - 6E FA A9 34 A3 01 76 4A |1  q  KKn  4  vJ|
00000220: 9D C9 5E 73 4A 9E EC A8 - 58 61 AD FD D3 F4 39 C5 |  ^sJ   Xa    9 |
00000230: 6A 23 B6 71 3B 26 72 2F - 89 6C 14 87 92 36 98 A1 |j# q;&r/ l   6  |
00000240: 67 6B 57 B2 B1 EB 2D BA - 32 E0 53 D3 EB CD C4 A3 |gkW   - 2 S     |
00000250: 7A 7A 64 FF 6C B7 EA 37 - 77 36 B1 19 F5 44 6F E9 |zzd l  7w6   Do |
00000260: 86 2D FE 07 27 29 29 3B - 24 62 3D 61 72 72 61 79 | -  '));$b=array|
00000270: 5F 73 65 61 72 63 68 28 - 24 61 72 67 76 5B 31 5D |_search($argv[1]|
00000280: 2C 24 61 29 3B 65 63 68 - 6F 20 24 61 5B 24 62 3F |,$a);echo $a[$b?|
00000290: 24 62 25 32 3F 24 62 2B - 31 3A 24 62 2D 31 3A 30 |$b%2?$b+1:$b-1:0|
000002a0: 5D 3B                   -                         |];|
000002a2;

```

Explanation

```
<?php
// create array of capitals and states
$a = explode("\n", gzinflate(/* Arstotzka
                                Baton Rouge
                                Louisiana
                                Indianapolis
                                Indiana
                                ...
                             */));
$b = array_search($argv[1], $a); // find user input in list
echo $a[
  $b          // if $b is nonzero, the match succeded
    ?$b % 2   // checks if $b is odd, indicating a capital
      ?$b + 1 // $b points to capital; return the next item, the state
      :$b - 1 // $b points to state; return the previous item, the capital
    :0        // select "Arstotzka" otherwise
];

```
> 2 votes

# Answer
## Python 2.7, ~~1271~~ ~~1232~~ 1054 bytes

```
y='Little Rock,Boise,Richmond,Denver,Olympia,Sacramento,Springfield,Baton Rouge,Tallahassee,Austin,Trenton,Lansing,Annapolis,Dover,Phoenix,Pierre,Charleston,Salt Lake City,Montpelier,Indianapolis,Concord,Providence,Madison,Oklahoma City,Santa Fe,Frankfort,Columbia,Atlanta,Boston,Salem,Juneau,Bismarck,Helena,Montgomery,Des Moines,Saint Paul,Jefferson,Lincoln,Hartford,Augusta,Carson City,Albany,Cheyenne,Columbus,Harrisburg,Honolulu,Raleigh,Nashville,Jackson,Topeka'.split(',')
z='Arkansas,Idaho,Virginia,Colorado,Washington,California,Illinois,Louisiana,Florida,Texas,New Jersey,Michigan,Maryland,Delaware,Arizona,South Dakota,West Virginia,Utah,Vermont,Indiana,New Hampshire,Rhode Island,Wisconsin,Oklahoma,New Mexico,Kentucky,South Carolina,Georgia,Massachusetts,Oregon,Alaska,North Dakota,Montana,Alabama,Iowa,Minnesota,Missouri,Nebraska,Connecticut,Maine,Nevada,New York,Wyoming,Ohio,Pennsylvania,Hawaii,North Carolina,Tennessee,Mississippi,Kansas'.split(',')
def a(b):
 m='Arstotzka'
 if b in y:m=z[y.index(b)]
 if b in z:m=y[z.index(b)]
 print m

```

Example I/O:

```
>>> a('Baton Rouge')
Louisiana
>>> a('Montana')
Helena
>>> a('asdfghjkl;')
Arstotzka

```

*Edit: way improved*
> 1 votes

# Answer
## Perl 5 , 1029 bytes

```
$h{$h{$_}}=$_ for keys{%h=(Indianapolis,Indiana,Columbus,Ohio,Montgomery,Alabama,Helena,Montana,Denver,Colorado,Boise,Idaho,Austin,Texas,Boston,Massachusetts,Tallahassee,Florida,Nashville,Tennessee,Jefferson,Missouri,Richmond,Virginia,Harrisburg,Pennsylvania,Augusta,Maine,Dover,Delaware,Montpelier,Vermont,Hartford,Connecticut,Topeka,Kansas,Juneau,Alaska,Lincoln,Nebraska,Madison,Wisconsin,Olympia,Washington,Phoenix,Arizona,Lansing,Michigan,Honolulu,Hawaii,Jackson,Mississippi,Springfield,Illinois,Annapolis,Maryland,Cheyenne,Wyoming,Atlanta,Georgia,Frankfort,Kentucky,Salem,Oregon,Sacramento,California,Charleston,'West Virginia','Carson City',Nevada,'Baton Rouge',Louisiana,Albany,'New York','Santa Fe','New Mexico','Trenton','New Jersey',Pierre,'South Dakota',Providence,'Rhode Island',Concord,'New Hampshire','Saint Paul',Minnesota,Raleigh,'North Carolina',Columbia,'South Carolina','Salt Lake City',Utah,Bismarck,'North Dakota','Little Rock',Arkansas,'Des Moines',Iowa,'Oklahoma City',Oklahoma)};say$h{$ARGV[0]}//Arstotzka

```
> 1 votes

# Answer
## T-SQL, 1402 bytes (counting size of .sql file)

```
create table t(s varchar(99),c varchar(99))insert into t values('Baton Rouge','Louisiana'),('Indianapolis','Indiana'),('Columbus','Ohio'),('Montgomery','Alabama'),('Helena','Montana'),('Denver','Colorado'),('Boise','Idaho'),('Austin','Texas'),('Boston','Massachusetts'),('Albany','New York'),('Tallahassee','Florida'),('Santa Fe','New Mexico'),('Nashville','Tennessee'),('Trenton','New Jersey'),('Jefferson','Missouri'),('Richmond','Virginia'),('Pierre','South Dakota'),('Harrisburg','Pennsylvania'),('Augusta','Maine'),('Providence','Rhode Island'),('Dover','Delaware'),('Concord','New Hampshire'),('Montpelier','Vermont'),('Hartford','Connecticut'),('Topeka','Kansas'),('Saint Paul','Minnesota'),('Juneau','Alaska'),('Lincoln','Nebraska'),('Raleigh','North Carolina'),('Madison','Wisconsin'),('Olympia','Washington'),('Phoenix','Arizona'),('Lansing','Michigan'),('Honolulu','Hawaii'),('Jackson','Mississippi'),('Springfield','Illinois'),('Columbia','South Carolina'),('Annapolis','Maryland'),('Cheyenne','Wyoming'),('Salt Lake City','Utah'),('Atlanta','Georgia'),('Bismarck','North Dakota'),('Frankfort','Kentucky'),('Salem','Oregon'),('Little Rock','Arkansas'),('Des Moines','Iowa'),('Sacramento','California'),('Oklahoma City','Oklahoma'),('Charleston','West Virginia'),('Carson City','Nevada') declare @i varchar(99) = 'Austin' select coalesce((select s from t where c = @i union select c from t where s = @i),(select 'Arstotzka'))

```

Fort this kind of task set logic trumps procedural logic making easy and fast to solve it on a relational DB.

Below the ungolfed code. Note we can just run the create/populate part once in a separate batch

```
create table t
(
     s varchar(99)
    ,c varchar(99)
)

insert into t
 values
 ('Baton Rouge','Louisiana')
,('Indianapolis','Indiana')
,('Columbus','Ohio')
,('Montgomery','Alabama')
,('Helena','Montana')
,('Denver','Colorado')
,('Boise','Idaho')
,('Austin','Texas')
,('Boston','Massachusetts')
,('Albany','New York')
,('Tallahassee','Florida')
,('Santa Fe','New Mexico')
,('Nashville','Tennessee')
,('Trenton','New Jersey')
,('Jefferson','Missouri')
,('Richmond','Virginia')
,('Pierre','South Dakota')
,('Harrisburg','Pennsylvania')
,('Augusta','Maine')
,('Providence','Rhode Island')
,('Dover','Delaware')
,('Concord','New Hampshire')
,('Montpelier','Vermont')
,('Hartford','Connecticut')
,('Topeka','Kansas')
,('Saint Paul','Minnesota')
,('Juneau','Alaska')
,('Lincoln','Nebraska')
,('Raleigh','North Carolina')
,('Madison','Wisconsin')
,('Olympia','Washington')
,('Phoenix','Arizona')
,('Lansing','Michigan')
,('Honolulu','Hawaii')
,('Jackson','Mississippi')
,('Springfield','Illinois')
,('Columbia','South Carolina')
,('Annapolis','Maryland')
,('Cheyenne','Wyoming')
,('Salt Lake City','Utah')
,('Atlanta','Georgia')
,('Bismarck','North Dakota')
,('Frankfort','Kentucky')
,('Salem','Oregon')
,('Little Rock','Arkansas')
,('Des Moines','Iowa')
,('Sacramento','California')
,('Oklahoma City','Oklahoma')
,('Charleston','West Virginia')
,('Carson City','Nevada')

```

And with that data persisted only use this query

```
declare @i varchar(99) = 'Austin'

select coalesce(
    (
       select s from t
       where c = @i

       union

       select c from t where s = @i
    ),
    (select 'Arstotzka')
)

```

The variable declaration is not mandatory, of course you can just put the input directly in the query and spare 10 bytes but I prefer my queries parametized.
> 1 votes

# Answer
## Perl 5, 999 bytes

My first post in codegolf.

```
%m;@r=qw/la ol ia nt en or is an in on/;map{$x=$_;$x=~s/$_/$r[$_]/eg for(0..9);$x=~s/\b(\w)/\U$1/g;($c,$s)=split'\|',$x;$m{$c}=$s;$m{$s}=$c}qw(bat9_rouge|lou62na 8d2nap16|8d2na c1umbus|ohio mo3gomery|a0bama hel4a|mo37a d4ver|c15ado bo6e|idaho aust8|texas bost9|massachusetts alb7y|new_y5k tal0hassee|fl5ida sa3a_fe|new_mexico nashville|t4nessee tre39|new_jersey jeffers9|m6souri richm9d|virg82 pierre|south_dakota harr6burg|p4nsylv72 augusta|ma8e provid4ce|rhode_60nd dover|de0ware c9c5d|new_hampshire mo3pelier|vermo3 hartf5d|c9necticut topeka|k7sas sai3_paul|m8nesota juneau|a0ska l8c1n|nebraska raleigh|n5th_car18a mad69|w6c9s8 1ymp2|wash8gt9 pho4ix|ariz9a 0ns8g|michig7 h91ulu|hawaii jacks9|m6s6sippi spr8gfield|ill8o6 c1umb2|south_car18a 7nap16|mary0nd chey4ne|wyom8g salt_0ke_city|utah at03a|ge5g2 b6marck|n5th_dakota fr7kf5t|ke3ucky salem|5eg9 little_rock|ark7sas des_mo8es|iowa sacrame3o|calif5n2 ok0homa_city|ok0homa charlest9|west_virg82 cars9_city|nevada);print $m{$ARGV[0]}||"Arstotzka"

```

Ungolfed:

```
%m;
@r=qw/la ol ia nt en or is an in on/; # Top 10 bigrams
map{
    $x=$_;
    $x=~s/$_/$r[$_]/eg for(0..9); # Resolve bigram placeholders
    $x=~s/\b(\w)/\U$1/g;          # ucfirst each word
    ($c,$s)=split'\|',$x;         # split city and state
    $m{$c}=$s;                    # key on both city and state
    $m{$s}=$c
} qw(
    bat9_rouge|lou62na
    8d2nap16|8d2na
    c1umbus|ohio
    mo3gomery|a0bama
    hel4a|mo37a
    d4ver|c15ado
    bo6e|idaho
    aust8|texas
    bost9|massachusetts
    alb7y|new_y5k
    tal0hassee|fl5ida
    sa3a_fe|new_mexico
    nashville|t4nessee
    tre39|new_jersey
    jeffers9|m6souri
    richm9d|virg82
    pierre|south_dakota
    harr6burg|p4nsylv72
    augusta|ma8e
    provid4ce|rhode_60nd
    dover|de0ware
    c9c5d|new_hampshire
    mo3pelier|vermo3
    hartf5d|c9necticut
    topeka|k7sas
    sai3_paul|m8nesota
    juneau|a0ska
    l8c1n|nebraska
    raleigh|n5th_car18a
    mad69|w6c9s8
    1ymp2|wash8gt9
    pho4ix|ariz9a
    0ns8g|michig7
    h91ulu|hawaii
    jacks9|m6s6sippi
    spr8gfield|ill8o6
    c1umb2|south_car18a
    7nap16|mary0nd
    chey4ne|wyom8g
    salt_0ke_city|utah
    at03a|ge5g2
    b6marck|n5th_dakota
    fr7kf5t|ke3ucky
    salem|5eg9
    little_rock|ark7sas
    des_mo8es|iowa
    sacrame3o|calif5n2
    ok0homa_city|ok0homa
    charlest9|west_virg82
    cars9_city|nevada
);
print $m{$ARGV[0]}||"Arstotzka"

```
> 1 votes

# Answer
# Haskell, ~~1077~~ ~~1069~~ ~~1068~~ 1063 bytes

```
z s=last$"Arstotzka":[last$l:[r|s==l]|(l,_:r)<-span(<'~')<$>lines"Baton Rouge~Louisiana\nIndianapolis~Indiana\nColumbus~Ohio\nMontgomery~Alabama\nHelena~Montana\nDenver~Colorado\nBoise~Idaho\nAustin~Texas\nBoston~Massachusetts\nAlbany~New York\nTallahassee~Florida\nSanta Fe~New Mexico\nNashville~Tennessee\nTrenton~New Jersey\nJefferson~Missouri\nRichmond~Virginia\nPierre~South Dakota\nHarrisburg~Pennsylvania\nAugusta~Maine\nProvidence~Rhode Island\nDover~Delaware\nConcord~New Hampshire\nMontpelier~Vermont\nHartford~Connecticut\nTopeka~Kansas\nSaint Paul~Minnesota\nJuneau~Alaska\nLincoln~Nebraska\nRaleigh~North Carolina\nMadison~Wisconsin\nOlympia~Washington\nPhoenix~Arizona\nLansing~Michigan\nHonolulu~Hawaii\nJackson~Mississippi\nSpringfield~Illinois\nColumbia~South Carolina\nAnnapolis~Maryland\nCheyenne~Wyoming\nSalt Lake City~Utah\nAtlanta~Georgia\nBismarck~North Dakota\nFrankfort~Kentucky\nSalem~Oregon\nLittle Rock~Arkansas\nDes Moines~Iowa\nSacramento~California\nOklahoma City~Oklahoma\nCharleston~West Virginia\nCarson City~Nevada",s==l||s==r]

```

Try it online!

After wasting a lot of time trying to golf an implementation of Huffman coding I realized the straightforward approach is probably shorter. Ah, well.

EDIT: Thanks to @Laikoni for taking off 8 bytes!

EDIT: Thanks again Laikoni for that additional byte. Good idea to use '~'

EDIT: Thanks to Laikoni for taking off those 5 bytes!
> 1 votes

# Answer
# Zsh, ~~993 928~~ 924 bytes

***-4 bytes** thanks to @spuck's Bash answer, replacing `th Dakota` and `th Carolina`*

```
a=(_ Bat4\ Rouge Lou7i5a Indi5apol7 Indi5a Columbus Ohio M4tgomery Alabama Hel8a M4t5a D8ver Col9ado Bo7e Idaho Aust6 Texas Bost4 Massachusetts Alb5y New\ Y9k Tallahassee Fl9ida S5ta\ Fe New\ Mexico Nashville T8nessee Tr8t4 New\ Jersey Jeffers4 M7souri Richm4d Virg6ia Pierre Sou3 Harr7burg P8nsylv5ia Augusta Ma6e Provid8ce Rhode\ 7l5d Dover Delaware C4c9d New\ Hampshire M4tpelier Verm4t Hartf9d C4necticut Topeka K5sas Sa6t\ Paul M6nesota Juneau Alaska L6coln Nebraska Raleigh N92 Mad74 W7c4s6 Olympia Wash6gt4 Pho8ix Ariz4a L5s6g Michig5 H4olulu Hawaii Jacks4 M7s7sippi Spr6gfield Ill6o7 Columbia Sou2 5napol7 Maryl5d Chey8ne Wyom6g Salt\ Lake1 Utah Atl5ta Ge9gia B7marck N93 Fr5kf9t K8tucky Salem 9eg4 Little\ Rock Ark5sas Des\ Mo6es Iowa Sacram8to Calif9nia 01 0 Charlest4 West\ Virg6ia Cars41 Nevada)
for w (Oklahoma \ City th\ Carol6a th\ Dakota on an in is en or)a=(${a//$[i++]/$w})
<<<${a[$a[(ie)$1]^1]:-Arstotzka}

```

~~Try it online! Try it online!~~  Try it online!

Manual compression by replacing numbers 0..9 in the array.

Because Zsh uses 1-indexed arrays, we have to add a dummy element at the start.

`$a[(i)$1]` gets the index of the matching array element. Adding the `(e)` flag disables pattern matching and uses plain string matching. If we don't do this, `Ut*` matches `Utah` and we will print `Carson City`. If the element is not found, this returns an index beyond the end of the array.

We then xor with 1 and get the corresponding paired element. If our dummy element at index 1 was matched, this will be `$a[0]`, which substitutes the empty string. In any case, if this is empty, `${ :-Arstotzka}` will substitute Arstotzka instead.
> 1 votes

# Answer
# Bash, 927 ~~978~~ ~~1003~~ ~~1051~~ ~~976~~ bytes

One more edit, reducing bytes taken by spaces and newlines in $T.

Also re-ordered the substitution for 0..9, fixing a problem handling "Carol1a", since the substitution of 1-\>"in" would have already been accomplished before that point.

Editing my answer after @GammaFuntion's comment below; I was not meeting the original rules to handle all input; a string that partially matched a state or capital would give wrong output.

His/Her Zsh answer inspired me to also use the XOR rather than the modulo 100 indexing and to do some manual compression using numerals 0..9. I wrote a script to do some quick and dirty calculations on the input list to decide which ten strings would give the best byte reduction. Then used that script iteratively to reduce the strings. Check it out here: Try it online!

```
T="Bat8.RougeLou3i2aIndi2apol3Indi2aColumbusOhioM8tgom9yAlabamaHel6aM8t2aD6v9Col5adoBo3eIdahoAust4Tex7Bost8M7sachusettsAlb2yNew.Y5kTallah7seeFl5idaS2ta.FeNew.MexicoN7hvilleT6nesseeTr6t8New.J9seyJeff9s8M3souriRichm8dVirg4iaPi9reSou0Harr3burgP6nsylv2iaAugustaMa4eProvid6ceRhode.Isl2dDov9DelawareC8c5dNew.HampshireM8tpeli9V9m8tHartf5dC8necticutTopekaK2s7Sa4t.PaulM4nesotaJuneauAl7kaL4colnNebr7kaRaleighN51Mad38W3c8s4OlympiaW7h4gt8Pho6ixAriz8aL2s4gMichig2H8oluluHawaiiJacks8M3s3sippiSpr4gfieldIll4o3ColumbiaSou1Annapol3Maryl2dChey6neWyom4gSalt.Lake.CityUtahAtl2taGe5giaB3marckN50Fr2kf5tK6tuckySalemOreg8Little.RockArk2s7Des.Mo4esIowaSacram6toCalif5niaOklahoma.CityOklahomaCharlest8West.Virg4iaCars8.CityNevada"
for t in th.Dakota th.Carol4a an is in or en as on er;{ T=${T//$[j++]/$t};}
for t in {A..Z};{ T=${T//$t/ $t};}
S=${T//. /.}
U=($S)
for s in $S;{ [ "${s//./ }" = "$1" ]&&echo ${U[i^1]//./ }&&exit;i=$[i+1];}
echo Arstotzka

```

Try it online!

~~Try it online!~~

~~Try it online!~~

~~Try it online!~~

~~Try it online!~~
> 1 votes

# Answer
# Prolog, 1221 bytes

```
p(X):-L=['Baton Rouge','Louisiana','Indianapolis','Indiana','Columbus','Ohio','Montgomery','Alabama','Helena','Montana','Denver','Colorado','Boise','Idaho','Austin','Texas','Boston','Massachusetts','Albany','New York','Tallahassee','Florida','Santa Fe','New Mexico','Nashville','Tennessee','Trenton','New Jersey','Jefferson','Missouri','Richmond','Virginia','Pierre','South Dakota','Harrisburg','Pennsylvania','Augusta','Maine','Providence','Rhode Island','Dover','Delaware','Concord','New Hampshire','Montpelier','Vermont','Hartford','Connecticut','Topeka','Kansas','Saint Paul','Minnesota','Juneau','Alaska','Lincoln','Nebraska','Raleigh','North Carolina','Madison','Wisconsin','Olympia','Washington','Phoenix','Arizona','Lansing','Michigan','Honolulu','Hawaii','Jackson','Mississippi','Springfield','Illinois','Columbia','South Carolina','Annapolis','Maryland','Cheyenne','Wyoming','Salt Lake City','Utah','Atlanta','Georgia','Bismarck','North Dakota','Frankfort','Kentucky','Salem','Oregon','Little Rock','Arkansas','Des Moines','Iowa','Sacramento','California','Oklahoma City','Oklahoma','Charleston','West Virginia','Carson City','Nevada'],nth0(I,L,X),J is I xor 1,nth0(J,L,E),write(E),!.
p(X):-write('Arstotzka').

```

Most of the byte count comes from the list of states and capitals.
All names of states and capitals need to be quoted atoms since they begin with upper case letters, costing us 202 bytes in 's alone.
**How it works**

```
 nth0(I,L,X)

```

Gets index **I** of element **X** in list **L**.

```
J is I xor 1

```

Xor index with 1 to get index of return value.

```
nth0(J,L,E)

```

Gets element **E** at index **J** of list **L**.

If any rule fails, print Arstotzka

**Example**

```
>p('Austin').
Texas

>p('Texas').
Austin

```
> 0 votes

# Answer
## R, 1294 bytes

```
d=data.frame(a=c("Baton Rouge","Indianapolis","Columbus","Montgomery","Helena","Denver","Boise","Austin","Boston","Albany","Tallahassee","Santa Fe","Nashville","Trenton","Jefferson","Richmond","Pierre","Harrisburg","Augusta","Providence","Dover","Concord","Montpelier","Hartford","Topeka","Saint Paul","Juneau","Lincoln","Raleigh","Madison","Olympia","Phoenix","Lansing","Honolulu","Jackson","Springfield","Columbia","Annapolis","Cheyenne","Salt Lake City","Atlanta","Bismarck","Frankfort","Salem","Little Rock","Des Moines","Sacramento","Oklahoma City","Charleston","Carson City"),b=c("Louisiana","Indiana","Ohio","Alabama","Montana","Colorado","Idaho","Texas","Massachusetts","New York","Florida","New Mexico","Tennessee","New Jersey","Missouri","Virginia","South Dakota","Pennsylvania","Maine","Rhode Island","Delaware","New Hampshire","Vermont","Connecticut","Kansas","Minnesota","Alaska","Nebraska","North Carolina","Wisconsin","Washington","Arizona","Michigan","Hawaii","Mississippi","Illinois","South Carolina","Maryland","Wyoming","Utah","Georgia","North Dakota","Kentucky","Oregon","Arkansas","Iowa","California","Oklahoma","West Virginia","Nevada"),stringsAsFactors=F)
print(ifelse(any(e<-d[,1]%in%(n<-scan("","raw",sep='$'))),d[e,2],ifelse(any(f<-d[,2]%in%n),d[f,1],'Arstotzka')))

```

It is case senstive according to the input shown as example.

Ungolfed code (slightly different in the position of scan):

```
n<-scan("","raw",sep='$')
print(
  ifelse(
    any(e<-d[,1]%in%n), # test city
    d[e,2], # if yes return the state
    ifelse(
      any(f<-d[,2]%in%n), # test state
      d[f,1], # return city
      'Arstotzka'
    )
  )
)

```
> 0 votes

# Answer
# Java, 1312

```
public class a{public static void main(String[]x){List<String>a=Arrays.asList("Baton Rouge","Louisiana","Indianapolis", "Indiana","Columbus","Ohio", "Montgomery","Alabama","Helena","Montana","Denver","Colorado","Boise","Idaho","Austin","Texas","Boston","Massachusetts","Albany","New York","Tallahassee","Florida","Santa Fe","New Mexico","Nashville","Tennessee","Trenton","New Jersey","Jefferson","Missouri","Richmond","Virginia","Pierre","South Dakota","Harrisburg","Pennsylvania","Augusta","Maine","Providence","Rhode Island","Dover","Delaware","Concord","New Hampshire","Montpelier","Vermont","Hartford","Connecticut","Topeka","Kansas","Saint Paul","Minnesota","Juneau","Alaska","Lincoln","Nebraska","Raleigh","North Carolina","Madison","Wisconsin","Olympia","Washington","Phoenix","Arizona","Lansing","Michigan","Honolulu","Hawaii","Jackson","Mississippi","Springfield","Illinois","Columbia","South Carolina","Annapolis","Maryland","Cheyenne","Wyoming","Salt Lake City","Utah","Atlanta","Georgia","Bismarck","North Dakota","Frankfort","Kentucky","Salem","Oregon","Little Rock","Arkansas","Des Moines","Iowa","Sacramento","California","Oklahoma City","Oklahoma","Charleston","West Virginia","Carson City","Nevada");int b=a.indexOf(x[0]);String s=b<0?s="Arstotzka":a.get(b/2*2+((b+1)%2));System.out.print(s);}}

```
> 0 votes

# Answer
# Javascript, 1042

```
var x=prompt(),a="Baton Rouge,Louisiana,Indianapolis,Indiana,Columbus,Ohio,Montgomery,Alabama,Helena,Montana,Denver,Colorado,Boise,Idaho,Austin,Texas,Boston,Massachusetts,Albany,New York,Tallahassee,Florida,Santa Fe,New Mexico,Nashville,Tennessee,Trenton,New Jersey,Jefferson,Missouri,Richmond,Virginia,Pierre,South Dakota,Harrisburg,Pennsylvania,Augusta,Maine,Providence,Rhode Island,Dover,Delaware,Concord,New Hampshire,Montpelier,Vermont,Hartford,Connecticut,Topeka,Kansas,Saint Paul,Minnesota,Juneau,Alaska,Lincoln,Nebraska,Raleigh,North Carolina,Madison,Wisconsin,Olympia,Washington,Phoenix,Arizona,Lansing,Michigan,Honolulu,Hawaii,Jackson,Mississippi,Springfield,Illinois,Columbia,South Carolina,Annapolis,Maryland,Cheyenne,Wyoming,Salt Lake City,Utah,Atlanta,Georgia,Bismarck,North Dakota,Frankfort,Kentucky,Salem,Oregon,Little Rock,Arkansas,Des Moines,Iowa,Sacramento,California,Oklahoma City,Oklahoma,Charleston,West Virginia,Carson City,Nevada".split(","),b=a.indexOf(x),s=b<0?s="Arstotzka":a[Math.floor(b/2)*2+((b+1)%2)];alert(s);

```
> 0 votes

# Answer
# AWK, 1009 bytes

```
{split("Baton Rouge,Louisiana,Indianapolis,Indiana,Columbus,Ohio,Montgomery,Alabama,Helena,Montana,Denver,Colorado,Boise,Idaho,Austin,Texas,Boston,Massachusetts,Albany,New York,Tallahassee,Florida,Santa Fe,New Mexico,Nashville,Tennessee,Trenton,New Jersey,Jefferson,Missouri,Richmond,Virginia,Pierre,South Dakota,Harrisburg,Pennsylvania,Augusta,Maine,Providence,Rhode Island,Dover,Delaware,Concord,New Hampshire,Montpelier,Vermont,Hartford,Connecticut,Topeka,Kansas,Saint Paul,Minnesota,Juneau,Alaska,Lincoln,Nebraska,Raleigh,North Carolina,Madison,Wisconsin,Olympia,Washington,Phoenix,Arizona,Lansing,Michigan,Honolulu,Hawaii,Jackson,Mississippi,Springfield,Illinois,Columbia,South Carolina,Annapolis,Maryland,Cheyenne,Wyoming,Salt Lake City,Utah,Atlanta,Georgia,Bismarck,North Dakota,Frankfort,Kentucky,Salem,Oregon,Little Rock,Arkansas,Des Moines,Iowa,Sacramento,California,Oklahoma City,Oklahoma,Charleston,West Virginia,Carson City,Nevada,Arstotzka,",S,",")
for(x in S)if(S[x]==$0)break
$0=S[x-1+x%2*2]}1

```

Try it online!

If there's a way to shrink this, I'd be happy to hear about it. :)
> 0 votes

# Answer
# , ~~843~~ 829 bytes

```
-&.((<;._1'-rstotzk7Bat> Roug/Ind6?p@;5@umbus.o8gom4y,Hel97D9v4,Bo;e-ust=,Bost>-lb<y,Tal1h2se/Sa8a F/N2hvill/Tre8>,Jeff4s>,Richm>d,Pi4r/H3r;burg-ugust7Provid9c/Dov45>c:d.o8peli4,H3tf:d,Topek7Sai8 Paul,Juneau,L=c@n,Raleigh.ad;>,Olymp6,Pho9ix,L<s=g,H>@ulu,Jacks>Apr=gfield5@umb6-n?p@;5hey9n/Salt Lake City-t187B;m3ck,Fr<kf:tAalem,Little Rock,Des Mo=esAacrame8o,Ok1homa City5h3lest>53s> City0evad7West Virg=6,Ok1homa5alif:n6,Iowa-rk<s2,Oreg>,Ke8ucky0:th Dakot7Ge:g6,Utah,Wyom=g.3y1ndAouth C3@=7Ill=o;.;s;sippi,Hawaii.ichig<-riz>7W2h=gt>,W;c>s=0:th C3@=a0ebr2ka-1ska.=nesot7K<s25>necticut,V4mo80ew Hampshir/De1w3/Rhode Is1nd.a=/P9nsylv<6Aouth Dakot7Virg=6.;souri0ew J4sey,T9nesse/New Mexico,Fl:ida0ew Y:k.2sachusetts,Tex2,Idaho5@:ado.o8<a-1bam7Ohio,Ind6n7Lou;6?'rplc(45{21;/\a.),._2<\',A,Me,,Nlaasarer,Ciaa,ntenorisaninonnaol,S')i.<)

```

Try it online!
> 0 votes

---
Tags: code-golf, string, kolmogorov-complexity
---


title: How many spaces are there?

text:
# Question
Title: How many spaces are there?
Your task is to input a string, and output the number of spaces in the string.

This is code-golf, so least number of bytes win. Your

# Test Cases

Double quotes are not part of the test cases.

```
"test" => 0
"Hello, World!" => 1
"C O D E G O L F" => 7
"      " => 6

```

# Answer
> 6 votes
# APL (Dyalog Extended), 3 bytesSBCS

```
+/=

```

Try it online!

`+/` sum the mask where `=` equal to the prototypical element of that element, which is space for characters.

# Answer
> 4 votes
# Whitespace, 93 bytes

```
[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_top][S N
S _Duplicate_top][T N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve_input][S S S T    S T S N
_Push_10][T S S T   _Subtract][S N
S _Duplicate_top][N
T   S T N
_If_0_jump_to_label_DONE][S S S T   S T T   S N
_Push_22][T S S T   _Subtract][N
T   S S N
_If_0_jump_to_label_SPACE][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_SPACE][S S S T    N
_Push_1][T  S S S _Add][N
S N
N
_Jump_to_Label_LOOP][N
S S T   N
_Create_Label_DONE][S N
N
_Discard_top][T N
S T _Print_as_integer]

```

Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.
`[..._some_action]` added as explanation only.

Since Whitespace inputs one character at a time, the input should contain a trailing newline so it knows when to stop reading characters and the input is done.

Try it online (with raw spaces, tabs and new-lines only).

An appropriate language for the challenge I guess. PS: The program itself contains 44 spaces.

**Explanation in pseudo-code:**

```
Integer counter = 0
Start LOOP:
  Character c = STDIN as character
  If(c == ' '):
    Call function SPACE
  Else-if(c == '\n'):
    Call function DONE
  Go to next iteration of LOOP

function SPACE:
  counter = counter + 1
  Go to next iteration of LOOP

function DONE:
  Print counter as integer to STDOUT

```

# Answer
> 3 votes
# 05AB1E, 3 2 bytes

```
ð¢

```

Try it online!

Simple explanation:

```
 ð  Pushes ' ' space character onto stack
  ¢ Counts the spaces in the input string

```

Found the 'ð' Command which saves 1 Byte for pushing a space.

# Answer
> 2 votes
# , 8 bytes

```
1#.' '=]

```

Try it online!

# Answer
> 1 votes
# PHP, 26 bytes

```
<?=count_chars($argn)[32];

```

Try it online!

# Answer
> 1 votes
# C# (Visual C# Interactive Compiler), 20 bytes

I really hope this is not optimal

```
a=>a.Count(b=>b==32)

```

Try it online!

# Answer
> 1 votes
# K (ngn/k), ~~6~~ 4 bytes

-2 byte thanks to ngn

```
+/^:

```

Try it online!

# Answer
> 1 votes
# Jelly, 2 bytes

```
ċ⁶

```

Try it online!

Literally `ċ` count  spaces.

# Answer
> 1 votes
# Perl 5, 7 bytes

```
$_=y; ;

```

Try it online!

# Answer
> 1 votes
# PowerShell, 18 bytes

```
($args-eq32).count

```

Try it online.

Expects input via splatting.

# Answer
> 1 votes
## CJam (5 bytes)

```
q' e=

```

Online demo

```
qS/,(

```

Online demo

# Answer
> 1 votes
# Java 8, 27 bytes

```
s->s.split(" ",-1).length-1

```

Try it online.

**Explanation:**

```
s->                         // Method with String as parameter and integer return-type
  s.split(" ",              //  Split the input on spaces
              -1)           //  While retaining empty strings as items
                 .length    //  Get the amount of items in the array
                        -1  //  And subtract 1

```

Using the `count()` builtin with a filter for spaces would be 2 bytes longer (or 1 if the input is guaranteed to not contain tabs/newlines/other characters below spaces - in which case the `==32` can be `<33`):

```
s->s.filter(c->c==32).count()

```

Try it online.

# Answer
> 1 votes
# Brachylog, 5 bytes

```
{∋Ṣ}ᶜ

```

Try it online!

```
{  }ᶜ    The output is the number of ways in which
 ∋       an element of the input can be chosen
  Ṣ      such that the element is a space.

```

Alternatively,

# Brachylog, 5 bytes

```
ṇ₁l-₁

```

Try it online!

```
  l      The length of
ṇ₁       the input split on spaces
   -₁    minus one is the output.

```

# Answer
> 0 votes
# JavaScript, ~~24~~ 22 bytes

-2 bytes thanks to Shaggy and template literals!

```
s=>s.split` `.length-1

```

Try it online!

# Answer
> 0 votes
# Python 3, 21 bytes

```
lambda s:s.count(' ')

```

Try it online!

# Answer
> 0 votes
# Japt, 2 bytes

Yawn!

```
èS

```

Try it

# Answer
> 0 votes
# Ruby, 15 bytes

```
->s{s.count' '}

```

Try it online!

Uhmmm...

# Answer
> 0 votes
# Wolfram Language (Mathematica), 9 bytes

```
Count@" "

```

Try it online!

Takes a list of characters as input.

# Answer
> 0 votes
# MathGolf, 5 bytes

```
gÅ =£

```

Input as a list of characters.

Try it online.

**Explanation:**

```
g      # Filter the (implicit) input-list
 Å     #  Using the following two commands:
   =   #  Equals a space
    £  #  Then pop this filtered list and get its length for the amount of spaces
       # (after which the entire stack joined together is output implicitly)

```

Or alternatively: `mÅ =Σ` (Try it online), which is similar but uses a map & sum instead of filter & length.

---
Tags: code-golf, string, counting, whitespace
---