title: Same length, different string

text:
# Question
Title: Same length, different string
## Challenge

Given a non-empty string *S* of length *L* consisting entirely of printable ASCII chars, output another string of length *L* that consists entirely of printable ASCII chars, but is not equal to *S*.

For the purposes of this challenge, a printable ASCII char is one between U+0020 and U+007E, inclusive; that is, from  (space) to `~` (tilde). Newlines and tabs are not included.

For example, given `"abcde"`, some valid outputs could be:

* `"11111"`
* `"abcdf"`
* `"edcba"`

But these would be invalid:

* `"abcde"`
* `"bcde"`
* `"abcde0"`

### Test cases

```
"asdf"
"1111"
"       "
"~~~~~"
"abcba"
"1"
" "
"~"
" ~"
"~ "
"  0"
"!@#$%^&*()ABCDEFGhijklmnop1234567890"
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

```

### Rules

* You may assume the input consists entirely of printable ASCII chars.
* You may not assume that the input does not contain all 95 printable chars.
* You may assume the input contains at least one character and is less than 256 chars long.
* The output must also consist entirely of printable ASCII chars. You could not, for example, output the byte \x7F for input `"~"`.
* The output must be different than the input with probability 1; that is, you may generate random strings until one is different than the input, but you can't just output *L* random characters and hope it's different.
* Newlines are disallowed in the output, but you may output one trailing newline which is not counted toward the string.

## Scoring

This is , so **the shortest code in bytes in each language wins.**

# Answer
> 36 votes
# Python 2, 21 bytes

```
lambda s:`s`[:len(s)]

```

Try it online!

Takes the string representation of the input string and truncates it to the length of the input string. For a typical string, this puts it in `'` quotes and chops off the end:

```
abc  ->   'abc'  ->  'ab
     rep        chop

```

Note that the new string starts with `'`. Let's show that the output always differs from the input.

* If the input has no `'`, then the output starts with `'` and the input does not.
* If the input contains a `'` and but no `"`, then Python will use `"` for the outer quotes, giving a first character `"` that's not in the input string.
* If the input has both `'` and `"`, then the outer quotes are `'` and each `'` is escaped as `\'`. Wherever the first `"` appears in the input, it's shifted right by the initial `'` in the output and by any possible escaping. This means it cannot match with a `"` in the corresponding position in the output.

Finally, note that quoting the input and possibly escaping characters always increases the number of characters, so truncating the output makes it the same length as the input.

Note that it was crucial that Python adaptively switches to `"` in the second case. If it didn't do so, it would fail on the three-character input `'\'`. Or, any longer prefix of the fix show string using `'`. So, this method won't work for most languages.

# Answer
> 17 votes
# 05AB1E, 3 bytes

```
ÇÈJ

```

Try it online!

```
Ç   # Convert to ASCII values
 È  # is even? (0 is 48 and 1 is 49 therefore 0 -> 1 and 1 -> 0)
  J # Join

```

# Answer
> 15 votes
# JavaScript (ES6), ~~37~~ ~~33~~ ~~36~~ ~~29~~ ~~26~~ ~~18~~ ~~21~~ 19 bytes

```
s=>s.slice(1)+ +!+s

```

Try it online!

-4 bytes thanks to ETHProductions

-7 + -5 + -2 bytes thanks to CalculatorFeline

-3 bytes thanks to Rick Hitchcock

Moves the first character to the end and sets it to 0 if it's numeric and non-zero, and 1 otherwise.

### Explanation

```
s=>                    anonymous function with parameter s
                 +s    convert s to a number
                !      not (converts to boolean; relevant: 0->true,1->false)
               +       convert !+s back to number (true->1, false->0)
   s.slice(1)+         prefix the rest of the string
              ␣        needed to avoid the +s combining

```

### Proof

Because the second char becomes the first, the third char becomes the second, etc. all chars would have to be identical. The last remaining char can only be a 0 or a 1, so the repeated char would have to be either 0 or 1. But any string of 0s produces a 1 at the end, and vice-versa; therefore, it is impossible to create an input that is equal to its output. -ETHProductions

See edits for former versions and explanations.

```
f=
s=>s.slice(1)+ +!+s

console.log(f("000"))
console.log(f("111"))
console.log(f("001"))
console.log(f("110"))
console.log(f("~"))
console.log(f("111111111111111111111111111111111111111111111111111"))
console.log(f("Hello world!"))
console.log(f("23"))
console.log(f(" "))
console.log(f("1x"))
```

# Answer
> 13 votes
# Jelly, 3 bytes

```
~Ṿṁ

```

Output is a string of digits, commas and hypen-minus characters, whose first character will differ from the first character of the input string.

Try it online!

### How it works

```
~Ṿṁ  Main link. Argument: s (string)

~    Map bitwise NOT over the characters c in s.
     This attempts to cast c to int and then apply bitwise NOT, mapping
     '0', ..., '9' to 0, ..., 9 (before ~), then -1, ..., -10 (after ~).
     For non-digits, the attempt fails, mapping c to 0.
 Ṿ   Uneval, yielding a comma-separated string of integers in [-10, ..., 0].
     The first character will be '-' if s starts with a digit and '0' if not.
  ṁ  Mold; truncate the result to the length of s.

```

# Answer
> 6 votes
# Haskell, 20 bytes

```
map$head.show.(<'M')

```

Try it online!

Converts to a string of `F` and `T`. What matters is that the characters `F` and `T` converts to each other. This is done by checking if the character is less than `M` to get `True` or `False`, then taking the first character of the string representation.

---

**Haskell, 23 bytes**

```
q '~'=' '
q _='~'
map q

```

Try it online

Replaces every character with `~`, except `~` becomes a space.

# Answer
> 5 votes
# MATL, ~~6~~ 5 bytes

```
Qo!V!

```

Try it online!

### Explanation

```
Q     % Implicitly input a string. Add 1 to each code point.
o     % Parity: 0 if odd, 1 if even. Note that '0' has ASCII code 48, so after
      % having added 1 it now gives 1. Similarly. '1' has ASCII code 49, so it
      % now gives 0. All other chars give 0 or 1.
!V!   % Convert each number to the corresponding char. Implicitly display

```

# Answer
> 5 votes
# Whitespace, 59 bytes

Visible representation

```
NSSNSSSTSSSSSNSNSSNSSNSTNTSTTTTSSTNTTSNSNSTSSSNSSSNTNSSNSNN

```

What it does:

For every character it reads it prints a space, except when it's a space, then it prints a @.

Disassembly:

```
loop:
    push 32
     dup
      dup
       dup
        ichr
       get
       sub
      jn not_32
     dup
      add
not_32:
     pchr
    jmp loop

```

# Answer
> 5 votes
# Haskell, 19 bytes

An anonymous function which takes and returns a `String`. Use as `(map$(!!1).show.succ) "1111"`.

```
map$(!!1).show.succ

```

Try it online! (Using @xnor's testing harness.)

* For each character in the input string, increments the character, then converts that to character literal format, then takes the second character of the literal, which is the character just after the starting `'` quote.
* For nearly all printable characters, this results in simply the incremented character. The exceptions are `&` and `~`, which instead give `\`, because their successors `'` and `\DEL` get escaped in character literals.

# Answer
> 5 votes
# \>\<\>, ~~9~~ 3 bytes

```
5%n

```

Try it online!

Takes input through the `-s` flag. Mods each digit with 5 and prints the integer, ending when the stack is empty. This results in only 5 possible output characters, 0-4. Each of those numbers when inputted will produce themselves plus 3, as the ASCII value of 0 is 48, which mod 5 is 3. While the output is reversed, no number is equivalent to another.

Both 7, 9 and `a`(10) also work as they are not factors of 48 and print single digits.

# Answer
> 4 votes
# 05AB1E, 5 bytes

```
žQDÀ‡

```

Try it online!

**Explanation**

Replaces each char with the next printable ascii char, wrapping from tilde to space.

```
žQ     # push a string of printable acsii chars (space to tilde)
  D    # duplicate
   À   # rotate left
    ‡  # translate

```

# Answer
> 4 votes
# Python 2, 25 bytes

```
lambda s:`s<'T'`[0]+s[1:]

```

Try it online!

Anders Kaseorg saved a byte by extracting the first character from `True` or `False`.

# Answer
> 4 votes
# , 7 bytes

```
íÁ/a
g?

```

Try it online! or Verify all test cases!

How does it work?

Consider all strings consisting of printable ASCII. Every string must either 1) Contain alphabetic characters, or 2) Contain no alphabetic characters.

So the way this program works is by first converting one non-alphabetic character into `'a'`, and then performing ROT13 on the input string.

```
í       " Substitute:
 Á      "   A non-alphabetic character ([^a-zA-Z])
  /     "   with
   a    "   the letter 'a'
g?      " Perform ROT13 on...
        "   (Implicit) the current line.

```

# Answer
> 4 votes
# Bash + coreutils, 13

```
tr \ -~ ~\ -}

```

Transliterates the characters  to `~` (0x20 - 0x7e) with `~`, then  to `}` (0x7e, 0x20 - 0x7d).

Try it online.

# Answer
> 4 votes
# C (gcc), 22 bytes

```
f(char*s){*s=65+*s%2;}

```

Takes a string pointer and modies the first char in place.

Try it online!

# Answer
> 4 votes
# C (gcc), 20 bytes

Saw Dennis's answer, thought of a 2 byte essential improvement.

```
f(char*s){*s^=*s/3;}

```

Try it online! (Footer by Dennis.)

Like the original, modifies the first character of the string in place, but xors it with its value divided by 3 (the smallest number that works. 2 fails on the single character `'U'` which gives 127, not printable.)

# Answer
> 3 votes
# Retina, ~~10~~ 6 bytes

*4 bytes golfed thanks to @Neil*

```
T`p`~p

```

Try it online!

This transliterates  to `~`, `!` to , `"` to `!`, ..., `~` to `}`.

# Answer
> 3 votes
# Octave, ~~19~~ 18 bytes

```
@(s)['',(s<66)+65]

```

Try it online!

**Explanation:**

```
@(s)                 % Anonymous function taking a string s as input
         s<66        % A boolean vector with `1` for all characters below ASCII-66.
        (s<66)+65    % Add 65 to this, so that all elements that are 32-65 are now 66.
                     % All other elements are 65
    ['',         ]   % Implicitly convert the list of 65 and 66 to the letters A and B

```

# Answer
> 3 votes
## Haskell, ~~30~~ 26 bytes

```
f ' '='~'
f c=pred c
map f

```

Try it online!

Replaces each char with its predecessor and space with tilde.

# Answer
> 3 votes
## CJam, 5 bytes

```
l)iA%

```

Try it online!

Converts the last character to its code point and takes that modulo 10. This is clearly different for non-digit characters in the last position. But the digits start at code point 48, so taking those mod 10 will shift them left cyclically and hence the last character is always changed.

# Answer
> 3 votes
# Japt, 4 bytes

```
®c v

```

Try it online!

## Explanation:

```
®c v
®    At each char:
 c     Convert to its ASCII value
   v   Return 1 if divisible by 2, otherwise return 0

```

# Answer
> 3 votes
# Cubix, 10 bytes

```
..@|i?2%)O

```

Try it online! or Watch it run!

For each char, prints `1` if the char has an even code point, `2` otherwise; `1` has an odd code point and `2` an even, so the output will never equal the input.

### Explanation

This code corresponds to the following cube net:

```
    . .
    @ |
i ? 2 % ) O . .
. . . . . . . .
    . .
    . .

```

The IP (instruction pointer) starts at the top-left corner of the far-left face, heading east. It follows this series of instructions:

```
i     Grab a char-code from STDIN and push it to the stack (-1 if there is no more input).
?     If the top item is negative, turn left and hit @ which ends the program.
      If it's positive (any printable ASCII char), turn right. The IP runs through a bunch
        of no-ops, then hits:
)     Increment the top item.
|     Mirror the IP's direction horizontally (turns it around).
)     Increment the top item again. The IP then wraps around again until it hits:
?     The top item is positive, so turn right.
2     Push a 2 to the stack.
%     Push the modulus of the top two items (0 for even char-code, 1 for odd).
)     Increment the result (now 1 for even char-code, 2 for odd).
O     Output as a number. The IP wraps back around to the i and the process starts again.

```

# Answer
> 3 votes
# Alice, 9 bytes

```
#oi/
t i@

```

Try it online!

### Explanation

The idea was taken from Martin Ender's CJam submission. The first character is taken as a code point, reduced mod 10, and moved to the end of the output. Since exactly one character was changed, permuting the characters cannot result in getting the same string back.

