[Question]
  [
### Instructions
Given an unknown input string `i` with a value of either *heads* or *tails*, return `1` for *heads* or `-1` for *tails* with the shortest code.
### Sample not golfed code (55b):
```
if(i == "heads"){
    print(1);
}else{
    print(-1);
}
```
### Sample golfed code (16b):
```
print("t">i||-1)
```
---
*Javascript was used for the example but it's **not** a requirement*. Sorry if it's too simple for most users, it can be improved.
  
[Answer]
## C, 18 bytes
Pretty easy, but let's do it just for fun...
```
puts("-1"+*i/8%2);
```
Given the string `char *i` it prints 1 for `heads` and -1 for `tails`, with trailing newline.
## Explanation
In C, `"-1" + 1` points to 1 character forward, so it is the same as `"1"`. Let's take a look at the first characters:
```
"heads"[0] = 'h' = 104 = 0b01101000
"tails"[0] = 't' = 116 = 0b01110100
```
If we count the bits from the rightmost one starting at zero, bit 3 is 1 in `heads` and 0 in `tails`: summing it to `"-1"` gives the right string. It looks like this:
```
"-1" + ((i[0] >> 3) & 1)
```
Now, substitute `i[0]` with `*i` and the right shift with the power-of-two division to save some bytes. Also remove useless parentheses:
```
"-1" + (*i / 8 & 1)
```
Now, `& 1` can be substituted with `% 2`. The character count is the same, but the modulus has higher priority, allowing to drop the parentheses. Remove the whitespace:
```
"-1"+*i/8%2
```
## Bonus
I think the shortest way to get an integer 1 or -1 (not a string) in C is:
```
18-*i/6
```
Explanation:
```
'h' = 104
't' = 116
('h' + 't') / 2 = 110
110 - 'h' =  6
110 - 't' = -6
(110 - 'h') / 6 =  1
(110 - 't') / 6 = -1
Apply distributive property (integer division):
18 - 'h' / 6 =  1
18 - 't' / 6 = -1
```
[Answer]
# Ruby, 8 (6 without output)
```
p ?t<=>i
```
Rocketship operator!
[Answer]
# CJam, 4 bytes
```
I'e#
```
Assumes that the variable `I` holds the input, since `i` isn't a valid identifier in CJam.
[Try it online.](http://cjam.aditsu.net/#code=%22heads%22%3AI%3B%20e%23%20Store%20input.%0AI'e%23%20%20%20%20%20%20%20e%23%20Execute%20code.%0AS%20%20%20%20%20%20%20%20%20%20e%23%20Push%20a%20space.%0A%22tails%22%3AI%3B%20e%23%20Store%20input.%0AI'e%23%20%20%20%20%20%20%20e%23%20Execute%20code.%0A "CJam interpreter.")
This is equivalent to the JavaScript code `I.indexOf('e')`.
[Answer]
## PHP - 11 Bytes
```
<?=1-$i^=F;
```
This works because `'tails' ^ 'F'` ‚Üí `'2'` and `'heads' ^ 'F'` ‚Üí `'.'`, which when typed as an integer is `0`.
You may test this solution (or any of the below) in the following way:
```
<?php foreach(['heads', 'tails'] as $i): ?>
 <?=1-$i^=F;
endforeach; ?>
```
[Ideone Link](http://ideone.com/kLyO5M)
---
**Alternatives**
*15*: `<?=1-md5($i)%3;`  
*16*: `<?=md5($i)[5]-5;`  
*16*: `<?=-crc32($i)%5;`
[Answer]
# TI-BASIC, 9-10 bytes
```
cos(œÄ ≥inString(Ans,"t
```
Straightforward. "t" is in position 1 of "tails", but "t" is not in the string "heads", so inString( returns 1 for tails and 0 for heads.
If your calculator is in radian mode (as any mathematician's should be), it takes only nine bytes:
```
cos(œÄinString(Ans,"t
```
Note that TI calculators do not have named strings, so the input is in the calculator's answer variable. Also note that lowercase letters are two bytes each, so this solution actually takes less memory than than the word "heads".
[Answer]
# [Fission](http://esolangs.org/wiki/Fission), ~~26~~ 21 Bytes
```
O/';'1
"S@]_"-
R? <tL
```
Martin (and his excellent answer [here](https://codegolf.stackexchange.com/a/50858/31054)) convinced me to learn a new language, and what better place than a quick golf? This is almost certainly not optimal, but hey, it was fun! Once I feel good about it, I may provide some form of explanation if it is requested.
[Answer]
# x86-16 machine code, 8 bytes
As a callable function, input string at `DS:SI`, output in `AL`.
```
80 3C 74    CMP  BYTE PTR[SI], 't'      ; if 'h': CF = 1, if 't': CF = 0 
1A C0       SBB  AL, AL                 ; AL = AL - AL - CF (AL = -CF) 
                                        ;  if 't': AL = 0 and CF = 0
                                        ;  if 'h': AL = -1 and CF = 1 
1C FF       SBB  AL, -1                 ; AL = AL - (-1) - CF 
                                        ;  if 't': AL = AL + 1 = 1
                                        ;  if 'h': AL = AL + 0 = -1
C3          RET
```
### x86-16 machine code, IBM PC DOS, 17 bytes
Or as a standalone DOS COM executable. Input from command line, output to stdout.
```
00000000: b402 0826 8200 7a04 b22d cd21 b231 cd21  ...&..z..-.!.1.!
00000010: c3
```
**Unassembled:**
```
B4 02           MOV  AH, 02H        ; DOS API display char function     
08 26 0082      OR   DS:[82H], AH   ; set parity flag from input 
7A 04           JPE  HEADS          ; if even, heads - display just '1'
B2 2D           MOV  DL, '-'        ; otherwise first display a '-''
CD 21           INT  21H            ; output DL to console
            HEADS: 
B2 31           MOV  DL, '1'        ; display the '1'
CD 21           INT  21H            ; output DL to console
C3              RET
```
**Explanation:**
Use the CPU's parity flag to determine if first char is an `'h'` (even number of binary `1`'s) or a `'t'` (odd number of binary `1`'s). This saves one byte over comparing the char in ASCII.
**Input/Output:**
[![enter image description here](https://i.stack.imgur.com/TqxaG.png)](https://i.stack.imgur.com/TqxaG.png)
[Answer]
## Python 2, 16 bytes
```
print(i<'t')*2-1
```
[Answer]
# Pyth - 4 bytes
---
```
 xz"e
```
Run with [heads](https://pyth.herokuapp.com/?code=xz%22e&input=heads&debug=0) or [tails](https://pyth.herokuapp.com/?code=xz%22e&input=tails&debug=0). As `i` is `int` in Pyth, this uses `z` as the variable name, which contains any user input. It is equivalent to the Python `print(z.find("e"))`, so uses @Dennis's method.
[Answer]
# VBA (Excel), 12 bytes
Not a fantastic bit of golfing, but it's fun to try with VBA to get anywhere near to a proper programming language...
```
?13-asc(i)/6
```
i is the string, and it just exploits the ASCII value of the first character, divided by 6 and substracted from 13 to give 1 or -1. Very simple.
Example run in immediate window (10 extra bytes to set the input variable) :
```
i="Heads":?13-asc(i)/6
 1
```
[Answer]
# C, 22 bytes
```
puts(*i>'h'?"-1":"1");
```
Credits goes to [@TheE](https://codegolf.stackexchange.com/users/40904/the-e) [for telling me about this](https://codegolf.stackexchange.com/questions/50270/quickgolf-heads-or-tails/50284#comment119324_50284)!
Explanation:
If the first character of the string is greater than `'h'`, the string `"-1"` is printed. Otherwise, the string `"1"` gets printed. Note that this approach comes with a trailing newline character.
---
Old version (25 bytes):
```
printf("%d",*i>'h'?-1:1);
```
Explanation:
If the first character of the string is greater than `'h'`, -1 is printed. Otherwise, 1 is printed.
[Answer]
# Tr: ~~17~~ 13 characters
(Or ~~14~~ 10 if you count only the arguments‚Ä¶)
```
tr -s ta-s -1
```
Sample run:
```
bash-4.3$ tr -s ta-s -1 <<< heads
1
bash-4.3$ tr -s ta-s -1 <<< tails
-1
```
Brief explanation:
`tr` stands for transliterate, that means, replaces each character of the input found in the first argument with character at the same position in the second argument:
```
tr ta -1 <<< tails         # replaces t ‚á¢ -, a ‚Üí 1
‚áí -1ils
```
If the first argument is longer, the characters without positional match in the second argument are replaced with second argument's last character:
```
tr tals -1 <<< tails       # replaces t ‚á¢ -, a ‚Üí 1, l ‚Üí 1, s ‚Üí 1
‚áí -1i11
```
When `-s` (`--squeeze-repeats`) option is used, successive characters which would be replaced with the same character are replaced at once:
```
tr -s tals -1 <<< tails    # replaces t ‚á¢ -, a ‚Üí 1, l+s ‚Üí 1
‚áí -1i1
```
So if we enumerate all characters in ‚Äútails‚Äù, we get what we need:
```
tr -s tails -1 <<< tails    # replaces t ‚á¢ -, a+i+l+s ‚Üí 1
‚áí -1
```
Same for ‚Äúheads‚Äù, but wee need to keep the ‚Äút‚Äù in front to consume the minus (characters sorted alphabetically for creepiness):
```
tr -s taedhs -1 <<< heads   # replaces h+e+a+d+s ‚Üí 1
‚áí 1
```
Merging all uniques characters of ‚Äútails‚Äù and ‚Äúheads‚Äù in a single first argument, keeping ‚Äút‚Äù in front leads to final solution:
```
tr -s tadehils -1 <<< tails # replaces t ‚Üí -, a+i+l+s ‚Üí 1
‚áí -1
tr -s tadehils -1 <<< heads # replaces h+e+a+d+s ‚Üí 1
‚áí 1
```
To avoid enumerating the characters, an interval in *from***-***to* format can be used instead.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 2 bytes
```
ae
```
[Try it online](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=YWU&input=ImhlYWRzIg)
[Answer]
# shell (portable/POSIX), 16 bytes
`expr $i : he - 1`
[Try It Online!](https://tio.run/##S0kszvhfnpGZk6pQlJqYopBprZCS/z@1oqBIQSVTwUohI1VBV8Hwf0p@Xur/DKCCYq6SxMycYi4A)  
Thanks to [@St√©phaneChazelas](https://unix.stackexchange.com/users/22565/st%c3%a9phane-chazelas) in [unix.stackexchange.com](https://unix.stackexchange.com/q/536172/265604)
Other solutions tried:  
`echo $[30#$i%7-1] # 17 bytes but only in bash, zsh.` [Try It Online!](https://tio.run/##qyrO@F@ekZmTqlCUmpiikGmtkJL/PzU5I19BJdrYQFklU9Vc1zD2f0p@Xur/DKCKYq6SxMycYi4A)  
Note: Using `dash` as a reasonable simile of a portable shell tester.
* `expr $i : he - 1` works by counting how many characters match `he` with `$i : he`. A `heads` match `2` and a `tails` match 0 (none).Then substracting `1` with `- 1`.
* `$[30#$i%7-1]` works by converting the string to an integer. The base 30 and the mod by 7 were selected to obtain a difference of 2 between `heads` and `tails`. Then subtracting 1 converts the numbers to `1` and `-1`.  
Note that a `$[...]` is an archaic form of arithmetic expression `$((...))` valid only in some shells.
* `he=2;echo $[${i%a*}-1]` works by making a variable of some value and then using Arithmetic Expansion to expand that variable (from the text value). The `${i%a*}` converts `heads` to `he` and `tails` to `t` (that, as a variable, has a value of 0).
* `IFS=h;set $i;echo ${1:+-}1` works in two steps. Setting IFS to `h` breaks the unquoted `$i` in `set $i` into parts divided by the character `h`, `heads` is divided to `''` and `'eads'`, thus setting `$1` to null. `tail` is not divided by `h`, thus making `$1` equal to `tails`. Then, `${1:+-}` generates a `-` if the value of `$1` is non-null (as in `tails`) or nothing (as with a null `$1`). That sign (or nothing) is concatenated with `1`.
* `(IFS=h;set $i;echo $(($#*2-3)))` works in a similar way but use the number of parts (`$#`) that the string in `$i` got broken into.
[Answer]
# Python, 20 bytes
```
print(('h'in i)*2-1)
```
This returns `False` if it isn't, and `True` if it is. In python `False` and `0` are the same, and `True` and `1` are as well.
So:
```
True (1) * 2 -1 = 2-1 = 1
False (0) * 2 - 1 = 0-1 = -1
```
[Answer]
# Python 2, 17 bytes
```
print'-1'['t'>i:]
```
`'heads'` is less than `'t'`, so it evaluates to `True == 1`, and prints the string after the first character. `'tails'` is greater than `'t'`, so it evaluates to `False == 0` and the whole string is printed.
If we're doing this from the command line, with implicit printing, it just becomes:
```
'-1'['t'>i:]
```
...for 12 bytes, but it adds single quotes to the output.
[Answer]
# QBasic, 11 bytes
This has got to be the shortest piece of QBasic I've ever written.
```
c=i>"t
?c^c
```
**Explanation:**
The above is some pretty heavily golfed QBasic. Once the autoformatter gets through with it, it'll look like this:
```
c = i > "t"
PRINT c ^ c
```
The first line compares the string `i` with `"t"`. If `i` is `"heads"`, `i > "t"` is false and `c = 0`. If `i` is `"tails"`, `i > "t"` is true and `c = -1`. Yes, `-1` is the default value for boolean true in QBasic!
The second line maps `-1` to `-1` and `0` to `1` via a math trick: `(-1)^(-1) == 1/(-1) == -1`, and `0^0`, though technically mathematically undefined, returns `1`.
This code requires that `i` be explicitly declared as a string variable; otherwise, it would have to be `i$`. Full test program (tested on [QB64](http://qb64.net)):
```
DIM i AS STRING
DATA heads, tails
FOR x = 1 TO 2
READ i
c=i>"t
?c^c
NEXT x
```
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), ~~5~~ 4 bytes
```
'eI(
```
Similar to [Dennis' CJam answer](https://codegolf.stackexchange.com/a/50271/87923), finds the index of `e` in the input string
Saved one byte since I didn't realise input was automatically used as an argument if there isn't enough stack values
# How it works
```
'e  Push e
I   Index of e in the the input. 2 if heads, 0 if tails
(   Subtract One
Stack gets automatically outputted
```
[Try it Online!](https://tio.run/##S0/MTPz/Xz3VU@P//5LEzJxiAA)
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 22
```
echo $[0x${1:1:1}/2-6]
```
Takes the 2nd letter (`e` or `a`) and interprets it as a hex digit (14 or 10), then divide by 2 and subtract 6 to get the right answers.
[Try it online!](https://tio.run/##S0oszvifpqFZ/T81OSNfQSXaoEKl2tAKCGv1jXTNYv/XcpVnZOakKhSlJqYo5GTmpVorpORzKQABREM1SKzWCiySpqAC4nGl5Oel/s8AaijmKknMzCnmAgA "Bash ‚Äì Try It Online")
[Answer]
# [ed](https://en.wikipedia.org/wiki/Ed_(text_editor)), ~~27~~ ~~25~~ 21 bytes
**`ed`** gave me a headache. Finally figured it out with help from [`@ed1conf`](https://twitter.com/ed1conf/status/1161687587360313355) on twitter and some peeps on [`unix.se`](https://unix.stackexchange.com/questions/535595/ed1-script-with-multiple-search-replace). You can't just match things with `s/re/newtext/`, you have to prefix it with `g` otherwise **`ed`** packs a sad. It's like a grumpy 50 year old unix program saying "get off my lawn".
```
g/t/s//-
,s/\w\+/1
w
```
[Try it online!](https://tio.run/##S035/z9dv0S/WF9fl0unWD@mPEZb35CrnOv//5LEzJzi///yC0oy8/OK/@sWAwA)
***-2*** bytes by dropping the final `/`s  
***-4*** bytes thanks to @manatwork (& whose `sed` answer i plagiarised)  
*Old version:  
`g/t/s//-
g/\w\+/s//1
wq
.`*
[Answer]
# [golflua](http://mniip.com/misc/conv/golflua/) 25 20 18
```
w(I.r():f'h'&1|-1)
```
Probably could be golfed some more by using some tricks that I'm not thinking about at the moment. (see [history](https://codegolf.stackexchange.com/posts/50290/revisions) for old version) Saved 5 chars by moving input to `write` and ignoring the `if` statement there. Two more chars were saved by ignoring the optional parenthesis on `find`. It does not check for failed conditions (i.e., input that isn't *heads* or *tails*).
A Lua equivalent would be
```
io.write(io.read():find('h') and 1 or -1)
```
[Answer]
# Haskell, 18 bytes
```
f('h':_)=1
f _= -1
```
Every string starting with the letter `h` is mapped to `1`, all others to `-1`.
[Answer]
# Sed: 16 characters
```
s/t/-/
s/\w\+/1/
```
Sample run:
```
bash-4.3$ sed 's/t/-/;s/\w\+/1/' <<< 'heads'
1
bash-4.3$ sed 's/t/-/;s/\w\+/1/' <<< 'tails'
-1
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 5 bytes
```
3-3‚äÉ‚çã
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P03hUdsEBWNd40ddzY96u0EC6iWJmTnF6lxAVkZqYkqxOgA "APL (Dyalog Unicode) ‚Äì Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 3 bytes
```
'eI
```
[Run and debug it](http://stax.tomtheisen.com/#c=%27eI&i=%22heads%22%0A%22tails%22&m=2)
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 4 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
‚îî0Y.
```
[Run and debug it](https://staxlang.xyz/#p=c030592e&i=heads%0Atails&a=1&m=2)
It's the codepoint of the first character mod 7 minus 5.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 15 bytes
```
($args[1]-99)/2
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfmvkmZb/V9DJbEovTjaMFbX0lJT3@h/LReXSoWCrYJ6RmpiSrE6l5pKmoJDBVSsJDEzBy72HwA "PowerShell ‚Äì Try It Online")
Takes input via splatting. Uses the `e` vs the `a` to do ASCII math
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 8 bytes
```
?z2*1r-p
```
dc can't do anything meaningful with strings other than read them in and attempt to evaluate them. Doing this, "heads" outputs some warnings about unimplemented commands and empty stack, which we ignore, but importantly the stack remains empty. "tails" does almost the same with the important exception that the final "ls" loads a value from the s register to the stack.
We then use "z" to get the stack length and arithmetically fiddle to get the right answers.
[Try it online!](https://tio.run/##JYxNCoAgFAb37xQf4ipoUcsyOov5HihIRgZB0dntb5YzMJPNvrBziWVQZTzaqlnrpSjafYiCVSwjhll6cCI8iPMJ@nzd1X2GHWqB0v9FwRgD/XbiNEvxzyLTZkPMdAM "Bash ‚Äì Try It Online")
[Answer]
# [Triangular](https://github.com/aaronryank/triangular), 10 bytes
```
F.~%.7/-_<
```
[Try it online!](https://tio.run/##KynKTMxLL81JLPr/302vTlXPXF833ub//5LEzJxiAA "Triangular ‚Äì Try It Online")
Divides the ASCII value of a character input by 7. Subtracts the quotient from 15. Execution stops when the IP runs out of the program space. This works because Triangular can only manage integer division. Conveniently, "h" has a value of 104, which is 14 when integer divided by 7; "t" is 116, which is 16 when integer divided by 7.
Ungolfed/Explanation:
```
   F
  . ~
 % . 7
/ - _ <
---------------------------------------------------------------
F                 - Push 15 to Top of Stack
 ~                - Read a character from input, push its value to ToS
   7              - Push 7 to ToS
     <_           - Change directions, then pop ToS-1 and ToS, push their integer quotient
        -         - Pop ToS-1 and ToS, push their difference
          %       - Print ToS as an integer
```
---
**Previous version (14 bytes):**
```
~\81|m/,!<.>i%
```
Read a character from input; if that character's ASCII value divided by 8 has a remainder, print -1, otherwise print 1.
[Answer]
## [Keg](https://github.com/JonoCode9374/Keg), ~~8~~ ~~12~~ 8 bytes
```
_d=2*1-.
```
[Try it online!](https://tio.run/##y05N//8/PsXWSMtQV@///5LEzJxiAA)
## Explanation (syntactically invalid)
```
_        Take input and discard the last item
 d=      If the top of the stack is d:
   2*    Re-set the top of the stack as 2
     1-  Decrement the top of the stack by 1
       . Explicitly output the top of the stack
```
> 
>  -4 bytes thanks to manatwork
> 
> 
> 
]