```
#   skip next command
o   (skipped)
i   push first byte onto stack
    STACK: [97]
/   reflect to SE, switch to ordinal mode (implicit reflect to SW)
i   push remaining input onto stack as string (implicit reflect to NW)
    STACK: [97, "sdf"]
o   output top of stack (implicit reflect to SW)
    STACK: [97]
t   implicitly convert code point to decimal string, and extract last character
    (implicit reflect to NE)
    STACK: ["9", "7"]
o   output this last digit (implicit reflect to SE)
i   push empty string, since there is no more input to take (implicit reflect to NE)
/   reflect to S, switch to cardinal mode
@   terminate

```

# Answer
> 3 votes
# Pushy, 1 byte

```
Q

```

**Try it online!**

This converts the given string into list of ASCII character codes, indexes them (modular indexing) into the uppercase alphabet, then prints the result. Essentially, each character `n` is mapped to `chr(ord(n) % 26 + 65)`. You can use **this program** to see how the mapping works.

The output:

* Will always be the same length as the input, as the characters are directly mapped into new ones.
* Will always comprise only printable ASCII characters (as it only contains uppercase letters)
* Will always be different to the input, as there is no possible input character `n` such that `chr(ord(n) % 26 + 65) == n`, as for this to be true there must be an integer `x` such that `26x = 65`, for which there is no solution.

---

# 1 byte

```
q

```

**Try it online!**

This answer is exactly the same, except that it maps to *lowercase* alphabet characters rather than *uppercase* alphabet characters. This is still valid as there is no possible input character `n` such that `chr(ord(n) % 26 + 97) == n`.

# Answer
> 3 votes
## R, 40 bytes

`function(s)substr(shQuote(s),1,nchar(s))`

This uses the shell quoting function `shQuote` to place appropriate quotes around a string and escape quotes within the string (similar to @xnor's answer). Then take a substring that's as long as the original string (because the string might have multiple escaped characters, we need to take a substring of the correct length, so we can't just use `substring(...,3)`). `sQuote` is shorter, but converts  to `‘‘’`.

Another approach, using more 'core' R stuff is 46 bytes:

`function(s)sub(".",letters[grepl("^a",s)+1],s)`

Substitute the first character with 'a', unless it is 'a', then substitute it for 'b'. `sub` only substitutes the first match, so we don't need `^`. `letters` is constant and a slightly shorter way of doing `c("a","b")`. `grepl` returns a boolean, and adding 1 converts it to a number that indexes `letters`. The `^` is needed to correctly convert "ba".

**Code to test**

```
x = function(s)substr(shQuote(s),1,nchar(s))

test = function(t){
  t2 = x(t)
  t2!=t & nchar(t)==nchar(t2)
}

testStrings = c("a","b","ab","ba","aa",
                "'","'\"","\\\\",'"','""',
                '‘','’',"~","asdf",
                "1111","       ","~~~~~","abcba",
                "1"," ","~"," ~","~ ","  0",
                "!@#$%^&*()ABCDEFGhijklmnop1234567890",
                " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~")

all(sapply(testStrings,test))

```

# Answer
> 2 votes
# Brain-Flak, 53 bytes

Includes +1 for `-c`

```
([(((()()()()){}){}){}()]({}())){{}(<({}[()()])>)}{}

```

This will decrement the first character unless it is a space, in that case it will increment the first character.

Try it online!

```
([(((()()()()){}){}){}()]      )                     # Push: input + 1 != 33 on top of...
                         ({}())                      #    input + 1
                                {{}(<          >)}{} # If (input + 1 != 33)
                                     ({}[()()])      #   Push: (input + 1) - 2

```

# Answer
> 2 votes
# PHP\<7.1, 31 Bytes

```
for(;~$c=$argn[$i++];)echo$c^1;

```

Try it online!

# Answer
> 2 votes
# Jelly, 4 bytes

```
^1Ṿ€

```

Outputs a digit string. No output character will be equal to the corresponding input character.

Try it online!

### How it works

```
^1Ṿ€  Main link. Argument: s (string)

^1    XOR each character c in with 1.
      This attempts to cast c to int, mapping '0', ..., '9' to 0, ..., 9.
      For non-digits, the attempt fails, mapping c to 0.
      After XORing with 1, we get 1, 0, 3, 2, 5, 4, 7, 6, 9, 8 for '0', ..., '9',
      and 1 for all non-digits.
  Ṿ€  Uneval each; mapping 0, ..., 9 to '0', ..., '9'. This yields a character
      array, which is Jelly's string type.
      Note that no character is mapped to itself.

```

# Answer
> 2 votes
## PHP, ~~30~~ 27

```
<?=strtr($a=$argn,$a,$a^1);

```

Changes every each char equal to the first char with the char that has the least significant bit flipped.

# Answer
> 2 votes
# Ruby, 20+1 = 21 bytes

Uses the `-p` flag.

```
sub(/./){$&=~/1/||1}

```

Try it online!

Replaces the first character in the input with a `0` if it is `1`, or `1` otherwise.

# Answer
> 2 votes
# Brachylog, 9 bytes

```
{¬Ṣ|∧Ịh}ᵐ

```

Try it online!

### Explanation

This replaces all chars by a space, except spaces which it replaces with `"0"`.

```
{      }ᵐ      Map on each char of the Input
 ¬Ṣ              The Input char is not " ", and the Output char is " "
   |             Or
    ∧Ịh          The Output char is "0"

```

# Answer
> 2 votes
# Golfscript, 3 bytes

Try it online!

```
)5%

```

Take the last character's ASCII value modulo 5, and replace the last character with the result. This obviously works for non-digit characters, but if the last character is a digit, it also changes ("0" mod 5 = 3, "1" mod 5 = 4, etc).

This would also work with 7 or 9 while still keeping the same length.

Also, yay! I have a Golfscript solution as good as the best solutions here!

# Answer
> 2 votes
# Funky, ~~26~~ 22 bytes

```
s=>s::gsub("."a=>1&~a)

```

Calculates `~a` which for non-digits will return NaN. Then `1&` limits it to either 0 or 1, for the digit 0, this will be `1`, and for `1` this will be `0`. So this string is always unique.

Try it online!

# Answer
> 2 votes
## C/C++, 29 bytes

```
void m(char*s){(*s%=26)+=65;}

```

Code to test :

```
#include <iostream>
#include <string>
#include <cassert>

#ifdef _MSC_VER
#pragma warning(disable:4996)
#endif

void m(char*s){(*s%=26)+=65;}

int main() {
    std::initializer_list<std::string> test{
        "asdf",
        "1111",
        "       ",
        "~~~~~",
        "abcba",
        "1",
        " ",
        "~",
        " ~",
        "~ ",
        "  0",
        "!@#$%^&*()ABCDEFGhijklmnop1234567890",
        " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
    };

    for (auto&a : test) {
        char* t = new char[a.size() + 1];
        std::strcpy(t, a.c_str());
        m(t);
        assert(a != t);
        std::cout << a << " => " << t << '\n';
        delete[] t;
    }
}

```

# Answer
> 2 votes
# brainfuck, ~~35~~ 27 bytes

Edit: switched to a better way of generating an odd number thanks to the brainfuck constants page

```
,[[[>]+<[-<]>]-[>+<---]>.,]

```

Try It Online

Prints out a string of semi-random Vs and Us. If the first character of the input is a V it will print out a U instead and vice versa.

### How it Works

```
,[ Gets first inputted char
  [[>]+<[-<]>] Converts the ASCII value to binary
  -[>+<---] Adds 85 to the last digit of that binary, which is the original value mod 2.
            This converts a V (value 86) into a U (value 85) and vice versa
  >. Print the value
,] Get a new value and repeat.
   Note that the binary of the previous value is still in memory,
     so it no longer prints specific chars for odd or even values

```

Another version with the same bytecount:

```
,[[>]+<[-<]>]-[>+<---]>[.,]

```

Only changes the first character to a V or a U, but doesn’t handle empty input (which is still valid)

# Answer
> 2 votes
# Brain-Flak, 42 bytes

```
({}[((((()()()()){}){}){})]<>){{}}([]<>{})

```

Try it online!

Replaces the first character of the string with a space, or a `!` if the first character is already a space.

# Answer
> 2 votes
# Perl 6, 14 bytes

```
{.ord%7~.chop}

```

Try it online!

Bare block, implicit lambda with input `$_`. The ordinal of the first character `.ord` modulo 7 is a different character: Non-numeric first character becomes numeric, numeric first characters map to a different character. If we append the input sans the last character (`~ $_.chop`), we match the length. It can never match the input because the first character never matches.

### ~~Perl 6, 15 bytes~~

```
{S/./{.ord%7}/}

```

Performs `S///` substitution (which returns the result of substituting on `$_`), matching `.` (any character) once, and replacing it with the ordinal of the first character in `$_` \- the same character - modulo 7. Non-numeric first character becomes numeric, numeric first characters map to a different character.

Try it online!

# Answer
> 2 votes
# str, 2 bytes

```
XV

```

Try it online!

## Explanation

```
XV
       over each character:
X         increment it  ("~" becomes "\x7f" and "@" becomes "A")
 V        wrap to printable ascii ("\x7f" becomes " ")

```

Alternatively, `YV` to decrement instead of increment.

# Answer
> 2 votes
# PowerShell, ~~37~~ 26 bytes

<sup>Thanks Mazzy for -11 bytes</sup>

```
-join($args|% t*y|%{$_%9})

```

Try it online!

Does alright. Uses the ToCharArray trick to save some bytes. Through a conversion chain, mods the ASCII value of each character by 9 then joins up the value.

# Answer
> 1 votes
# \>\<\>, 11 bytes

```
i:0(?;'0'=n

```

**Try it online!**

### Explanation

Like my MATL answer, this transforms character `'0'` into `'1'` and all other characters into `'0'`.

```
i       Input one char, or push -1 if there aren't any more chars
:       Duplicate
0(      Is it less than 0?
?;      If so, end program. Else:
'0'     Push character '0'
=       Is it equal? Gives 1 or 0
n       Output as a number. Go back to the beginning

```

# Answer
> 1 votes
## JavaScript (ES6), 24 bytes

```
f=
s=>s.replace(/./,s[0]^1)
```

```
<input oninput=o.textContent=f(this.value)><pre id=o>
```

Changes the first character of the string according to this table:

```
1   0
2   3
3   2
4   5
5   4
6   7
7   6
8   9
9   8

```

Everything else becomes `1`.

# Answer
> 1 votes
# Chip, 5 bytes

```
g*A~a

```

Try it online!

Maps all characters to either `@` or `A`, so that the lowest bit always differs from the input:

`0`, `@`, `~`, etc. map to `A`
`1`, `a`, `A`, etc. map to `@`

# Answer
> 1 votes
# x86 Assembly, 19 bytes

Alternates the first character of the string between '@' and 'A'

```
_diffstr:
  00000000: 8B 54 24 04        mov         edx,dword ptr [esp+4]
  00000004: 8A 02              mov         al,byte ptr [edx]
  00000006: 3C 41              cmp         al,41h
  00000008: 75 04              jne         0000000E
  0000000A: B0 40              mov         al,40h
  0000000C: EB 02              jmp         00000010
  0000000E: B0 41              mov         al,41h
  00000010: 88 02              mov         byte ptr [edx],al
  00000012: C3                 ret

```

# Answer
> 1 votes
# Perl 5, 49 bytes

```
sub{$_="a"x length $_[0];$_++while $_ eq$_[0];$_}

```

Explanation:

* starts with string of letter "a" as long as input
* keeps incrementing that until it's different from input

Starting from "a"s was to avoid incrementing to point where Perl lengthens the string; with only one strings to avoid being same as, it couldn't overflow.

This is shamelessly cribbed (and simplified) from my answer to the "related" problem "The Third String".

Execute with:

```
perl -e '$s = ' -E 'sub{$_="a"x length $_[0];$_++while $_ eq$_[0];$_}' -E ';say $s->("z")'

```

# Answer
> 1 votes
# x86 opcode, 6 bytes

```
    and     byte [ecx], 0xF1
    inc     byte [ecx]
    ret

```

# Answer
> 1 votes
# Julia 0.6, 26 bytes

```
s->map(x->x<'b'?'b':'a',s)

```

Try it online!

# Answer
> 1 votes
# Java 8, ~~39~~ 38 bytes

```
s->(s.charAt(0)<49?9:0)+s.substring(1)

```

Try it online.

**Explanation:**

If the first character has a unicode value below 49 (space, or one of `!"#$%&'()*+'-./0`), change it to a '9', else change it to a '0'.

```
s->                 // Method with String as both parameter and return-type
  (s.charAt(0)<49?  //  If the first character has a unicode value below 49:
    9               //   Change the first character to a '9'
  :                 //  Else
   0)               //   Change the first character to a '0'
  +s.substring(1)   //  And return the rest of the input-String (if any)

```

# Answer
> 1 votes
# Python 3, ~~29~~ 26 bytes

```
lambda s:'a~'[s<'~']+s[1:]

```

Try it online!

* Replacing first character with `~`, if the first character is `~` already, it is replaced by `a`.

# Answer
> 1 votes
# Pyth, 9 bytes

```
*h-+QGhQl

```

Try it here

### Explanation

```
*h-+QGhQl
   +QG      Stick the alphabet to the end of the input.
  -   hQ    Delete all instances of the first character.
 h          Take the first remaining character.
*       lQ  Multiply by the length of the (implicit) input.

```

# Answer
> 1 votes
# SmileBASIC, ~~27~~ 25 bytes

```
DEF D S
S[0]=@1[S>"2"]END

```

Creates a function named `D` that is called like:

```
STRING$="abcde"
D STRING$
'STRING$ is now "1bcde"

```

The first character is replaced with either `@` or `1`

# Answer
> 1 votes
# Gol\>\<\>, 6 bytes

```
iE;5%n

```

Try it online!

Direct translation of Jo King's \>\<\> answer.

# Answer
> 1 votes
# C (gcc), 22 bytes

```
f(char*s){*s=~1&*s^2;}

```

Try it online!

# Answer
> 1 votes
# MAWP, 11 bytes

```
0|[!5P5WA:]

```

Idea from Jo King's answer.

Prints the ASCII value of each letter modulo 5.

Try it!

# Answer
> 1 votes
# Husk, 6 bytes

```
ṁ(s%5c

```

Try it online!

Port of Jo King's answer \- upvote it!
Outputs ASCII values MOD 5.

# Answer
> 1 votes
# Vyxal, 3 bytes

```
C∷ṅ

```

Try it Online!

05AB1E port, go read that.

# Answer
> 1 votes
# APL (Dyalog Extended), ~~11~~ 8 bytes

```
∊⍕¨'0'=⎕

```

Try it online!

*-3 thanks to @Adám*

#### Explanation

```
∊⍕¨'0'=⎕
   '0'=⎕        For each character: 1 if it's '0', 0 otherwise
 ⍕¨             Convert each to string
∊               Flatten into a single string

```

# Answer
> 0 votes
# Perl 6,  ~~48~~  28 bytes

```
{(->{[~] (' '..'~').roll(.chars)}...*ne$_).tail}

```

Generates a sequence of random strings, stopping when one of them doesn't match the input. Returns the last string produced

Test it

```
{first *ne$_,(0,1 Xx.chars)}

```

Generates two strings one consisting of only `0`s, the other of `1`s. Returns the `first` that is not stringwise equal to (`ne`) the input (`$_`).

Test it

## Expanded

```
{             # bare block lambda with implicit parameter ｢$_｣

  first       # return the first value where the following is true

    * ne $_,  # WhateverCode lambda ( ｢*｣ is the parameter )

    (
      0, 1    # list of 0 and 1
      X[x]    # cross ｢X｣ that using the string repetition operator ｢x｣
      .chars  # with the number of characters in ｢$_｣
    )
}

```

# Answer
> 0 votes
# Convex, 4 bytes

```
'0f=

```

Try it online!

# Answer
> 0 votes
# Aceto, ~~16~~ ~~12~~ 9 bytes

```
=01`
,'pO

```

Run with `-F` to see immediate output (but works without).

### Explanation:

We read a character, then push the character `0` on the stack and test for equality:

```
=0
,'

```

If equal, we push a 1.

```
  1`

```

We now print the top element (either a one or an implicit zero), and go back to the start:

```
  pO

```

This prints zeroes for any characters that aren't zeroes, and ones for zeroes, e.g.:

```
Input  |  Output
----------------
abcde  |  00000
11111  |  00000
10010  |  01101

```

# Answer
> 0 votes
# Charcoal, 8 bytes

```
ＦＳＩＸ⁰⁼ι1

```

Try it online! Link is to verbose version of code. Works by comparing each character to `1`, then taking the result as the exponent of zero, then converting to string. This results in an output `0` for each `1` in the input and a `1` for each other character. Edit: Changes in Charcoal now mean that I can directly cast the result of `Equals` saving 2 bytes: `ＦＳＩ⁼ι0` Try it online! Link is to verbose version of code. Edit: Actually there was a 6-byte solution all along: `ＦＳ§α℅ι` Try it online! Link is to verbose version of code. Port of @FlipTack's Pushy answer. (Also works with lower case of course.)

# Answer
> 0 votes
# Braingolf, 12 bytes

```
.#~e1-:1+|&@

```

Subtracts 1 from the last char's ordinal if it is a tilde, otherwise adds one.

### Explanation:

```
.#~e1-:1+|&@  Implicit input of string, convert each char to ordinal and push to stack
.             Duplicate last item
 #~           Push tilde ordinal
   e          If last 2 items are equal (consumes last 2 items)
    1-        ..then subtract one
      :       else
       1+     ..add one
         |    endif
          &@  Print entire stack as chars

```

# Answer
> 0 votes
# C#, 46 bytes

```
_=>(char)(_[0]>32?_[0]-1:_[0]+1)+_.Remove(0,1)

```

Changes first letter to next to previous letter on ASCII table unless it is the first letter, in which case it takes the next one.

# Answer
> 0 votes
## SAS, 34

```
substr(s,1,1)=ifc(s=:'z','a','z');

```

If the first character of the string `s` is `z`, change it to `a`, otherwise change it to `z`. Rubbish compared to the proper golfing languages, but at least it beats C#!

# Answer
> 0 votes
# T-SQL, 45 bytes

```
SELECT STUFF(S,1,1,CHAR(ASCII(S)%7+48))FROM t

```

Takes input from pre-existing table **t** with VARCHAR field **S**, per our IO standards.

Modifies the first character by taking the remainder MOD 7 of the ASCII value, then converting that back into a digit between 0 and 6. But ASCII(0)=48, which is 6 MOD 7, so the first character never maps back onto itself.

# Answer
> 0 votes
# Cubically, 23 bytes

```
(~-61/1=7&6:7>4?6@4!@5)

```

Converts the string into `$`s and `-`s.

# Answer
> 0 votes
# Implicit, ~~15~~ 14 bytes

```
'_._` !{+32}*-

```

Found about 10 interpreter bugs writing this. Try it online!

```
'_._` !{+32}*-
'                « read string                              »;
 _               « push last char onto stack                »;
  .              « increment                                »;
   _`            « mod by 127 (the "` " evaluates to 127)   »;
      !{...}     « if falsy (char was ~)                    »;
        +32      «  add 32 (make it a space)                »;
            *    « stick char at beginning of string        »;
             -   « pop last char off string                 »;

```

# Answer
> 0 votes
# BrainFuck, ~~49~~ 47 Bytes

```
,>++++[-<-------->]++[<]++++[->++++++++<]>-[.,]
x           0   (x-32) 2                (x-32||2)+31
^           ^(x>32) ^(x==32)

```

Assuming EOF as zero

# Answer
> 0 votes
# Perl 5, 23 + 1 (-p) = 24 bytes

```
s/./chr 65+ord($&)%26/e

```

Try it online!

Blatantly steals @FlipTack's method to change the first character to a different upper case letter.

# Answer
> 0 votes
# Swift 3, 76 68 bytes

```
let s=readLine()!;print(s.characters.map{$0=="a" ?"b":"a"}.joined())

```

Try it online!

# Answer
> 0 votes
# Fortran (GFortran), 77 bytes

```
CHARACTER(256)A
READ*,A
A(1:1)=CHAR(MOD(IACHAR(A(1:1))+1,94)+33)
PRINT*,A
END

```

Try it online!

It does what was required... well, with some issues...

1) If the first character is `"`or `<space>`, they will be ignored;

2) If there is `/`, it will be understood as something like "end of transmission";

3) There will be a leading space (which is not part of the output (so do I think), because Fortran always prints a leading space if the output is not formated) and up to 255 trailing spaces. This last problem (i.e., the trailing spaces) can be solved using no more then six bytes.

# Answer
> 0 votes
# SNOBOL4 (CSNOBOL4), 71 bytes

```
	INPUT LEN(1) . X REM . S
	X =IDENT(X) 1	:S(O)
	X =0
O	OUTPUT =X S
END

```

Try it online!

Replaces the first character of `S` with a `0` unless it's already, `0` in which case it swaps it with `1`.

# Answer
> 0 votes
## Pyth, 12 bytes

```
+C+%ChQlG32t

```

**Test suite**

Python 3 translation:
```
Q=eval(input())
print(chr(ord(Q[0])%26+32)+Q[1:])

```

# Answer
> 0 votes
# Tcl, 56 bytes

```
proc C s {join [lmap x [split $s ""] {expr {$x==0}}] ""}

```

Try it online!

Approach very similar to last one: replaces every non-zero by a zero and every zero by one.

---

~~Tcl, 62 bytes
```
proc C s {puts [expr {[string in $s 0]==0}][string ra $s 1 e]}

```
Try it online!<br>Approach replaces first character by 1 if it is a 0, else it replaces anything else by a 0.<br>~~

##

~~Tcl, 83 bytes
```
proc C s {scan [string in $s 0] %c f
puts "[format %c [incr f]][string ra $s 1 e]"}

```
Try it online!<br>~~

# Answer
> 0 votes
# naz, 36 bytes

```
2a2x1v1x1f1r3x1v2e5p1o1f0x1x2f0a0x1f

```

Works for any input string terminated with the control character STX (U+0002).

**Explanation** (with `0x` commands removed)

```
2a2x1v             # Set variable 1 equal to 2
1x1f               # Function 1
    1r             # Read a byte of input
      3x1v2e       # Jump to function 2 if it equals variable 1
            5p1o   # Otherwise, output it modulo 5
                1f # Jump back to the start of function 1
1x2f               # Function 2
    0a             # Add 0 to the register
1f                 # Call function 1

```

# Answer
> 0 votes
# Thunno `J`, \\$ 5 \log\_{256}(96) \approx \\$ 4.12 bytes

```
O2%1_

```

Attempt This Online!

Port of Riley's 05AB1E answer.

#### Explanation

```
O2%1_  # Implicit input
O      # Ordinals of input
 2%    # Mod 2 (vectorised)
   1_  # Not (vectorised)
       # J flag joins the list
       # Implicit output

```

# Answer
> 0 votes
# MathGolf, 4 bytes

```
É1░¡

```

Converts `1` to `0` and every other character to `1`.

Try it online.

**Explanation:**

```
É     # Foreach over each character of the (implicit) input-string,
      # using 3 characters as inner code-block:
 1░   #  Push 1, and convert it to a string: "1"
   ¡  #  Check whether it's NOT equal to the current character
      # (after which the entire stack is joined together and output implicitly)

```

# Answer
> 0 votes
# Thunno 2 `JB`, 1 byte

```
E

```

Attempt This Online!

### Thunno 2, 3 bytes

```
CEJ

```

Attempt This Online!

Port of Riley's 05AB1E answer. Converts to charcodes and checks if even. Then, joins the resulting list.

# Answer
> 0 votes
# (,) `N`, ~~116~~ 108 Chars or \\$108\log\_{256}(3)\approx21.4\\$ Bytes

```
((),()()()()()()())(,,,,(()(),((()()())))(()(),(),(),,(()()),()((),,,,(),,(())))(()(),(),()(),,(()()),()()))

```

Try It Online!
Or, without flags, for 138 chars or 27.34 Bytes

```
((),()()()()()()()()()())(,,,,(()(),((()()())))(()(),(),,(())(())(())()(),(()()),(())(())(())(()))(()(),(),,(())(())(())(()),(()()),()()))

```

Try It Online!
Basically, it outputs 1 (with flags) or \32 (without flags) if the char code is greater than or equal to that of \50 (with flags) or \40 (without flags), and outputs 2 (with flags) or \40 (without flags) otherwise.
The reason 1 and 2 are written as 1 and 2 rather than as \49 and \50 is because they are outputted numerically, hence the need for the `N` flag to remove seperators. All others are encoded in the code by char code.

---
Tags: code-golf, string
---


title: Element of string at specified index

text:
# Question
Title: Element of string at specified index
Given a string `s` and a non-negative number `n` less than the length of `s`, output the character at the `n`-th position of `s`.

0-indexing and 1-indexing are allowed. For 1-indexing, `n` will be positive and less than or equal to the length of `s`.

`s` will consist of printable characters only.

Any reasonable input/output is permitted. Standard loopholes apply.

Testcases (0-indexing):

```
n s        output
0 "abcde"  a
1 "abcde"  b
2 "a != b" !
3 "+-*/"   /
4 "314159" 5

```

Testcases (1-indexing):

```
n s        output
1 "abcde"  a
2 "abcde"  b
3 "a != b" !
4 "+-*/"   /
5 "314159" 5

```

This is , so shortest answer in bytes wins.

# Answer
> 9 votes
# MATL, 1 byte

```
)

```

Try it online!

Well, hard to make it much simpler. `)` indexes the first input, using the second input value. This is 1-indexed.

# Answer
> 8 votes
## Alice, 5 bytes

```
I&IO@

```

Try it online!

As usual it's much shorter if we avoid Ordinal mode and use an abysmal input format. Here, the first character's code point is used as the integer input. The remainder of the input is the string. The index is 1-based.

### Explanation

```
I   Read a character and push its code point.
&I  Read that many more characters and push them.
O   Output the last one we read.
@   Terminate the program.

```

# Answer
> 7 votes
# Python, 15 bytes

```
str.__getitem__

```

or

```
lambda s,i:s[i]

```

Both take 2 arguments: the string and the index. 0-indexed.

# Answer
> 6 votes
## Haskell, 4 bytes

```
(!!)

```

0-based indexing. Usage example: `(!!) "Hello" 1`-\> `'e'`.

# Answer
> 5 votes
# Octave, 10 bytes

```
@(s,n)s(n)

```

Takes a string `s`, and a number `n` as input, and returns the `n`th character of `s`.

# Answer
> 5 votes
# Retina, ~~28~~ ~~20~~ 19 bytes

*Saved 8 bytes thanks to @MartinEnder by not using balancing groups*

*Saved 1 byte thanks to @mbomb007 by using `^.+` instead of `^\d+`*

```
^.+
$*
+`1¶.
¶
!1`.

```

Try it online!

The program is 0-indexed.

# Answer
> 4 votes
# 05AB1E, 1 byte

0-indexed.

```
è

```

Try it online!

# Answer
> 3 votes
## CJam, 3 bytes

```
{=}

```

Try it online!

`=` is the built-in for list/string indexing.

# Answer
> 3 votes
## Alice, 10 bytes

```
/@!O?]&
 I

```

Try it online!

Expects the string on the first line and the 0-based index on the second line.

### Explanation

Despite its wealth of built-ins, string indexing doesn't exist in Alice. The reason is that it requires both an integer and a string parameter, and all commands in Alice are strictly integers to integers or strings to strings.

In general, the main way to perform any operations on strings that require or result in integers is to store the string on the tape in Ordinal mode, which you can then manipulate with integers in Cardinal mode.

```
/    Reflect to SE. Switch to Ordinal. While in Ordinal mode, the IP bounces
     diagonally up and down through the program.
I    Read one line from STDIN and push it.
!    Store the string on the tape. This writes the character codes into consecutive
     tape cells starting at the tape head. (It also writes a -1 at the end as a
     terminator, but the tape is initialised to -1s anyway).

     The next few commands are junk that luckily doesn't affect the program:

?      Load the string from the tape and push it to the stack again.
&      Fold the next command over this string. That is, for each character
       in the string, push that character, then execute the command.
?      So we're folding "load" over the string itself. So if the string is "abc"
       we'll end up with "a" "abc" "b" "abc" "c" "abc" on the stack.
!      Store the top copy of "abc" on the tape (does nothing, because it's
       already there).

     Now the relevant part of the program continues.

I    Read another line from STDIN, i.e. the string representation of the index.
/    Reflect to W. Switch to Cardinal. The IP wraps to the last column.
&    Implicitly convert the string to the integer value it represents and
     repeat the next command that many times.
]    Move the tape head right that many cells. Note that Ordinal and Cardinal
     mode have separate tape heads, but they are initialised to the same cell.
?    Load the value from that cell, which is the code point of the character
     at the given index.
O    Print the corresponding character.
!    This discards or converts some of the strings on the stack and writes some
     value back to the tape, but it's irrelevant.
@    Terminate the program.

```

# Answer
> 3 votes
# Prolog (SWI), ~~40~~ 37 bytes

```
q(L,N,A):-nth0(N,L,X),char_code(A,X).

```

Try it online!

# Answer
> 3 votes
# Cubix, 8 bytes

```
t@poIA//

```

This solution is 1-indexed. The input should consist of a number first, then a separator (that is not a digit or a `.`) and then the string.

Try it online!

# Answer
> 3 votes
# Jelly, 1 byte

Try it online!

# Answer
> 3 votes
# Brachylog, 2 bytes

```
∋₎

```

Try it online!

### Explanation

unifies its output with an element of the Input. With  as subscript, it will unify its output with the `I`th element of `S`, with `[S,I]` as input.

# Answer
> 2 votes
# Japt, 2 bytes

```
gV

```

This solution is 0-indexed.

Try it online!

# Answer
> 2 votes
# JavaScript, ~~11~~ 10 bytes

```
s=>n=>s[n]

```

Uses 0-based indexing.

*-1 byte thanks to @Leaky Nun*

```
f=
s=>n=>s[n]
console.log(f("abcde")(0));
console.log(f("abcde")(1));
console.log(f("a != b")(2));
console.log(f("+-*/")(3));
console.log(f("314159")(4));
```

# Answer
> 2 votes
# Carrot, 16 bytes

```
$^//.{#}/S1//.$/

```

Try it online!

The input format is as such:

```
string
index

```

And the program is 1-indexed.

### Explanation

Carrot has several global variables, one for each type: string, float and array (others to be implemented soon). The program starts in string-mode, where all the operators will affect the global string variable. And I call these variables the "stack".

(Example input: `abcdef\n3`)

```
$                          Get the first line of the input and set the stack-string to this value
^                          Exit caret-mode
                           stack-string = "abcdef"
/                          Operator (behaves differently depending on the argument)
 /.{#}/                     And the argument to this operator is a regex, so this program gets the matches of this regex into the stack-array
  .                          Any character
   {#}                       Pops a line from the input. So now this evaluates to # of any character where # is the second line of the input (in this case, 3)
                           stack-array = ["abc"]
                           And now we just need to get the last character in this string, but first
S1                         Join the array on the number 1 and set this to the stack-string. Because the array only contains one element, the number 1 does not appear in the stack-string.
                           stack-string = "abc"
/                          Operator; because the argument is a regex, this retrieves the matches of the regex:
 /.$/                       Get the last character in the string
                           stack-array = ["c"]

```

Now this returns a one element array containing a string of length one, but it is shown as a string in the website.

If we really wanted to give the result as a string, we could easily do `S","` at the end, but it doesn't matter because the output still looks the same on the interpreter.

# Answer
> 2 votes
# \>\<\>, 13 + 1 = 14 bytes

+1 for `-v` flag to take input

```
:?!\i~1-
io;\

```

*Thanks to @steenbergh for notifying me about the `-v` flag and saving me 3 bytes!*

Input the index with the command line argument `-v [index]` (0-indexed) and input the string through stdin.

Try it online!

### Explanation

The stack starts with the index on top.
`:` duplicates it.
`?` ignores the next character if the index is 0. (Popping it off the stack)
If it is zero, `\` reflects the direction to go down. Then, it is reflected to the right with the next `\`. It wraps around and executes `i`nput a character, `o`utput it and `;` halts execution.
If not, `!` skips the next instruction, so it doesn't go down.
`i~` inputs a character and then immediately discards it.
`1` pushes 1.
`-` subtractes `1` from the index, so one character in the input is consumed and the index is decremented. The program loops around back to the `:`.

# Answer
> 2 votes
# S.I.L.O.S, 43 bytes

```
loadLine
readIO
a=256+i
a=get a
printChar a

```

Try it online!

Simple enough.

# Answer
> 2 votes
# BF, 9 bytes

```
,[->,<]>.

```

The index is taken via the character code of a char (like the Alice submission). Following that, we have the string.

Try it online!

The TIO link uses a Bash wrapper and the input can be changed in the header file (the reason for the wrapper is so that we can see the bytes).

# Answer
> 1 votes
## Clojure, 3

```
nth

```

:P What can you do when there is a built-in for this? This works on lists, vectors, strings and sequences. It is either O(1) or O(n), depending on the used datatype.

# Answer
> 1 votes
## Batch, 32 bytes

```
@set/ps=
@call echo(%%s:~%1,1%%

```

Reads `s` from STDIN and takes `n` as a command-line parameter.

# Answer
> 1 votes
# GolfScript, ~~7~~ 4 bytes

```
~1/=

```

Try it online!

I suck in GolfScript, so I value Martin Ender's help.

# Answer
> 1 votes
# Turtlèd, 9 bytes

```
!?:[*l+].

```

**Try it online!**

## explanation:

First off, Turtlèd is grid based, with a turtle thing. There are grid cells the turtle can move left, up, down, and right on, and can write things on the grid cells.

```
[the first grid cell the turtle starts on is marked with a *]
!         input the string into the string variable

 ?        input the number into the number variable

  :       this command takes the number variable and moves right that many.
          hence this moves right by the amount inputted

   [*  ]  this is an `until` loop. the * there means that `until` the turtle ends the loop
          on a grid cell with * written on it (that is, the first cell), it will execute
          the code inside again and again

     l+   the code inside the while loop. the `l` moves the turtle left, and the +
          increments the string pointer. the string pointer is used with the string var;
          when you want to write something from the string, you use `.`, which writes
          the pointed char. the pointed char is the n-th character of the string, n being
          the value of the string pointer. this code will execute until the l moves
          the turtle back on to the origin cell. since we moved right by the number
          inputted, this will increase the string pointer (which starts at 1)
          by the amount inputted.

       .  write the pointed char, which was dealt with in the previous comment.
          if 0 is inputted, turtle stayed on the origin square, and executed none
          of the loop, and turtle writes the first char of string input.
          if 1 is inputted, turtle moved one right, moved one left and incremented
          string pointer once, which means the second char is written. and so on.

          [the char of input has been written over the origin square]
          [implicitly the grid is outputted, which has spaces and blank lines taken out]
          [this is the requested char outputted, plus an unavoidable trailing newline
          due to how I made the interpreter. sue me]

```

# Answer
> 1 votes
# sed, 31 bytes

```
:
/^1/{s:1 .: :;b}
s: (.).*:\1:

```

Try it online!

Input: index and the string, separated by one space. Index in unary, but zero-based.

# Answer
> 1 votes
# Axiom, 1 byte

```
.

```

1-Indexing... string.index is the value of string at index some test

```
(5) -> "123".6
   >> Error detected within library code:
   index out of range
    protected-symbol-warn called with (NIL)

(5) -> "123".0
   >> Error detected within library code:
   index out of range
protected-symbol-warn called with (NIL)

(5) -> ["123".i  for i in 1..3]
   (5)  [1,2,3]
                                                     Type: List Character

```

Where you see Axiom warn for index out of space too

# Answer
> 1 votes
# Dyvil, 4 Bytes

```
_[_]

```

Creates an anonymous function that takes a `String` and an `int` and returns a `char`.

Usage:

```
let f: (String, int) -> char = _[_]
print f("abc", 1) // b

```

# Answer
> 1 votes
# Pip, 3 bytes

```
a@b

```

This is 0-based. Try it online!

# Answer
> 1 votes
## QBasic 4.5, 24 bytes

```
INPUT a$,b:?MID$(a$,b,1)

```

Pretty straightforward.

# Answer
> 1 votes
# Vim, 8 bytes

```
DJ@"|xVp

```

Since V is backwards compatible, you can Try it online!

# Answer
> 1 votes
# Mathematica, 18 bytes

```
#~StringTake~{#2}&

```

Basic solution, but unfortunately the function name is quite long.

# Answer
> 1 votes
## C#, 11 bytes

```
s=>n=>s[n];

```

# Answer
> 1 votes
# Python 3, 28 bytes

```
print(input()[int(input())])

```

# Answer
> 1 votes
# Java 8, ~~18~~ ~~17~~ 12 bytes

```
s->s::charAt

```

-5 bytes saved thanks to *@Jakob*.

Try it here.

# Java 7, 43 bytes

```
char c(String s,int n){return s.charAt(n);}

```

Try it here.

Both 0-indexed.

# Answer
> 1 votes
## (kona), 0 bytes (noncompeting); 1 byte

In K, list access (as function application) is implicit. As such, we can do

```
q)"abcdef"0
"a"

```

But that's not really in the spirit of things, so we'll make the application of 0 on "abcdef" explicit for 1 byte:

```
q)"abcdef"@0
"a"

```

# Answer
> 1 votes
# TI-Basic, 14 bytes

```
Prompt Str0,N
sub(Str0,N,1

```

Returns the Nth 1-indexed character of the string.

Noncompeting 10 bytes:

```
Prompt N
sub(Ans,N,1

```

run with: `"string":prgmNAME` then input the number. I can't see the upvote/downvote ratio of this meta post on whether different input types are allowed, and it doesn't say in the tag-wiki, so I'm assuming they aren't.

# Answer
> 1 votes
# brainfuck, 17 bytes

...because why not?

```
,[,>+<-]>[<,>-],.

```

Try it online!

Uses 0-indexing, takes number in unary, `n` separated from `s` by .

This separates `n` from `s` with a newline.

# Answer
> 1 votes
# Ruby, 9 bytes

```
proc &:[]

```

How Ruby handles operator overloading is `:+`, `:-`, `:*`, `:[]`, etc. are defined as methods, so `1+2` is essentially `1.+(2)`. `:[]` is the symbol for the subscripting "operator", which when converted to a `proc` calls the `:[]` method with the first as a receiver and the second as an argument. E.g., `(proc &:[]).call("asd",0) == "asd".[](0) == "asd"[0]`

# Answer
> 1 votes
# J-uby, 3 bytes

```
:[]

```

`[]` is the subscripting operator. Example run:

```
irb(main):001:0> f = :[]
irb(main):002:0> f.call("string", 2)
=> "r"

```

# Answer
> 1 votes
# Integral, 2 Bytes

Integral doesn't have an `a[n]` built-in. Unfortunately it does have some slicing built-ins, which makes a 2-byter possible...

```
rn

```

Try it!

## Explanation

```
r   Last b
 n  Head

```

# Answer
> 1 votes
# Factor, 3 bytes

```
nth

```

Try it online!

# Answer
> 1 votes
# Vyxal, 1 byte

```
i

```

Try it Online!

Can't get much simpler than this.

# Answer
> 1 votes
# Thunno 2, 1 byte

```
i

```

Attempt This Online!

Built-in.

# Answer
> 0 votes
## C, 18 Bytes

```
#define f(s,n)s[n]

```

Try it online

# Answer
> 0 votes
# PHP, 22 Bytes

```
<?=$argv[1][$argv[2]];

```

Try it online!

# Answer
> 0 votes
# Swift - 53 bytes

```
func f(a:String,i:Int){print(Array(a.characters)[i])}

```

A function `f` that can be used as `f(a: "abcdef",i: 3)`. It is 0-indexed.

**Check it out!**

# Answer
> 0 votes
## QBIC, 8 bytes

```
?_s;,:,1

```

Explanation:

```
?     PRINT
_s    Substring(in$, start, length)
  ;   Reads a string from the cmd line as in$
  ,:  Reads an int from the command line as start
  ,1  One character
      Statement delimeter | is auto-added at EOF.

```

This is 1-based. It uses QBIC's new ability to inline `;` and `:`. Previously, to get `s` and `n`, you needed to do this:

```
;:?_sA,a,1

```

That would create the assignment of a cmd line arg to `A$` and `a` resp. Now we can skip assignment: the interpreter extracts the assignment and moves those to the top of the script.

# Answer
> 0 votes
# Fireball, 3 bytes

1-indexed.

```
╡1╞

```

Explanation:

```
╡         Get the first n characters of the input
 1╞       Get the last character of the that

```

Alternatively, for 4 bytes:

```
╡r↔♥

```

Explanation:

```
╡      Get the first n characters of the input
 r     Reverse
  ↔♥   Get the first character

```

# Answer
> 0 votes
# Perl 6, 18 bytes

```
{substr $^a,$^b,1}

```

I'm a little surprised it can't be done shorter. By me, anyway.

# Answer
> 0 votes
# Axiom,61 bytes

```
f(s:String,n:PI):Union(Character,Complex INT)==(n>#s=>%i;s.n)

```

1-Indexing; it return the required char or it return the %i=sqrt(-1) for error if n\> lenght(s) Some test

```
(4) -> [f("123",i) for i in 1..10]
   (4)  [1,2,3,%i,%i,%i,%i,%i,%i,%i]
                              Type: List Union(Character,Complex Integer)
(5) -> f("123", 0)
   Conversion failed in the compiled user function f .
   Cannot convert from type Integer to PositiveInteger for value
   0

```

instead of doing less (few characters) instead of do more (more cicle) instead to do fast... to do the right

# Answer
> 0 votes
# LLVM IR, 72 bytes

```
define i8*@a(i8*,i64){
entry:%2=getelementptr i8,i8*%0,i64%1
ret i8*%2
}

```

Takes a `(string, index)` (0-indexed) as argument, where `string` is a c-string. Returns an `i8*` (`char*`) which points to the desired char. I can't directly move the `getelementptr` with the `ret` instruction as `%0` and `%1` are function-local and therefore need their own instruction

Try it online!

# Answer
> 0 votes
# PowerShell, 18 Bytes

```
param($s,$i)$s[$i]

```

indexes into param 1 (`$s`) using param 2 (`$i`)

# Answer
> 0 votes
# Perl 6, 15 bytes

```
{$^s.comb[$^n]}

```

Try it

## Expanded:

```
{ # bare block lambda with placeholder parameters ｢$n｣ and ｢$s｣

  $^s      # declare second parameter
  .comb\   # split it into graphemes
  [ $^n ]  # get the value indexed by the first parameter
}

```

# Answer
> 0 votes
# Groovy 11 bytes

```
{s,n->s[n]}

```

0-indexed.

# Answer
> 0 votes
# Charcoal, 3 bytes

```
§ＳＮ

```

# Explanation

```
§     At index
 Ｓ   Input string
   Ｎ Input number

```

Try it online!

# Answer
> 0 votes
# APL (Dyalog), 1 byte

(Index) or  (Pick)

Try them online!

They only differ for higher rank arrays and nested arrays:

`2⌷A` will choose the second element or second row, leaving any nesting
`2⊃A` will pick the second element, and attempt to remove one level of nesting

`2 3⌷A` will choose the element at row 2 column 3
`2 3⊃A` will pick the third element of the second element

`(⊂2 3)⌷A` will choose the second and third elements or rows
`(⊂2 3)⊃A` will pick the element at row 2 column 3

# Answer
> 0 votes
# Chip, 114 bytes

```
*Z
,x.z.
`@z\{Aa
,x.|*
`@z\{Bb
,x.|
`@z\{Cc
,x.|*
`@z\{Dd
,x.|
`@z\{Ee
,x.|*
`@z\{Ff
,x.|
`@z\{Gg
,x.|*
`@z\{H
S{*

```

The first byte of input is a 0-based index, the remainder is the string to process: `\x02abcde`.

Try it online!
In this TIO, a newline character is the index, which means an index of `0x0a` = 10.

Test cases!
These use hex input + printf to make it clearer what's happening.

### How does it work?

`S{*`

This suppresses output for all bytes, by default. If powered, this can be overridden. It is a not-gate based on an xor-gate (`{`).

`Aa`, `Bb`, `Cc`, etc.

These relay the input to the output for every byte, unless suppressed. Note that the `h` is missing, this is because we never need to output something with the high bit set.

```
,x.
`@z\{D

```

This is the real meat of it all. There are eight of these, one for each bit of the index (a one-byte index means that indexes are not able to be specified above 255). This reads in the index on the first cycle only with switches (`\`). The index bits have been flipped with an xor gate (`{`), which is almost negation. Then, for each character of the string, this value is incremented via some half-adders (`@`). When this value is incremented from `0xff` to `0x00`, it uses the carry from the high bit to unsuppress output for that character, meaning that it is printed.

# Answer
> 0 votes
# Ruby, 11 bytes

```
->n,s{s[n]}

```

Try it online!

# Answer
> 0 votes
# Pyth - 3 bytes

```
@wE

```

Try it here

# Answer
> 0 votes
# RProgN 2, 1 byte

```
ü

```

Just a builtin!

Try it online!

# Answer
> 0 votes
# SmileBASIC 3, 17 bytes

Woo! String indexing!

```
DEF A S,N?S[N]END

```

Defines a command `A` to print the result. Uses 0-indexing. Call like `A "string",number`.

## No string functions, 29

Here's one that uses absolutely no string-specific built-ins.

```
DEF A S,N
COPY T$,S,N,1?T$END

```

`COPY` is a memory copy command, capable of copying data between two compatible types. It's usually used for arrays, but it works on strings as well.

# Answer
> 0 votes
# tcl, 18

```
string index $s $n

```

Input is on the variables `s` and `n`

Output is the return of the script

demo — Iterates a list with all test case pairs and outputs them to console.

# Answer
> 0 votes
# x86 Machine Code, 13 bytes

```
8B 44 24 04 03 44 24 08 8A 08 8A C1 C3

```

Which disassembles to:

```
  00000000: 8B 44 24 04        mov         eax,dword ptr [esp+4]
  00000004: 03 44 24 08        add         eax,dword ptr [esp+8]
  00000008: 8A 08              mov         cl,byte ptr [eax]
  0000000A: 8A C1              mov         al,cl
  0000000C: C3                 ret

```

# Answer
> 0 votes
# Excel, 13 bytes

```
=MID(B1,A1,1)

```

1-indexed `n` in A1. Text in B1.

# Answer
> 0 votes
# Husk, 1 byte

Another built-in, 1-indexed:

```
!

```

Try it online!

# Answer
> 0 votes
## Julia 0.6.0 (13 bytes)

`f(s,n)=(s[n])`

s is a string, n the index. Pretty simple since Julia considers strings as arrays so I just call the index in the array. Julia is a 1 indexing.

Try it online!

# Answer
> 0 votes
# Cubically, ~~18~~ 16 bytes

```
$:7~(~*1-1/1)6@7

```

*(1-based index)*

Input format is `n abcde`, where `n` is the index, and `abcde` is the string.

How it works:

```
$:7              Get numeric input and set notepad to it
   ~             Skip next character (the space)
    (       )6   Do while the notepad is nonzero
     ~           Get next character of input
      *1-1/1     Subtract 1 from notepad (found by Kamil Drakari)
              @7 Output the current input character

```

Try it online

# Answer
> 0 votes
# T-SQL, 29 bytes

```
SELECT SUBSTRING(s,n,1)FROM t

```

Input is taken via a pre-existing table **t** with integer **n** and string **s**, per our IO standards.

# Answer
> 0 votes
Rebol, Red 4 bytes

```
s/:n

```

(need to make body at least 30 to satisfy submission nanny)

# Answer
> 0 votes
# MathGolf, 1 byte

```
§

```

Try it online!

Finally a showcase for the implicit input! Works regardless of the order of the input (if the string or int comes first).

# Answer
> 0 votes
# *Acc!!*, 85 bytes

```
N
Count i while _/128^i/32 {
_+128^(i+1)*N
}
Count j while N/48 {
_/128
}
Write _%128

```

Takes the string on one line of stdin and the 0-based index, in unary, on the following line. (I hope unary is okay. Decimal I/O is a pain in *Acc!!*) Try it online!

### Commented

```
# Read printable ASCII characters into the accumulator, storing the first character
# in the least significant place
N
Count i while _/128^i/32 {
_+128^(i+1)*N
}
# Read 1s, shifting the accumulator down by one character's worth each time
Count j while N/48 {
_/128
}
# We have now removed the first i characters from the original input string,
# which means the first remaining character is the one at index i (0-based)
Write _%128

```

# Answer
> 0 votes
# Perl 5 `-plF`, 9 bytes

```
$_=$F[<>]

```

Try it online!

# Answer
> 0 votes
# Befunge-98 (FBBI), 5 bytes

1-indexing. Input is the index, a space and the string.

```
&k~,@

```

Try it online!

This just reads *index* characters as input and prints the last one.

---
Tags: code-golf, string
---


# Question
Title: Is a number divisible by each of its digits?
My friend and I were working on a lab in our AP Computer Science class and decided to code golf one one the problems since we still had half the class free after we finished. Here is the question:

> Given a number n, is n divisible by each of its digits?

For example, 128 will pass this test- it is divisible by 1,2, and 8. Any numbers with a zero automatically disqualify the number. While you may use other languages and post solutions with them if you like, we are most interested in seeing how compact people can make the program in Java, as that is the language we use in the class. So far, we both have 51. Here is my current code:

```
public boolean dividesSelf(int n){for(int p=n;n%10>0;)n/=p%(n%10)>0?.1:10;return n<1;}
// 51 characters

// Breakdown:
// for(int p=n;         Saves one semicolon to put declaration into for loop
// n%10>0;)             Basic check-for-zero
// n/=                  Pretty simple, discarding one number off of n at a time
// p%(n%10)>0?          If p (the given value) is not divisible by n%10 (the current digit)...
// .1:10;               Divide by .1 (multiply by 10) so it fails the check next iteration. If it is divisible, divide by 10 to truncate the last digit
// return n<1           If the number was fully divisible, every digit would be truncated, and n would be 0. Else, there would still be non-zero digits.

```

## Requirements

The method signature can be whatever you want. Just count the function body. Make sure, though, that the method returns a boolean value and only passes in *one numeric* parameter (not a string).

The code must be able to pass all of these cases (in order to stay true to the directions of the original question, *only* boolean true and false values count if the language supports booleans. If and only if your language does not have boolean variables you may represent false with 0 and true with any nonzero integer (preferably 1 or -1):

```
128 -> true
 12 -> true
120 -> false
122 -> true
 13 -> false
 32 -> false
 22 -> true
 42 -> false
212 -> true
213 -> false
162 -> true
204 -> false

```

Also, we didn't count whitespace, so feel free to do the same, unless the whitespace is essential to the working of the program (so newlines in Java don't count, but a single space between `int` and `x=1` does count.) Good luck!

# Answer
# Perl 6, 13

```
sub golf($_) {
   $_%%.comb.all
}

```

Uses the implicit variable `$_``$_ %% .comb.all` is equivalent to `$_ %% all($_.comb)`. `%%` is the "is divisible" operator, and `comb` with no additional argument returns a list of the characters in a string. As an example, if the argument is 123, then the function evaluates

```
123 %% all(123.comb)

```

which is

```
123 %% all(1, 2, 3)

```

junction autothreading makes it

```
all(123 %% 1, 123 %% 2, 123 %% 3)

```

which is

```
all(True, False, True)

```

which is false in boolean context because it's an "all" junction and clearly not all of its elements are true.

It should be possible to coerce the return value to `Bool` and hide the junction-ness from callers by making the function signature `sub golf($_ --> Bool())`, but coercions in function signatures don't work yet in Rakudo. The return value is still correctly true or false, it's just not `True` or `False`.
> 22 votes

# Answer
# C# and System.Linq - 26 / 40

Per the rules, not counting the method declaration itself.

```
bool dividesSelf(int i) {
    return(i+"").All(d=>i%(d-48d)<1);
}

```

Showing that once again, C# is the superior choice when Java is under consideration... I kid, I kid!

Unfortunately, this function (and many in other answers) will not produce correct results for negative input. We can fix this, but the solution loses a lot of its charm (and grows to 46 characters in length):

```
return(i+"").All(d=>d>48&&i%(d-48)==0||d==45);

```

**Edit**: shaved off one character with Tim's suggestion.

**Edit**: with the introduction of expression-bodied members in C# 6, we can pare this down further by cutting out the `return`:

```
bool dividesSelf(int i) =>
    (i+"").All(d=>i%(d-48d)<1);

```

for a total of 26 characters (in my opinion, the `=>` should not be included any more than braces would be). The version handling negative numbers can be similarly shortened.
> 21 votes

# Answer
## APL (~~13~~ 11)

(apparently the brackets don't count)
```
{0∧.=⍵|⍨⍎¨⍕⍵}

```

Explanation:

* `⍎¨⍕⍵`: evaluate each character in the string representation of
* `⍵|⍨`: for each of those, find the modulo of it and
* `0∧.=`: see whether all of those are equal to `0`

Testcases:

```
      N,[.5] {0∧.=⍵|⍨⍎¨⍕⍵} ¨ N←128 12 120 122 13 32 22 42 212 213 162 204
128 12 120 122 13 32 22 42 212 213 162 204
  1  1   0   1  0  0  1  0   1   0   1   0

```
> 17 votes

# Answer
## Python 2: 43 chars

```
f=lambda n:any(n%(int(d)or.3)for d in`n`)<1

```

Checks whether the number has any nonzero remainders modulo its digits, and outputs the negation of that. Zero digits are handled strangely: since computing `%0` causes an error, digits of `0` are replaced with `.3`, which seems to always give a nonzero result due to floating point inaccuracies.

The function body is 32 chars.
> 15 votes

# Answer
## Perl - 27 bytes

```
sub dividesSelf{
    $_=pop;s/./!$&||$_%$&/ger<1
}

```

Not counting the function signature, as instructed.

**Sample Usage:**

```
use Data::Dump qw(dump);
for $i (128, 12, 120, 122, 13, 32, 22, 42, 212, 213, 162, 204) {
  printf "%3d -> %s\n", $i, dump(dividesSelf $i);
}

```

**Sample Output:**

```
128 -> 1
 12 -> 1
120 -> ""
122 -> 1
 13 -> ""
 32 -> ""
 22 -> 1
 42 -> ""
212 -> 1
213 -> ""
162 -> 1
204 -> ""

```

---

Addressing the problem specification: "Only boolean true and false values count. Truthy/falsey values do *not* count."

```
use Data::Dump qw(dump);
dump(1 == 1);
dump(0 == 1);

```

Outputs:

```
1
""

```

'True' and 'False' are defined as `1` and `""`.

**Erratum:**
As Brad Gilbert rightly points out, perl defines *true* as a scalar which is both the integer `1` and the string `"1"` simultaneously, and *false* as a scalar which is both the integer `0` and the string `""` simultaneously.
> 14 votes

# Answer
# JavaScript ES6, ~~39~~ ~~32~~ 28 bytes

```
v=>[...""+v].every(x=>v%x<1)

```

Thanks core1024 for the suggestion to replace `(""+v).split("")` with `[...""+v]`, and openorclose for suggesting the use of `every` function.

The answer currently doesn't contain one bit of my code :O

### Previous solution

```
v=>[...""+v].filter(x=>v%x|!+x)==""

```

`==""` is not a valid way to check if an array is empty, since `[""]==""` returns `true`, but the array is guarantee to contain non-empty string, so it works here.

The rest are quite standard shorthand type conversion in JavaScript.
> 13 votes

# Answer
# CJam, ~~11~~ 10 bytes

```
{
    _Ab:df%:+!
}:F;

```

This defines a function named `F` and discards the block from the stack.

Try it online.

### Test cases

```
$ cjam <(echo '{_Ab:df%:+!}:F;[128 12 120 122 13 32 22 42 212 213 162 204]{F}%p')
[1 1 0 1 0 0 1 0 1 0 1 0]

```

### How it works

```
_      " Copy the integer on the stack.                                          ";
Ab     " Push the array of its digits in base 10.                                ";
:d     " Cast each digit to Double.                                              ";
f%     " Take the integer on the stack modulus each of its digits.               ";
:+     " Add the results.                                                        ";
!      " Push the logical NOT of the sum.                                        ";

```
> 13 votes

# Answer
## Java 8, 46 Bytes (method body)

Using Jeroen Mostert's converting to double trick.

```
public static boolean dividesSelf(int n) {
    return(""+n).chars().allMatch(x->n%(x-48d)<1);
}

```
> 9 votes

# Answer
# Pyth, 12 bytes

```
!f|!vT%vzvTz

```

This filters the characters in the string for being either zero (`!vT`) or not dividing the input (`%vzvT`), then takes the logical not of the resulting list.

Try it here.
> 8 votes

# Answer
# Ruby, 44 bytes (function body: 37)

Probably has potential to be golfed further.

```
f=->n{n.to_s.chars.all?{|x|x>?0&&n%x.hex<1}}

```

Input taken through function `f`. Example usage:

```
f[128] # => true
f[12]  # => true
f[120] # => false
...

```
> 8 votes

# Answer
# Python - ~~59~~ ~~50~~ ~~49~~ 47 bytes

```
f=lambda n:all(c>'0'and 0==n%int(c)for c in`n`)

```

I'm sure there's a faster way... oh well.

*Edit* \- Thanks to FryAmTheEggman for the golfing tips.

*Edit 2* \- FryAmTheEggman may as well have written this at this point, oops

*Edit 3* \- Hands up if you didn't even know genexps were a thing. ...Just me?
> 8 votes

# Answer
## Pyth 11

```
!f%Q|vT.3`Q

```

This combines @isaacg's and @xnor's answers. It filters out digits from the input by checking the value of `input % (eval(current_digit) or .3)`. Then it checks if the resulting string is empty or not.

Came across another couple same-length variants:

```
!f%Q|T.3jQT
!f|!T%QTjQT

```

Try it online.
> 8 votes

# Answer
# Bash + coreutils, 44 bytes

The full function definition is:

```
f()((`tr 0-9 \10<<<$1``sed "s/./||$1%&/g"<<<$1`))

```

I'm not sure how to score this as normally shell functions use a single set of `{}` or `()` to contain the function body. I found here I could also use double `(())` to contain the function body which causes an arithmetic expansion which is what I need here. So for now I am counting just one pair of those brackets - further discussion of this is welcome.

### Output:

```
$ for i in 128 12 120 122 13 32 22 42 212 213 162 204; do f $i; printf "%d " $?; done
1 1 0 1 0 0 1 0 1 0 1 0 $
$

```
> 5 votes

# Answer
# J - 14 char

The function body is the portion after the `=:`. If we want to minimize the character count for the whole function, that's the 15 char `*/@(0=,.&.":|])`.

```
f=:0*/@:=,.&.":|]

```

`,.&.":` is the shortest way in J to expand as number into a list of its decimal digits: convert to string, separate the digits, and convert each digit back into a number. `,.&.":|]` takes the input number (`]`) modulo (`|`) those digits. `0*/@:=` returns true if all the results were 0, else gives a false.

```
   f 162
1
   f every 204 212 213
0 1 0

```
> 4 votes

# Answer
# Java - ~~121~~ ~~102~~ ~~97~~ ~~79~~ 78 bytes

I just *know* this will get clobbered later. Oh well.

```
boolean b(int a){int m=10,j,t=1;for(;m<a*10;m*=10){j=10*(a%m)/m;if(j==0||a%j>0)t=0;}return t>0;}

```

I'll be back.
> 3 votes

# Answer
# Haskell - 100 54 38

```
f x=all(\y->y>'0'&&x`mod`read[y]<1)$show x

```

Still learning, critiques appreciated
> 3 votes

# Answer
## Julia 32 25 23

### Improved using digits

Also fixes problem with negative numbers

```
selfDivides(x)=sum(x%digits(x).^1.)==0

```

### Old method

All digits divide if the sum of all the remainders is 0. Like others, has a problem with negative numbers.

```
selfDivides(x)=sum(x.%(Float64["$x"...]-48))==0

```

## Output

```
[selfDivides(x) for x in [128,12,120,122,13,32,22,42,212,213,162,204]]
12-element Array{Any,1}:
  true
  true
 false
  true
 false
 false
  true
 false
  true
 false
  true
 false

```

### Improved method also handles BigInt

```
selfDivides(BigInt(11111111111111111111111111111111111111112))
true

```

however

```
selfDivides(BigInt(11111111111111111111111111111111111111113))
false

```

because

```
BigInt(11111111111111111111111111111111111111113) %3
1

```
> 3 votes

# Answer
# 05AB1E (legacy), 3 bytes

```
SÖP

```

Only `1` is truthy in 05AB1E, so this will output `1` if the input-integer is divisible by each of its digits.

For falsey test cases it either outputs `0`, or a multiple of the input if it contains `0`s (due to division by zero errors). If you want a distinct falsey output of `0`, you can add a trailing `Θ` (`== 1` builtin).

Try it online or verify all test cases.

**Explanation:**

```
S    # Convert the (implicit) input-integer to a list of digits
 Ö   # Check for each digit if it evenly divides the (implicit) input-integer
     # (results in 1 for truthy; 0 for falsey; and itself for division by zero errors)
  P  # Take the product of this list to check if all are truthy
     # (after which it is output implicitly as result)

```
> 3 votes

# Answer
# CJam, 15 bytes

```
{_Abf{_{%}1?}1b!}

```

`{}` is the closest thing to a function in CJam. I am just counting the body of the function

Use it like this:

```
128{_Abf{_{%}1?}1b!}~

```

To get either `1` (if the number is divisible) or `0` (if the number is not divisible by its digits).

Try it online here

**Explanation**

```
_Ab                "Copy the number and split it to its digits";
   f{      }       "For each digit, run this code block on the number";
     _{%}1?        "If the digit is 0, put 1, otherwise perform number modulus digit";
            1b     "We now have an array of modulus corresponding to each digit. Sum it up";
              !    "Negate the sum. If all digits were divisible, sum of modules will be"
                   "0, thus answer should be 1 and vice versa";

```
> 2 votes

# Answer
# C89, 43 bytes

```
unsigned char d(int n, int c) {
        int a=n%10;return!n||a&&!(c%a)&&d(n/10,c);
}

```

C89 doesn't have a boolean type. Hope that works. Also I used a second parameter to pass a copy of the original number through the stack, but the definition can be anything. To get the correct result you just have to call the function with the same value for both parameters (`d(128, 128)`).

**EDIT:** Applied suggested edits by an anonymous user
> 2 votes

# Answer
# C / C++, 58 bytes (44 in body)

**Invokes Undefined Behaviour** (see comments)

```
int d(int i){int j=i;while(i&&!(j%(i%10)))i/=10;return!i;}

```

`true` and `false` **are** 1 and 0, but feel free to add one character to the signature to return a `bool`.

And for fun, a recursive version which is smaller if you allow calls of the form `r(128,128)`

**Edit**: Now disallowed by the rules:

~~C / C++, 53 bytes (33 in body)
```
int r(int i,int j){return!i||!(j%(i%10))&&r(i/10,j);}

```~~
> 2 votes

# Answer
# CJam, 15 bytes

```
{_Abf{_g{%}*}:|!}

```

This is a block, the closest thing to a function in CJam. I'm only counting the body (i.e. omitting the braces). You can use it as follows:

```
128{_Abf{_g{%}*}:|!}~

```

Or if you want to test a series of inputs, you can do

```
[128 12 120 122 13 32 22 42 212 213 162 204]{{_Abf{_g{%}*}:|!}~}%

```

The block leaves `0` (falsy) or `1` (truthy) on the stack to indicate the result. (CJam doesn't have a Boolean type.)

Test it here.

Explanation:

```
_               "Duplicate input.";
 Ab             "Get base-10 digits.";
   f{      }    "This maps the block onto the list of digits, supplying the input each time.";
     _g         "Duplicate digit, get signum S (0 or 1).";
       { }*     "Repeat this block S times.";
        %       "Take input modulo digit.";
                "This leaves an array of zeroes for divisible digits, non-zeroes
                 for non-divisible digits, and non-zero junk for zeroes.";
            :|  "Fold OR onto this list. One could also sum the list with :+";
              ! "Logical NOT. Turns 0 into 1, and non-zero values into 0.";

```

# Alternative, also 15 bytes

```
{:XAb{X\_X)?%},!}

```

Explanation

```
:X              "Store input in X.";
  Ab            "Get base-10 digits.";
    {       },  "Filter this list by the result of the block.";
     X\         "Push another copy of X, swap with digit.";
       _        "Duplicate digit.";
        X)      "Push X+1.";
          ?     "Select digit itself or X+1, depending on whether digit is 0 or not.";
           %    "Take modulo. X%(X+1) will always be nonzero for positive integers.";
              ! "Logical NOT. Turns an empty list into 1 and a non-empty list into 0.";

```
> 2 votes

# Answer
# C11 - 44 Bytes in function body

Another C version, non recursive and without a floating point exception.

```
bool digit_multiple(int i)
{
    for(int n=i;i%10&&n%(i%10)<1;i/=10);return!i;
}

```

This will also work in C++, Java, and most other C-like languages.

Edited to include the improvement of primo's comment.
> 2 votes

# Answer
## R: ~~72~~ ~~67~~ 65

The function

```
f<-function(a)!(anyNA(a%%(d=as.double(strsplit(paste0(a),"")[[1]])))|sum(a%%d))

```

Thanks to @AlexA and @plannapus for the savings

Test run

```
i=c(128,12,120,122,13,32,22,42,212,213,162,204)
for(a in i){print(f(a))}
[1] TRUE
[1] TRUE
[1] FALSE
[1] TRUE
[1] FALSE
[1] FALSE
[1] TRUE
[1] FALSE
[1] TRUE
[1] FALSE
[1] TRUE
[1] FALSE

```
> 2 votes

# Answer
# PHP: 45 Characters

The character count is for the body of the function.

It is necessary to only pass the first parameter.

```
function t($n, $k=true, $s='str_split'){foreach($s($n)as$b)$k=$k&&$n%$b===0;return$k;}

```
> 2 votes

# Answer
# GNU Awk: 53 characters

The counted part:

```
for(;++i<=split($1,a,//);)r=r||!a[i]||v%a[i];return!r

```

The entire function:

```
function self_divisible(v, i, r)
{
    for (; ++i <= split($1, a, //); )
        r = r || ! a[i] || v % a[i]

    return ! r
}

```

As Awk has no boolean values, returns 1 tor true and 0 for false.
> 1 votes

# Answer
# JavaScript (ES6) 30

Function with one numeric parameter. Using % and subtraction, no need to special case '0' because 0%0 is NaN in JavaScript.

*Edit* Saved 1 char thx DocMax

```
F=n=>[for(d of t=n+'')t-=n%d]&&t==n

```

Just for fun, abusing the rule about not counting function signature, 4

```
Check=(n,t=n+'',q=[for(d of t)n-=t%d])=>t==n

```

**Test** In FireFox/FireBug console

```
console.log([128, 12, 120, 122, 13, 32, 22, 42, 212, 213, 162, 204]
.map(x=>+x + ' -> ' + F(x)).join('\n'))

```

*Output*

```
128 -> true
12 -> true
120 -> false
122 -> true
13 -> false
32 -> false
22 -> true
42 -> false
212 -> true
213 -> false
162 -> true
204 -> false

```
> 1 votes

# Answer
# PHP: 85 bytes (64 bytes on the body)

For this function to work, simply pass a string or a number.

`0` will correctly return false.

The code:

```
function f($n,$i=0){for($n.='';$n[$i]&&$t=!($n%$n[$i++]););return$t&&$i==strlen($n);}

```

Please, DO NOT SET THE 2ND PARAMETER!

# Javascript: 76 bytes (61 bytes on the body)

This is a rewrite of the previous function.

Not much changed between both versions.

Here is the code:

```
function f(n){for(i=0,n+='';n[i]/1&&(t=!(n%n[i++])););return t&&i==n.length}

```

---

# Polyglot: Javascript+PHP 187 ~~217~~ bytes (~~76~~ 84 bytes without boilerplate):

Why I made it?

Because of reason and maybe because I can!

~~Just ignore the error on PHP: it works anyway!~~
No longer needed, this was fixed by removing 3 bytes.

Here is the masterpiece:

```
if('\0'=="\0"){function strlen($s){return $s['length'];}}
function toString(){return'';}
function f($n){for($i=0,$n=$n.toString();$n[$i]/1&&($t=!($n%$n[$i++])););return $t&&$i==strlen($n);}

```

You can run this code both on your console and on a PHP interpreter!

---

Old version:

```
if('\0'=="\0"){function strlen($s){return $s['length'];}}
function s($s){return('\0'=="\0")?$s+'':str_replace('','',$s);}
function f($n,$i){for($i=0,$n=s($n);$n[$i]/1&&($t=!($n%$n[$i++])););return $t&&$i==strlen($n);}

```
> 1 votes

# Answer
# Octave, 33 (39 including function setup)

Using numeric-to-matrix conversion:

```
f=@(a)sum(mod(a./(num2str(a)-48),1))==0

```

Divide number elementwise by matrix X, where X is made by converting number to string and subtracting 48 to go from ASCII values to numbers again. Take modulo 1 to get decimal part of each division, confirm that all of these are zero (if any are NaN because of /0, the sum will be NaN and hence not zero).

Sample input using www.octave-online.net:

```
f=@(a)sum(mod(a./(num2str(a)-48),1))==0
for j=[128,12,120,122,13,32,22,42,212,213,162,204]
f(j)
end

```

Output:

```
ans =  1
ans =  1
ans = 0
ans =  1
ans = 0
ans = 0
ans =  1
ans = 0
ans =  1
ans = 0
ans =  1
ans = 0

```
> 1 votes

# Answer
# PHP - 74 71 64 Characters

Golfed:

```
function t($n){while($n>1){if(!($b=$n%10)||($n%$b)){return 0;}$n/=10;}return 1;}

```

Less Golfed:

```
function t($n){
    while($n>1){
        if( !($b=$n%10) || ($n%$b) )
            { return 0; }
        $n/=10;
    }
    return 1;
}

```

Test Results:

(Code)

```
$ans = array(128,12,120,122,13,32,22,42,212,213,162,204);
foreach($ans as $a)
{ echo "$a -> ".(t($a)?"True":"False").PHP_EOL; }

```

(Output)

```
128 -> True
12 -> True
120 -> False
122 -> True
13 -> False
32 -> True
22 -> True
42 -> True
212 -> True
213 -> True
162 -> False
204 -> False

```
> 1 votes

# Answer
# MATLAB - 39 characters

```
function [b] = dividesSelf(i)
b=all(~mod(i,sscanf(num2str(i),'%1d')))
end

```
> 1 votes

# Answer
**BASH - 117 characters**

```
f(){ [[ $1 =~ 0 ]]&& return 0 || r=;n=$1;for((i=0;i<${#n};i++));do r=$(($r+${n}%${n:$i:1}));done;return $(($r==0));}

```

tests

```
for N in 128 12 120 122 13 32 22 42 212 213 162 204; do
  f $N
  echo "${N} ->  $?"
done

128 ->  1
12 ->  1
120 ->  0
122 ->  1
13 ->  0
32 ->  0
22 ->  1
42 ->  0
212 ->  1
213 ->  0
162 ->  1
204 ->  0

```
> 1 votes

# Answer
## Javascript ES6, 33

```
n=>(""+n).replace(/./g,x=>n%x)==0

```

Test:

```
f=n=>(""+n).replace(/./g,x=>n%x)==0
console.log(
           [128, 12,  120,  122, 13,   32,   22,   42,  212, 213,  162, 204]
.map(f) == "true,true,false,true,false,false,true,false,true,false,true,false"
)
```
> 1 votes

# Answer
# 05AB1E, ~~6~~ 5 bytes

```
Ñ¨K0‹

```

Try it online!

# Explanation

```
Ñ¨K0‹  full program with implicit input  [213]
Ñ      push divisors                     [1, 3, 71, 213]
 ¨     remove the last element           [1, 3, 71]
  K    push a without b                  [2]
   0   push 0                            [2] [0]
    ‹  push a < b                        [0]
       output implicitly

```

`K` uses the implicit input `[213]` as a and the current stack `[1, 3, 71]` as b.
> 1 votes

# Answer
# Stacked, 11 bytes in the function body

```
[:10 tb\|all]

```

Try it online!

Takes a number from the stack and returns `1` if they are all divisible or `0` otherwise.

## Explanation

```
[:10 tb\|all]
[           ]   anonymous function (the function body)
 :10 tb         push digits of the number (*t*o *b*ase 10)
       \|       vectorized "divides" test
         all    ensure all are truthy (i.e. not 0)

```
> 1 votes

# Answer
# , 14 bytes

```
0=1#."."0@":|]

```

Try it online!

Small improvement on existing J answer.
> 1 votes

# Answer
# Vyxal, 3 bytes

```
fḊg

```

Try it Online!

### Explained

```
fḊg
f   # flatten input to get list of digits
 Ḋ  # divisible by
  g # minimum value of the individual lists whether the digit is divisible or not.
    #   If it is, `1`, if not `0`. So if 1 digit is not divisible, it returns `0` in the list, and the program takes it as the minimum.

```
> 1 votes

# Answer
# Japt, 7 bytes

Handling `0`s cost a couple of bytes (`x/0 = Infinity`).

```
ìeÈ©UvX

```

Try it

```
ìeÈ©UvX     :Implicit input of integer U
ì           :Convert to digit array
 e          :Does each return true
  È         :When passed through the following function as X
   ©        :  Logical AND with
    UvX     :  Is U divisible by X

```
> 1 votes

# Answer
# Ruby, 32 bytes

```
->n{n.digits.all?{_1>0&&n%_1<1}}

```

Attempt This Online!
> 1 votes

# Answer
# Fig, \\$3\log\_{256}(96)\approx\\$ 2.469 bytes

```
a%f

```

Try it online!

I really gotta fix `a`.

```
a%f # Returns 0 for truthy, "true" for falsey
 %  # Modulo the number
  f # By each of its digits
a   # Any != 0?

```
> 1 votes

# Answer
# Thunno 2, 3 bytes

```
dḊp

```

Attempt This Online!

#### Explanation

```
dḊp  # Implicit input   ->  128
d    # Cast to digits   ->  [1,2,8]
 Ḋ   # Divisible?       ->  [1,1,1]
  p  # Product          ->  1
     # Implicit output

```
> 1 votes

# Answer
## Python 2, ~85 ~83 characters (~75 ~73 just the function body)

Staying all numeric; count includes newlines and spacing.

```
def t(n):
 r=n
 while r:
  r,i=divmod(r,10)
  if not i or n%i:return 0>1
 return 1>0

assert(t(128)==True)
assert(t(12)==True)
assert(t(120)==False)
assert(t(122)==True)
assert(t(13)==False)
assert(t(32)==False)
assert(t(22)==True)
assert(t(42)==False)
assert(t(212)==True)
assert(t(213)==False)
assert(t(162)==True)
assert(t(204)==False)

```

Alternative, 88 characters in the function body:

```
def t(n):return '0' not in `n` and not reduce(lambda a,b:a or b,[divmod(n,int(x))[1] for x in `n`])

```

The approach feels shorter with map/reduce but with Python code it isn't.
> 0 votes

# Answer
# J (16)

```
+/@:|~_1&(10&#.)

```

Returns 0 when true, another number otherwise
> 0 votes

# Answer
# **Java 7, Score = ~~96~~ 76**

Since I can't compete with your number based method, I used a character based method instead. `a` has the input integer in it.

```
int c=0;for(char e:(""+a).toCharArray())c+=(e-=-48)<1||a%e>0?1:0;return c<1;

```

Here it is golfed indented with structure code:

```
public class T{

    public static void main(String[] args){
        System.out.println(new T().test(Integer.parseInt(args[0])));
    }

    boolean test(int a){
        int c=0;
        for(char e:(""+a).toCharArray())
            c+=(e-=-48)<1||a%e>0?1:0;
        return c<1;
    }

}

```

Here it is completely expanded:

```
public class Test{

    public static void main(String[] args){
        System.out.println(new Test().test(Integer.parseInt(args[0])));
    }

    boolean test(int number){
        String numberString = "" + number;
        int failed = 0;
        for (int a = 0; a < numberString.length(); a++){
            int charAt = numberString.charAt(a) - '0';
            if (charAt == 0 || number % charAt != 0){
                failed++;
            }
        }
        return failed < 1;
    }

}

```

**Edit:** Used Mathew Kirschbaum's suggestions to shorten code size.
> 0 votes

# Answer
# PHP - 91 characters

```
function divides($n) {
    foreach(array_map('intval', str_split($n))as$i)if($i==0||$n%$i!=0)return false;return true;
}

foreach ([128, 12, 120, 122, 13, 32, 22, 42, 212, 213, 162, 204] as $n) {
    echo "\n" . $n . ' -> ' . divides($n);
}

```
> 0 votes

# Answer
# Mathematica, 53 bytes (46 byte body)

```
f[x_]:=AllTrue[IntegerDigits@x,#!=0&&Divisible[x,#]&]

```
> 0 votes

# Answer
# PHP, 59 Characters

Where `$n` is the number you're checking

```
foreach(str_split($n)as$v)if($n%$v!=0){echo 0;exit;}echo 1;

```
> 0 votes

# Answer
# Haskell, 55

```
let f x =(\s->all(>'0')s||all((<1).(x`mod`).read.(:[]))s)$show x

```

Counting characters after the `=` sign as per the rules.
> 0 votes

# Answer
# Python 2, 41 bytes

Size not including `f=lambda j:`.

```
f=lambda j:all(j%int(i)==0if i>"0"else 0for i in`j`)

```

Argument supplied must be an integer.

Basically what this does is iterates through the integer (after converting it to a string) and checks the divisibility.
> 0 votes

# Answer
## Java 104

Uses recursion. This test (i==0) is required to stop divide by zero error.

```
public boolean d(int n,int k)
{
int i=k%10;return (k<10)?(k>0)&&(n%k==0):(i==0)?false:(n%i==0)&d(n,k/10);
}

```
> 0 votes

# Answer
## Batch - 202 Bytes

Takes input from stdin - `C:\div.bat 128`.

```
@echo off&setLocal EnableDelayedExpansion&set s=%1&set c=%1&set l=0
:c
if defined s set/Al+=1&set "s=%s:~1%"&goto c
for /l %%a in (1,1,!l!)do set/aa=%c%%%%%a&if !a!==1 echo false&goto :EOF
echo true

```
> 0 votes

# Answer
# Java - (64)

This is the shortest I can come up with:

```
boolean t(int a) {
    int x=a,t=0;do t+=x%10>0?a%(x%10):0;while((x/=10)>0);return t<1;
}

```

If you don't count the method overhead, just the body, it scores 64.
> 0 votes

# Answer
# Scala, 38 characters

```
def isDivisibleByAllDigits(n: Int) = n.toString.forall(d=>d>48&&n%(d-48)<1)

```
> 0 votes

# Answer
# ES6, not exactly a golf, just screwing around with the Y-combinator

```
let dividesSelf = v =>
  !(l =>
    (f => f(f))
    (f => l(n => f(f)(n))))
  (f => n => n + v % n)
  (v >> 1);

```

A little minified, 52 characters long

```
let dividesSelf = v =>
  !(l=>(f=>f(f))(f=>l(n=>f(f)(n))))(f=>n=>n+v%n)(v>>1)

```

The fact I beat about half of the answers is surprising.
> 0 votes

# Answer
# Go - 47 chars

```
func dividesSelf(i int) bool {
    for n:=i;i%10>0&&n%(i%10)<1;i/=10{};return i==0
}

```

Runnable on Go Playground: http://play.golang.org/p/67DQXWnwOT
> 0 votes

# Answer
## Bash, 49

Exits with 0 if the number is divisible, other exit code (and a warning) if not.

```
f () { [ `<<<$1 sed "s/./+$1%\0/g"|cut -c2-|bc` -eq 0 ]; }

```
> 0 votes

# Answer
# Clojure, 71 bytes

```
(fn[n](every? integer?(map #(if(=\0 %1)1.1(/ n(- 48(int %1))))(str n))))

```
> 0 votes

# Answer
# JAGL Alpha 1.2 - 24 bytes

Obviously this wouldn't count in a real contest, because the language came out after the question, but I'm still gonna answer just for fun. Assumes that the number is the only value on the stack, and sets the top value of the stack to 1 or 0, depending on whether the number is divisible by its digits or not.

```
dg{i}/d0en{{SdcS%n}/A}Sf

```

Explanation:

```
dg                         Duplicate number and convert to string
  {i}/                     Convert that to an array of digits
      0en                  If 0 is in the array, push 0, else push 1
         {                 Block to be run if 0 not in array
          {SdcS            Swap, duplicate, cycle, swap
               %n}         Push 1 if divisible by digit, 0 otherwise
                  /A       Map over list and push 1 if all values are 1, otherwise 0
                    }Sf    Run block if 0 not in array

```
> 0 votes

# Answer
# JavaScript, ~~89~~ ~~81~~ 70 bytes

```
function d(n){a=(n+"").split("");for(i in a)if(n%a[i]||1/0==n/a[i])return!1;return!0}

```
> 0 votes

# Answer
# Javascript, ~~82~~ ~~81~~ 80 bytes

```
a=prompt(q=1);b=a.split('');while(d=b.pop())q=q&!(a%d);alert(a.indexOf(0)+1?0:q)

```
> 0 votes

# Answer
# R, 40 chars

```
f=function(n)all(n%%scan(t=gsub("(.)","\\1 ",n))%in%0)

```

`%%` is vectorized. `scan(t=gsub("(.)","\\1 ",n)` is a trick that I stole from an old answer by flodel, to split a number into its digits. `%in%0` instead of simply negating the results allows for detection of NA (resulting from mod 0; `NA==0` gives `NA`, `!NA` gives `NA` but `NA%in%0` gives `FALSE`).

```
> f(120)
Read 3 items
[1] FALSE
> f(128)
Read 3 items
[1] TRUE
> f(12)
Read 2 items
[1] TRUE
> f(213)
Read 3 items
[1] FALSE
> f(212)
Read 3 items
[1] TRUE
> f(42)
Read 2 items
[1] FALSE

```
> 0 votes

# Answer
# TI-BASIC, 29

Adapted from my answer to Generate Monday Numbers.

```
Input X
int(10fPart(X10^(-randIntNoRep(1,1+int(log(X
not(max(remainder(X,Ans+2Xnot(Ans

```

To disqualify numbers that contain zeroes, I replace all zeroes with `2X`, which will not divide X.

I don't count the `Input X` in the code size, because it is analogous to a method signature.
> 0 votes

# Answer
# Hassium, 130 Bytes

```
func i(n){m=n.toString();if(m.contains("0"))return false;foreach(d in m)if(n%d.toString().toDouble()!=0)return false;return true;}

```

Run and see expanded version here
> 0 votes

# Answer
# K (oK), 13 bytes

**Solution:**

```
f:{~+/(48!$x)!'x}

```

**13** bytes excludes function definition (+4) per specification.

Try it online!

**Examples:**

```
f 1024
0
f 128
1
f 333
1
f 334
0

```

**Explanation:**

Evaluation is performed right-to-left.

Convert (e.g.) `128` =\> `1 2 8`. `128` mod each `1 2 8` =\> `0 0 0`. Sum of this is `0`. Not of this is `1`:

```
f:{~+/(48!$x)!'x} / the solution including function definition
f:{             } / assign lambda function to f
               x  / implicit single parameter
             !'   / mod (!) each-left with each-right
      (     )     / do this together
          $x      / string x, 128 => "128"
       48!        / mod ascii values with 48, "128" => 1 2 8
    +/            / sum over results
   ~              / not, 0 => 1, anything else => 0

```
> 0 votes

# Answer
# PHP, 44 bytes

```
function f($n,$s=str_split){
    foreach($s($n)as$d)$f|=!$d||$n%$d;return!$f;
}

```

Try it online.
> 0 votes

# Answer
# Jelly, 3 bytes

```
ọDẠ

```

Try it online!

This is a link, i.e. a function in Jelly. Since Jelly doesn't have specific boolean values, this returns `1` for `True` and `0` for `False`.
> 0 votes

# Answer
# Python 2: ~~36~~ 38 Bytes

Excluding `f=lambda n:`

```
f=lambda n:all([not n%(int(a)or n-1)for a in`n`])

```

Similar to the other python solution. Works because `x or 0` returns `x` if `x != 0`.

Maybe some edge cases around 0-3 or something.

Edit: Didn't work, fixed it
> 0 votes

# Answer
# J, 18 Bytes (21 with function definition)

```
d=:0:=+/@:(|~"."0@":)

```

Explanation:

```
d=:                     | Define d
                  ":    | Format into string
             "."0       | Turn into array of digits
           |~           | Starting Number mod each element
      +/                | Sum
   0:=                  | Test if it’s equal 0. Returns 1 for true, 0 for false

```

Other characters are for ensuring functions compose properly.
> 0 votes

# Answer
# Python 2, 53 bytes

```
lambda s:all(s%int(i)==0 if i!='0'else 0 for i in`s`)

```

Try it online!
> 0 votes

# Answer
# Mathematica - 93ish characters

Robert G Wilson v gives us the following for Mathematica:

Function definition:

```
fQ[n_] :=
  Block[{id = Union[IntegerDigits[n]]},
   Union[IntegerQ[#] & /@ (n/id)] == {True}];

```

To call:

```
Select[Range[487], fQ[#] &]

```

Output (ignoring divide by zero complaints):

```
{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22, 24, 33, 36, 44, 48, 55,
66, 77, 88, 99, 111, 112, 115, 122, 124, 126, 128, 132, 135, 144,
155, 162, 168, 175, 184, 212, 216, 222, 224, 244, 248, 264, 288, 312,
315, 324, 333, 336, 366, 384, 396, 412, 424, 432, 444, 448}

```
> -1 votes

# Answer
# Scala, 44 bytes

```
def f(n:Int)=n+""forall{k=>k>48&&n%(k-48)<1}

```

Try it online!
> -1 votes

---
Tags: code-golf
---