title: As Easy as One-Two-Three

text:
# Question
Title: As Easy as One-Two-Three
Write a program or function that takes in a positive integer. You can assume the input is valid and may take it as a string. If the number is any of

```
123
234
345
456
567
678
789

```

then output a truthy value. Otherwise, output a falsy value. For example, the inputs

```
1
2
3
12
122
124
132
321
457
777
890
900
1011
1230
1234

```

must all result in falsy output. (The input will not have leading zeroes so you needn't worry about things like `012`.)

**The shortest code in bytes wins.**

# Answer
> 49 votes
## Python, 24 bytes

```
range(123,790,111).count

```

An anonymous function that outputs 0 or 1. It creates the list `[123, 234, 345, 456, 567, 678, 789]` and counts how many times the input appears.

```
f=range(123,790,111).count

f(123)
=> 1
f(258)
=> 0

```

# Answer
> 35 votes
## Python, 24 bytes

```
lambda n:n%111==12<n<900

```

Just a lot of condition chaining.

# Answer
> 25 votes
## Haskell, 22 bytes

```
(`elem`[123,234..789])

```

An anonymous function. Generates the evenly-spaced list `[123, 234, 345, 456, 567, 678, 789]` and checks if the input is an element.

# Answer
> 13 votes
# Brachylog, 9 bytes

```
h:2j:12+?

```

Try it online! or Verify all test-cases.

Credits to Dennis for the algorithm.

In English, "(prove that) the Input's first digit, concatenated to itself twice, add 12, is still the Input."

# Answer
> 13 votes
# Python 2, 25 bytes

```
lambda n:`n-12`==`n`[0]*3

```

Test it on Ideone.

# Answer
> 8 votes
# Brain-Flak 76 + 3 = 79 bytes

This answer is a golf of this answer. I don't actually know quite how my answer works but DJMcMayhem gives a good explanation in his original answer and my answer is a modification of his.

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

```

It is run with the -a ascii flag adding 3 bytes.

## Explanation (of sorts)

Starting with the original working solution:

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

```

I run this through a simple golfing algorithm I wrote and get:

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

```

From here I see the section `<({}[()()()])>{}` this essentially multiplies by one which makes it equal to `{}[()()()]` reduce the whole code to:

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

```

Lastly negatives can be combined:

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

```

# Answer
> 8 votes
# Brainfuck, 32 bytes

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

```

Try it online!

Credits to Lynn for the core of the algorithm.

# Answer
> 8 votes
# 05AB1E, 5 bytes

```
¥XX‚Q

```

**Explanation**

```
¥      # deltas
    Q  # are equal to
 XX‚   # [1,1]

```

Try it online

# Answer
> 7 votes
# Jelly, 6 bytes

```
DI⁼1,1

```

Try it online! or verify all test cases.

### How it works

```
DI⁼1,1  Main link. Argument: n (integer)

D       Decimal; convert n to base 10.
 I      Increments; compute the differences of all pairs of adjacent digits.
   1,1  Yield [1, 1].
  ⁼     Test the results to both sides for equality.

```

# Answer
> 6 votes
# MATL, 8 bytes

```
d1=tn2=*

```

Try it online!

This will print `1 1` for a truthy input, and an array with a `0` in it for a falsy value, since that is falsy in MATL.

Explanation:

```
d           % Calculate the difference between consecutive digits
 1=         % Push an array of which elements equal one
   t        % Duplicate this array
    n       % Push the length of this array
     2=     % Push a one if the length is 2, and a zero otherwise
            % Now, if we have a truthy input, the stack looks like:
            %   [1 1]
            %   1
            % And if we have a falsy input, the stack looks something like this:
            %   [1 0]
            %   1
            % Or this:
            %   [1 1]
            %   0
       *    % Multiply the top two elements

```

# Answer
> 6 votes
## Java 7, 46 bytes

```
boolean f(int a){return a>12&a<790&a%111==12;}

```

After trying several things with Leaky Nun in chat, this seems to be the shortest. Sometimes you just have to do things the straightforward way :/

Explanation:

```
boolean f(int a){
    return a>12         Is it more than 12? (stupid edge case)
           &
           a<790        Is it in range the other way?
           &
           a%111==12;   Is it 12 more than a multiple of 111?
}

```

# Answer
> 6 votes
# Perl 6,  ~~35 29 24 21~~  19 bytes

```
~~{.chars==3&&'0123456789'.index: $_}
{$_ (elem) (123,*+111...789)}
{$_∈(123,*+111...789)}
*∈(123,*+111...789)~~
*∈(123,234...789)
```

## Explanation:

```
# Whatever lambda ( the parameter is ｢*｣ )
*

∈ # is it an element of:

# this sequence
(
  123,
  234,

  # deduce rest of sequence
  ...

  # stop when you generate this value
  789
)

```

## Usage:

```
my &code = *∈(123,234...789);

say code 123; # True
say code 472; # False

say (  *∈(123,234...789)  )( 789 ); # True

```

# Answer
> 6 votes
# Retina, 26

```
.
$*:
^(:+ ):\1::\1$

```

Outputs 1 for truthy and 0 for falsey.

Try it online (First line added to allow multiple testcases to be run).

# Answer
> 5 votes
# Brain-Flak, 99 bytes

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

```

Try it online!

This is 98 bytes of code `+1` for the `-a` flag.

This prints `1` for truthy, and either `0` or nothing (which is equivalent to 0) for falsy

# Answer
> 5 votes
# Ruby `-nl`, ~~32~~ ~~30~~ 25 bytes

```
p"123456789"[$_]&.size==3

```

Attempt This Online!

# Answer
> 4 votes
# R, ~~30~~ 22 bytes

```
scan()%in%(12+1:7*111)

```

Not particularly exciting; check if input is in the sequence given by 12 + 111k, where k is each of 1 to 7. Note that `:` precedes `*` so the multiplication happens after the sequence is generated.

# Answer
> 4 votes
# Brain-Flak, 114 bytes

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

```

Try it online!

Correct version (in the spirit of the question): takes the integer as input, output 0 for falsey and 1 for truthy.

This is **not** stack clean.

### Algorithm

Let the input be `n`.

The output is truthy iff `(n-123)(n-234)(n-345)(n-456)(n-567)(n-678)(n-789)=0`.

I computed those seven numbers by first subtracting 12 and then subtract 111 7 times, and then computed the logical double-NOT of those seven numbers and added them up.

For truthy results, the sum is 6; for falsey results, the sum is 7.

Then, I subtract the sum from 7 and output the answer.

# Answer
> 4 votes
# C# (Visual C# Interactive Compiler), ~~41 30~~ 23 bytes

First code-golf submission, be gentle :)

```
~~a=>{return a>12&&a<790?a%111==12:false;};~~
~~a=>a>12&&a<790?a%111==12:false~~
a=>a>12&a<790&a%111==12

```

Try it online!

* -11 bytes thanks to Kirill L.
* Another -7 bytes thanks to ASCII-only.

# Answer
> 3 votes
# CJam, ~~13~~ 9 bytes

```
A,s3ewqe=

```

Try it online!

**Explanation**

```
A,s        e# Push "0123456789".
   3ew     e# Split it into contiguous length-3 chunks: ["012" "123" "234" ... "789"].
      q    e# Push the input.
       e=  e# Count the number of times the input appears in the array.

```

# Answer
> 3 votes
# Brainfuck, 43 bytes

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

```

Bah, I'm no good at this. Outputs `\x01` if the output is one of the strings `123`, `234`, …, `789`; outputs `\x00` otherwise.

(I beat Java 7, though…)

Try it online!

# Answer
> 3 votes
# Excel - 62 57 35 31 bytes

Based on Anastasiya-Romanova's answer, but returning Excel's `TRUE/FALSE` values.

```
=AND(LEN(N)=3,MID(N,2,1)-MID(N,1,1)=1,MID(N,3,1)-MID(N,2,1)=1)

```

Further, we can get to

```
=AND(LEN(N)=3,MID(N,2,1)-LEFT(N)=1,RIGHT(N)-MID(N,2,1)=1)

```

since both `RIGHT` and `LEFT` return a single character by default.

And, inspired by some of the Python solutions:

```
=AND(LEN(N)=3,MOD(N,111)=12,N<>900)

```

Thanks to Neil for 4 more bytes...

```
=AND(N>99,MOD(N,111)=12,N<900)

```

# Answer
> 3 votes
# JavaScript ES6, 26 bytes

`n=>1>(n-12)%111&n>99&n<790`

This takes advantage of the fact that I'm using bit-wise logic operators on what are essentially booleans (which are bit-based!)

Thanks to Titus for saving 2.

# Answer
> 3 votes
# Brachylog (2), 7 bytes

```
ẹ~⟦₂-_2

```

Try it online!

## Explanation

```
ẹ~⟦₂-_2
ẹ        Split into digits
 ~⟦₂     Assert that this is an increasing range; take its endpoints
    -_2  Assert that the starting minus ending endpoint is -2

```

As a full program, we get a truthy return if all assertions hold, a falsey return if any fail.

# Answer
> 3 votes
# Regex (ECMAScript), 20 bytes

The input *n* is in unary, as the length of a string of `x`s.

```
^x{12}(x{111}){1,7}$

```

Try it online!

This works by asserting that \\$n-12\\$ is of the form \\$111k\\$ where \\$1\le k\le 7\\$.

# Answer
> 3 votes
# Vyxal, 4 bytes

```
¯k₁⁼

```

Try it Online!

### Explained

```
¯k₁⁼
¯    # Deltas
 k₁  # [1,1]
   ⁼ # compare lists

```

# Answer
> 3 votes
# K (ngn/k), 15 bytes

```
{($x-12)=3#*$x}

```

Try it online!

Port of Dennis' algorithm.

Explanation:

```
{($x-12)=3#*$x}  Main function. Takes x as input
            $x   Convert x to string
           *     Then get the first character
         3#      And duplicate it thrice
        =        Is it equal to
 ( x-12)         x - 12
  $              Converted to string?

```

# Answer
> 2 votes
# Excel - 104 bytes

```
=IF(LEN(N)<3,"Falsy",IF(AND(LEN(N)=3,MID(N,2,1)-MID(N,1,1)=1,MID(N,3,1)-MID(N,2,1)=1),"Truthy","Falsy"))

```

**Explanation:**

The syntax for the IF formula in Excel is:

```
IF( condition, [value_if_true], [value_if_false] )

```

If the length of input `N`, where it's a name of the reference cell, is less than 3, then it will return **Falsy**. Else, if the length of input `N` is 3 and both of the difference of second digit and first digit and the difference of third digit and second digit are equal to 1, then it will return **Truthy**.

# Answer
> 2 votes
# Pyth, 8 Bytes

```
qi>3SeQT

```

Try online!

Explanation:

```
q       Q  Is the input equal to:
  <3S       The last three digits of the range from 1 to
     eQ      The last digit of the input
 i     T      Concatenated together into an integer

```

# Answer
> 2 votes
# Dyalog APL, 10 bytes

Takes string argument.

```
1 1≡¯2-/⍎¨

```

`1 1≡` Is {1, 1} identical to

`¯2-/` the reversed pair-wise difference of

`⍎¨` each character taken as a number?

TryAPL online! ( has been emulated with `e` for security reasons.)

# Answer
> 2 votes
# Perl, 18 bytes

Includes +1 for `-p`

Run with the input on STDIN

```
123.pl <<< 123

```

`123.pl`:

```
#!/usr/bin/perl -p
$_=$_=/./.2==$_-$&x3

```

# Answer
> 2 votes
# PHP, 31 bytes

```
<?=($n=$_GET[n])-12==$n[0]*111;

```

Check if first digit of (number minus 12) is multiple of 111

# Answer
> 2 votes
## PowerShell v3+, 24 bytes

```
($args[0]-12)/111-in1..7

```

Uses the same *"multiple of 111 plus 12"* trick as some other answers, but goes the other direction. Takes input `$args[0]`, subtracts `12`, divides by `111`, and checks whether that's `-in` the range `1..7`. Outputs a Boolean true/false value. Requires v3+ for the `-in` operator.

### Test Cases

```
PS C:\Tools\Scripts\golfing> 123,234,345,456,567,678,789|%{.\easy-as-one-two-three.ps1 $_}
True
True
True
True
True
True
True

PS C:\Tools\Scripts\golfing> 1,2,3,12,122,124,132,321,457,777,890,900,1011,1230,1234|%{.\easy-as-one-two-three.ps1 $_}
False
False
False
False
False
False
False
False
False
False
False
False
False
False
False

```

# Answer
> 2 votes
# ARM Machine Code, 18 bytes

Hex dump (little endian):

```
3803 d105 6808 ebc0 2010 b280 f2a0 1001 4770

```

This is a function that takes in a length, pointer pair for the string. The output is bash-style, it outputs 0 for true and a non-zero value for false. In C the function would be declared int oneTwoThree(size\_t length, char\* string). The instruction encoding is thumb-2, which has 2 and 4 byte instructions. Tested on a Raspberry Pi 3.

Ungolfed assembly:

```
.syntax unified
.text
.global oneTwoThree
.thumb_func
oneTwoThree:
    @Input: r0 - the number of characters in the string
    @r1 - A pointer to the (not necessarily NUL-terminated)
    @string representation of the number (char*)
    @Output: r1 - 0 if the number is in 123,234,...,789, else non-zero (bash-style)
    subs r0,r0,#3
    bne end @Return non-zero if r0!=3
    ldr r0,[r1] @Remember that this is little endian
    @So the first digit is the most siginificant byte
    @I.e. if the input was 123 then r0 contains 0xXY010203 where XY is garbage

    rsb r0,r0,r0,lsr #8 @r0=(r0>>8)-r0 (rsb is reverse subtract)
    uxth r0,r0 @r0&=((1<<16)-1) (mask off top half)
    @Now r0 is 0x0101 iff we have a matching number
    sub r0,r0,#0x101
    @Now r0 is 0 iff the string fit the specification

    end:
    bx lr @return

```

Testing script (also assembly):

```
.syntax unified
.text
.global main
.thumb_func
main:
    push {r4,lr}
    ldr r4,[r1,#4] @r0=argv[1]
    mov r0,r4
    bl strlen
    @Now r0 is the length of the string argv[1]
    mov r1,r4
    bl oneTwoThree @oneTwoThree(strlen(argv[1]),argv[1])
    cmp r0,#0
    it ne
    movne r0,#1 @Output through return code, 1 if false
    pop {r4,pc}

```

# Answer
> 2 votes
# JavaScript (ES6), 34 bytes

And one more option in JS. Takes input as a string and outputs `0` for `false` and `1` for `true`.

```
n=>++n[0]==n[1]&++n[1]==n[2]&!n[3]

```

See my other solutions here and here

---

## Try it

```
f=
n=>++n[0]==n[1]&++n[1]==n[2]&!n[3]
i.addEventListener("input",_=>o.innerText=f(i.value))
```

```
<input id=i type=number><pre id=o>
```

# Answer
> 2 votes
# Jelly, 5 bytes

```
9ṡ3Vċ

```

Try it online!

# Answer
> 2 votes
# Brachylog (v2), 4 bytes

```
~s₃Ị

```

Try it online!

Certainly not as creative as user62131's answer, but quite a bit shorter. Takes input as a string through the input variable and assumes the string has no leading zeroes (i.e. `"012"` is a false positive), outputting through success or failure, where success of a predicate run as a program prints `true.` and failure prints `false.`

```
        The input is a
~s₃     length-3 substring of
   Ị    "0123456789".

```

If input is allowed to be a bit less orthodox...

# Brachylog, 3 bytes

```
Ịs₃

```

Try it online!

Outputs the same way and takes input in the same format, but takes it through the output variable. To run this as a program, the input is given as the first command-line argument on TIO, rather than through the Input box (which actually has to either be empty or contain `"0123456789"`).

# Answer
> 2 votes
# BRASCA, 15 bytes

```
Ci,:::SSL{+,SS=

```

Try it online!

## Explanation

```
Ci                - Set implicit output to output numbers, and turn "0-9" into 0-9
  ,               - Reverse stack
   :::SSL{+       - First digit of input, concatenated to itself twice, + 12
           ,SS=   - Concatenate the digits of the original, then check if both numbers are equal
<implicit output> - Output 1 if truthy, 0 if falsy

```

# Answer
> 2 votes
# Factor, 26 bytes

```
[ "123456789"3 clump in? ]

```

Try it online!

* `"123456789" 3 clump` -\> `{ "123" "234" "345" "456" "567" "678" "789" }`
* `in?` Is the input in this?

# Answer
> 1 votes
# Brain-Flak, 118 + 3 = 121 bytes

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

```

Try it online!

ASCII version: take code-points as input, output \x00 for falsey or \x01 for truthy.

# Answer
> 1 votes
## Pyke, 9 bytes

```
~ut{3Qlq&

```

Try it here!

```
~ut{      -  input in "123456789"
        & - ^ and V
    3Qlq  -  len(input) == 3

```

Or 5 bytes if allowed sequence input

```
$1D]q

```

Try it here!

```
$     - delta(input)
 1D]q - ^ == [1,1]

```

# Answer
> 1 votes
# Fish (\>\<\>), 14 bytes

With input from the command line/initial stack.

```
l3=?!;$:@---0=l1==n;

```

Explanation:

```
$:@              Swaps top two values on stack then duplicates topmost one, then swaps top three values
   ---             Each '-' subtracts the second most value on the stack from the topmost and pushes their result
      0=l1=          Checks if topmost value is 0, pushes 1 if true and 0 if false, then checks if length of stack is 1 (pushes 1 is true, 0 if false)
         =n;           Does the logical && of the top two truthy/falsy values pushed in previous step and outputs the result.

```

Try it here

# Answer
> 1 votes
# PHP, ~~32~~ 34 bytes

```
<?=(800>$x=$argv[1]-12?:1)>$x%111;

```

Run like this:

```
echo '<?=(800>$x=$argv[1]-12?:1)>$x%111;' | php -- 124

```

Updates:

* I made a little mistake where 12 was considered valid.

# Answer
> 1 votes
## Batch, 49 bytes

```
@for /l %%a in (123,111,789)do @if %%a==%1 echo 1

```

# Answer
> 1 votes
# 3d, 61 bytes

```
>:&&#a&×∕$#a∕#a%.--v
  v--.%a#$∕a#&%×&a#—'F!,;
v —'F!;
>'T!;

```

Will output:

```
T

```

if input is a three consecutive increasing digits,

```
F

```

if not.

Explanation:

```
:&&  push imput and duplicate twice
#a&× push 0xa (10), duplicate it, multiply top two of the stack: get 100
∕    floor divide top two elements of the stack (we get the first digit)
$    invert top two elements
#a∕  floor divide by 10 (get rid of last digit)
#a%  modulo 10 (get middle digit)
.-   push 1 and difference
-    difference (hence we get 0 if two initial digits have a difference of 1)
—    is top of stack null?
if not:
'F!  print 'F'
,;   pops the stack and exits
if yes:
#a&× get 100
%    modulo (get rid of first digit)
&    duplicate
#a∕  floor divide by 10 (get middle digit)
$    invert
#a%  modulo 10 (get last digit)
.- push 1 and difference
-  difference
— is top of stack null?
yes:
'T!; print 'T' and exit
not:
'F!; print F and exit

```

Phew, this really ain't golfy.

# Answer
> 1 votes
## Java 8, 23 bytes

```
n->n<900&(n-122)%111==1

```

Ungolfed:

```
interface N { boolean f(int n); }

public static void main(String[] args) {
  N f = n ->
    n < 900 // 900 is not good
    &
    (n - 122) % 111 == 1 // force 12 to go negative and fail the comparison (can't use 123 because -111 % 111 == 0, while -110 % 111 == -1).
}

```

Test class:

```
public class Main {
  private interface N {

    boolean f(int n);
  }

  static void test(N f, int n, boolean expected) {
    boolean result = f.f(n);
    System.out.printf("%s -> %b (%b) -> %s%n", n, result, expected, result == expected ? "OK" : "NOK");
  }

  public static void main(String[] args) {
    N f = n->n<900&(n-122)%111==1;

    test(f,  123, true);
    test(f,  234, true);
    test(f,  345, true);
    test(f,  456, true);
    test(f,  678, true);
    test(f,  789, true);

    test(f,    1, false);
    test(f,    2, false);
    test(f,    3, false);
    test(f,   12, false);
    test(f,  122, false);
    test(f,  124, false);
    test(f,  132, false);
    test(f,  321, false);
    test(f,  457, false);
    test(f,  777, false);
    test(f,  890, false);
    test(f,  900, false);
    test(f, 1011, false);
    test(f, 1230, false);
    test(f, 1234, false);

  }
}

```

# Answer
> 1 votes
# Javascript (ES5), 47 39 bytes

```
function(n){return(n-12)%111==0&&i<1e3}

```

Old solution with 47 did not work correctly.

# Answer
> 1 votes
# JavaScript (ES6), ~~41~~ ~~39~~ ~~38~~ 37 bytes

Just another JS option. Takes input as a string and outputs `0` for `false` and `1` for `true`.

```
n=>+n[2]&!n[3]&~"123456789".search(n)

```

See my other solutions here and here

---

## Try it

```
f=
n=>+n[2]&!n[3]&~"123456789".search(n)
i.addEventListener("input",_=>o.innerText=f(i.value))
```

```
<input id=i type=number><pre id=o>
```

# Answer
> 1 votes
# Japt, ~~6~~ 5 bytes

```
%#o¥C

```

Try it online!

# Answer
> 1 votes
# 8086 Machine Code, 14 bytes

```
3C 03   CMP  AL, 3      ; check if input length is 3 chars exactly
75 0A   JNZ  FALSY      ; if not, falsy
AD      LODSW           ; load first char into AL, second into AH, advance SI
40      INC  AX         ; increment first char
3A E0   CMP  AH, AL     ; are chars now equal?
75 04   JNZ  FALSY      ; if not, falsy
AC      LODSB           ; load third char into AL
48      DEC  AX         ; decrement third char
3A E0   CMP  AH, AL     ; are chars now equal?
FALSY:

```

Input string is `SI`, length in `AL`. Return is Zero Flag where (`ZF=1`) if Truthy, (`ZF=0`) if Falsy.

# Answer
> 1 votes
# Stax, 5 bytes

```
╡e╦ù┌

```

Run and debug it

# Answer
> 1 votes
# Java 8, 23 bytes (thanks ASCII-only!)

```
n->n>12&n<790&n%111==12

```

Old version, 40 bytes

```
n->n>99&n<999&"123456789".contains(n+"")

```

-1 bytes thanks to gwaugh
Try it online!

# Answer
> 1 votes
# Julia 1.0, 18 bytes

```
n->n∈123:111:789

```

Try it online!

# Answer
> 1 votes
# MathGolf, ~~6~~ 4 bytes

```
│ª▒=

```

Try it online!

## Explanation

```
│       get differences of digits in integer
 ª      push [1]
  ▒     duplicate items in list
   =    pop(a, b), push(a==b)

```

# Answer
> 1 votes
# Befunge-98 (PyFunge), 36 bytes

```
0c75*2+3*&# :b9*8*`#0_# \%# -#0_1.@.

```

Try it online!

Alternate version that uses the 2-D aspect of Befunge:

```
c75*2+3*&:98*b*`#v_\%-#v_1.@
                 >     >0. ^

```

I actually prefer the second, however the first is shorter. Also, the first version leaves some stack pollution, whereas the second leaves a clean stack. Either could easily be made for Befunge-93 with a small 4-byte addition. I did not include it because there is already a 93 answer.

# Answer
> 1 votes
# Pyt, 11 bytes

```
ą₋Đ₋¬⇹Ʃ2=∧Π

```

Try it online!

```
ą              implicit input; convert to ąrray of characters
 ₋             reduce by subtraction
  Đ            Đuplicate
   ₋           reduce by subtaction
    ¬          logical NOT (coerce integer to boolean, then negate)
     ⇹         swap top two items on stack
      Ʃ        Ʃum
       2=      ... equals 2?
         ∧     logical AND
          Π    product; implicit print

```

# Answer
> 1 votes
# Thunno 2, 4 bytes

```
Ṣk&⁼

```

Attempt This Online!

#### Explanation

```
Ṣk&⁼  # Implicit input
Ṣ     # deltas
   ⁼  #        ==
 k&   #           [1, 1]
      # Implicit output

```

# Answer
> 0 votes
# PHP, 35 bytes

```
<?=($n=$argv[1]-99)<790&$n%111==24;

```

exploiting that the modulo of a negative number is never positive in PHP

# Answer
> 0 votes
**C 61 Bytes**

```
f(char*v){puts(v[3]==0&v[0]+1==v[1]&v[1]+1==v[2]?"T":"F");}
g(v){puts(v<790&v%111==12?"T":"F");}
main(c, v)char**v;{
    f(v[1]);
    g(atoi(v[1]));
}

```

61 Bytes only includes the function. f(...) 36 Bytes using the trick from Geobits in g(...)

# Answer
> 0 votes
# GNU Octave : 74 bytes

golfed:

```
function r=g(a)t=conv(a-'0',[1,-1],'valid')==1;r=(sum(t)==2).*prod(t);end;

```

ungolfed:

```
function r=golf_123(a)
  t=conv(a-'0',[1,-1],'valid')==1;
  r=(sum(t)==2).*prod(t);
endfunction

```

**Explanation**: Treat the string as an integer vector, any two consecutive digits will then have derivative given the finite difference filter \[1,-1\] equal to 1 at each valid convolution output. The prod command calculates product, so it will short circuit to 0 if at least one entry is 0. The sum(t)==2 disqualifies any run of increasing digits longer or shorter than 3.

# Answer
> 0 votes
## JAVA 7, 57 bytes

```
boolean f(int x){return (int)Math.log(x)-1==3&x%111==12;}

```

# Answer
> 0 votes
# AWK, ~~33~~ ~~28~~ 27 Bytes

```
{$0=($1-12)/111~/^[1-7]$/}1

```

Prints `1` for corresponds to one of the desired values, `0` otherwise.

Updated answer is based on TimmyD's powershell answer.

Example usage:

```
awk '{$0=($1-12)/111~/^[1-7]$/}1' <<< 789

```

Prints `1`

```
awk '{$0=($1-12)/111~/^[1-7]$/}1' <<< 12

```

Prints `0`

Since this is using division rather than modulus, the result will be an integer for the desired values, but that integer needs to be between 1 and 7.

Try it online!

# Answer
> 0 votes
# SpecBAS - 35 bytes

```
1 INPUT n: ?(n-12)/111 in [1 TO 7]

```

Uses the same formula as the Powershell answer, returns 0 for False and 1 for True.

My original version was 59 bytes (and seems more "honest" for being my own work). Input as number and converted to string to avoid "012" showing as True.

```
1 INPUT n: n$=STR$ n: ?LEN n$=3 AND POS(n$,"0123456789")>0

```

# Answer
> 0 votes
## C# 6 (36 bytes)

```
bool f(int x)=>x<790&0==(x+321)%111;

```

# Answer
> 0 votes
# C, 71 bytes

Taking the input as `int`:

```
f,d,c;F(n){for(f=c=0;n;)d=n%10,c++,f|=d-(n/=10)%10-1&&n;return!f&c==3;}

```

Test main:

```
int main() {
  printf("%d\n", F(123));
  printf("%d\n", F(234));
  printf("%d\n", F(345));
  printf("%d\n", F(456));
  printf("%d\n", F(567));
  printf("%d\n", F(678));
  printf("%d\n", F(789));
  printf("%d\n", F(1));
  printf("%d\n", F(2));
  printf("%d\n", F(3));
  printf("%d\n", F(12));
  printf("%d\n", F(122));
  printf("%d\n", F(124));
  printf("%d\n", F(321));
  printf("%d\n", F(457));
  printf("%d\n", F(777));
  printf("%d\n", F(890));
  printf("%d\n", F(900));
  printf("%d\n", F(1011));
  printf("%d\n", F(1230));
  printf("%d\n", F(1234));
}

```

# Answer
> 0 votes
# Ruby, 114 bytes

```
i = gets.chomp.to_i
l = [123, 234, 345, 456, 567, 678, 789]
y=false
l.each {|x| if i==x then y=true end;}
puts y

```

I don't know how many bytes this answer is, but I'm guessing it's not that small.

# Answer
> 0 votes
# Clojure, 48 bytes

```
(defn f [n] (= n ((set (range 123 900 111)) n)))

```

Test:

```
user=> (map (fn [n] [n (f n)]) [123 234 345 456 567 678 789])
([123 true]
 [234 true]
 [345 true]
 [456 true]
 [567 true]
 [678 true]
 [789 true])

user=> (map (fn [n] [n (f n)]) [1 2 3 12 122 124 132 321 457 777 890 900 1011 1230 1234])
([1 false]
 [2 false]
 [3 false]
 [12 false]
 [122 false]
 [124 false]
 [132 false]
 [321 false]
 [457 false]
 [777 false]
 [890 false]
 [900 false]
 [1011 false]
 [1230 false]
 [1234 false])

```

# Answer
> 0 votes
# PHP 5.6, 48 bytes

```
<?=($a=$argv[1])==join("",range($a[0],$a[0]+2));

```

Wanted to try something a little different from the other PHP answers (and a different approach to most of the posted answers). Take the first number of the input string, add two to it and create a `range` array, then join those together to create a new string and then return if they're equal or not.

Run with:

```
echo '<?=($a=$argv[1])==join("",range($a[0],$a[0]+2));' | php -- 123

```

# Answer
> 0 votes
# \>\<\> (Fish), 28 Bytes

```
l3-0=?v0n;>
?+1-@:<;n1^?+2-!

```

Input is via an execution argument to add each digit to stack, left to right.

Checks if the length of the stack (number) is three, then that there's a difference of one between the third and second digits, then that there's a difference of two between the first and third digits.

Try it online!

# Answer
> 0 votes
## Jelly, 8 bytes

Not as short as Dennis's answer (duh), but I'm quite proud of myself for getting the results I wanted out of Jelly.

```
9Rṡ3
De¢

```

Try it online!

Explanation:

```
9R    Push 1-9 to the stack
ṡ3    Slice up the stack in parts of 3, overlapping
      This gives us [1,2,3], [2,3,4], ..., [7,8,9]
D     Convert input to list ( '123' -> [1, 2, 3])
e¢    This checks to see if the decimal list is in the list of our previous link.

```

# Answer
> 0 votes
# Clojure, 25 bytes

```
(set (range 123 790 111))

```

Basically the Haskell answer. Creates a range which includes all the truthy answers, then converts it into a set. Sets are functions in Clojure (they implement the function interface and can be called).

Returns the number as the truthy return (every number is truthy in Clojure), and `nil` for the falsey value.

Use:

```
(let [s (set (range 123 790 111))]

    (s 123)
    123

    (s 234)
    234

    (s 993)
    nil

```

# Answer
> 0 votes
# SmileBASIC, 27 bytes

```
INPUT N?N-12==N DIV&H64*111

```

Using Dennis's algorithm.

If forcing the user to add `&H` to their input is OK, this works for 24 bytes:

```
INPUT N?N-18==(N>>8)*273

```

# Answer
> 0 votes
## QBIC, 21 bytes

```
;[7|~!12+111*a$=A|_Xq

```

This prints `1` if a match is found, nothing otherwise.

Explanation

```
;              Get A$ from the command line
[7|            FOR a=1; a <=7 ; a++ (for each of the 7 sequences)
  12+111*a     Generate the number 123, 234, 345 by mult. 111 x index, plus 12
 !        $    Cast that to string B$
~          =A  And IF that matches A$
|_Xq           THEN quit, printing 1
               IF and FOR loop implicitly closed

```

# Answer
> 0 votes
# Befunge-93, ~~57~~ 53 bytes

```
#@ #.0 &# ::57*2+3*%34*-#<_# 34*`!#<_# 98*34**`#<_1.@

```

Try it online!

Explanation

```
#@ #.0        skip the terminator and output command. Adds a meaningless zero to
                the stack.
&# ::         take in an input and add two more copies to the stack
57*2+3*%      adds input mod 111 ((5*7+2)*3) to the stack
34*-#<_#      compares 12 to the result, if they are the same, continue to move
                right, else move left
34*`!#<_#     checks to see that the input is greater (`) than 12. If it is,
                continue to move right, else move left
98*34**`#<_   check that 864 (9*8*3*4) is greater than the input. (the reason for
                this is that 864 was an easy number to create that was greater than
                the last possible number (789) and was less than the next number
                divisible by 111 (900)
1.@           if you pass all the checks, output 1, otherwise...
@.0># &#      you will move back through the code heading left. (you will do
                the operations, but that will not matter.) Skip the input
                command. Output zero and end the code.

```

# Answer
> 0 votes
# Thue, 84 bytes

```
123z::=~1
234z::=~1
345z::=~1
456z::=~1
567z::=~1
678z::=~1
789z::=~1
a::=:::
::=
az

```

Outputs `1` when given one of the target values, and no output when given something else. The `z` at the end is needed to prevent false positives with numbers like `1230`

# Answer
> 0 votes
# Unexpanded Sinclair ZX-81 and Timex TS1000/1500 ~99 97 tokenised BASIC bytes

```
 1 LET A$="123456789"
 2 INPUT B$
 3 LET P=NOT PI
 4 FOR F=VAL "1" TO VAL "7"
 5 LET P=P+(A$(F TO F+VAL "2")=B$)
 6 NEXT F
 7 PRINT P

```

This is using a sub-string method to scan the string literal `A$` for the match as per the test cases; if a match is found then the variable `1` is added to the `P`, otherwise zero is added to `P`.

# Answer
> 0 votes
# APL(NARS), 40 chars, 80 bytes

```
{(∼⍵⊆⎕D)∨3≠≢⍵:0⋄(⊂⍎¨⍕⍵)∊{⍵+0..2}¨⍳7:1⋄0}

```

This is a little long, but would return the 0 if type is not string, or if string is different "123","234",..,"789"; test:

```
  f←{(∼⍵⊆⎕D)∨3≠≢⍵:0⋄(⊂⍎¨⍕⍵)∊{⍵+0..2}¨⍳7:1⋄0}
  f 'aaa'
0
  f ''
0
  f¨('12')(,'3')('3')('122')('124')('132')('123456789')
0 0 0 0 0 0 0
  f¨('123')('456')('789')
1 1 1

```

# Answer
> 0 votes
# Arturo, 27 bytes

```
$[n][∧12=n%111n<=>13 789]

```

Try it

```
$[n][                      ; a function taking an argument n
              n<=>13 789   ; is n between 13 and 789?
     ∧                     ; and
      12=n%111             ; is n mod 111 equal to 12?
                         ] ; end function

```

# Answer
> 0 votes
# Thunno, \\$ 8 \log\_{256}(96)\approx \\$ 6.58 bytes

```
dz[11dA=

```

Attempt This Online!

Port of Emigna's 05AB1E answer.

---
Tags: code-golf, number, decision-problem, integer
---


title: Remove character at specified index

text:
# Question
Title: Remove character at specified index
(heavily inspired by Element of string at specified index)

Given a string `s` and an integer `n` representing an index in `s`, output `s` with the character at the `n`-th position removed.

0-indexing and 1-indexing are allowed.

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

`s` will consist of printable ASCII characters only (`\x20-\x7E`, or  through `~`).

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

Testcases (0-indexed):

```
n s        output
0 "abcde"  "bcde"
1 "abcde"  "acde"
2 "a != b" "a = b"
3 "+-*/"   "+-*"
4 "1234.5" "12345"
3 "314151" "31451"

```

Testcases (1-indexed):

```
n s        output
1 "abcde"  "bcde"
2 "abcde"  "acde"
3 "a != b" "a = b"
4 "+-*/"   "+-*"
5 "1234.5" "12345"
4 "314151" "31451"

```

This is , so shortest answer in bytes wins.

# Answer
# C#, ~~20~~ 19 bytes

```
s=>n=>s.Remove(n,1)

```
> 22 votes

# Answer
## Alice, ~~13~~ 12 bytes

*Thanks to Leo for saving 1 byte.*

```
/oI\!e]&
@ q

```

Try it online!

First line of the input is the string, second line is the 0-based index.

### Explanation

```
/    Reflect to SE. Switch to Ordinal. While in Ordinal mode, the IP bounces
     diagonally up and down through the code.
I    Read the first line of input (the string).
!    Store the string on the tape, which writes the characters' code points to
     consecutive cells (the tape is initialised to all -1s).
]    Move the tape head right. This moves it by an entire string, i.e. to the
     cell after the -1 that terminates the current string.
     The IP bounces off the bottom right corner and turns around.
]    Move the tape head right by another cell.
!    Store an implicit empty string on the tape, does nothing. It's actually
     important that we moved the tape head before this, because otherwise it
     would override the first input code point with a -1.
I    Read the second line of input (the index) as a string.
/    Reflect to W. Switch to Cardinal.
     The IP wraps around to the last column.
&]   Implicitly convert the first input to the integer value it contains
     (the index) and move the tape head that many cells to the right, i.e.
     onto the character we want to delete. Note that Ordinal and Cardinal mode
     have two independent tape heads on the same tape, so the Cardinal tape
     head is still on the first cell of the string input before we do this.
e!   Store a -1 in the cell we want to delete.
\    Reflect to SW. Switch to Ordinal.
q    Push the entire tape contents as a single string. This basically takes
     all cells which hold valid code points from left to right on the tape
     and concatenates the corresponding characters into a single string. Since
     we wrote a -1 (which is not a valid code point) over the target character,
     this will simply push the entire input string without that character.
o    Output the result.
@    Terminate the program.

```
> 14 votes

# Answer
# Japt, 2 bytes

```
jV

```

Try it online!
> 10 votes

# Answer
## K (Kona), 1 byte

```
_

```

Gotta love builtins. 0-based indexing. Usage:

```
k)"abcdef" _ 3
"abcef"

```
> 10 votes

# Answer
# Haskell, ~~28~~ 24 Bytes

-4 byte thanks to Laikoni, this version is 1-indexed.

```
s#n=take(n-1)s++drop n s

```

Old answer:

```
f(s:t)0=t;f(s:t)n=s:f t(n-1)

```

A simple recursive function that takes the value, it's 0-indexed.

My first time code-golfing so maybe it's not the optimal solution. Oh well.
> 8 votes

# Answer
# CJam, 4 bytes

```
q~Lt

```

Try it online!

### Explanation

```
q~    e# Read and eval input (push the string and number to the stack).
  Lt  e# Set the nth element of the string to the empty string.

```
> 6 votes

# Answer
## Mathematica, 18 bytes

1-indexed

```
#2~StringDrop~{#}&

```

input

> \[1, "abcde"\]

thanks Martin Ender
> 6 votes

# Answer
# , 3 bytes

```
À|x

```

Try it online!

This uses 1-indexing.
> 6 votes

# Answer
# MATL, 3 bytes

```
&)&

```

Uses 1-based indexing.

Try it online! Or verify all test cases.

### Explanation

```
&    % Specify secondary default number of inputs/outputs for next function
)    % Implicitly input string and number. Index: with & it pushes the char
     % defined by the index and the rest of the string
&    % Specify secondary default number of inputs/outputs for next function
     % Implicitly display (XD): with & it only displays the top of the stack

```

In the modified version with all the test cases, the code is within an infinite loop ``...T` until no input is found. At the end of each iteration the display function (`XD`) is explicitly called, and the stack is cleared (`x`) to ready it for the next iteration.
> 5 votes

# Answer
# Vim, 7 bytes

```
jDk@"|x

```

**How it works:**

It expects two lines; one with the string and one with the number.

1. Go to line two, copy the number into register
2. Go to first line and then go to column in the register with @"|
3. Delete the character under the cursor
> 4 votes

# Answer
# Java 8, 39 bytes

```
s->n->s.substring(0,n)+s.substring(n+1)

```

Try it here.

# Java 7, 67 bytes

```
String c(int n,String s){return s.substring(0,n)+s.substring(n+1);}

```

Try it here.
> 4 votes

# Answer
# Ruby, 16 bytes

```
->n,s{s[n]='';s}

```

Try it online!
> 4 votes

# Answer
# GCC c function, 25

1-based indexing.

```
f(n,s){strcpy(s-1,s+=n);}

```

Plenty of undefined behavior here so watch out for stray velociraptors:

* The `strcpy()` man page says *If copying takes place between objects that overlap, the behavior is undefined*. Here there clearly is overlap of the *src* and *dest* strings, but it seems to work, so either glibc is more careful or I got lucky.
* The answer is reliant on the fact that the `s+=n` happens before the `s-1`. The standard gives no such guarantees, and in fact calls this out as undefined behaviour. Again, it seems to work as required with the gcc compiler on x86\_64 Linux.

Try it online.
> 4 votes

# Answer
# Jelly, 3 bytes

```
Ṭœp

```

A full program taking the (1-based) index and the string (in that order) and printing the result.

As a dyadic function it returns a list of the two parts.

In fact the index may be a list of **n** indices, in which case it returns a list of the **n-1** parts.

**Try it online!**, or see a test suite.

### How?

```
Ṭœp - Main link: number i, string s                   e.g. "fish 'n chips", 6
Ṭ   - untruth - get a list with 1s at the indexes of i      000001 <-- i.e. [0,0,0,0,0,1]
 œp - partition s at truthy indexes without borders       ["fish ","n chips"]
    - implicit print                                        fish n chips

```

As an example of using multiple indexes:

```
      "fish and chips", [6,8]
Ṭ      00000101 <- i.e. [0,0,0,0,0,1,0,1]
 œp  ["fish ","n"," chips"]
       fish n chips

```
> 4 votes

# Answer
# APL (Dyalog), 5 bytes

Zero-indexed. Takes index `n` as left argument and string `s` as right argument.

```
↑,1↓↓

```

Try it online!

`n` characters from `s`

`,` followed by

`1↓` one character dropped from

`n` characters dropped from `s`
> 4 votes

# Answer
# Haskell, 15 bytes

This requires the recently released GHC 8.4.1 (or higher). Now `<>`, as a function on Semigroups, is in Prelude. It is particularly useful on the function Semigroup

```
take<>drop.succ

```

Try it online!
Since tio is using an older bersion of GHC, I've imported `<>` in the header.
> 4 votes

# Answer
# R, 40 bytes

Just goes to show the variety of ways, none of which particularly compact, you can fiddle with strings in R.

```
function(s,n)intToUtf8(utf8ToInt(s)[-n])

```
> 4 votes

# Answer
# JS (ES6), ~~41~~ ~~32~~ 31 bytes

```
y=>i=>y.slice(0,i++)+y.slice(i)

```

Based on this. Takes input through currying, first is string, second is index.

-9 thanks to @JohanKarlsson

-1 thanks to @ETHproductions
> 3 votes

# Answer
## vim, ~~10~~ 7

```
DgJ@"|x

```

Takes 1-indexed input in the following format:

```
2
abcde

```

```
D      delete the number on the first line into register "
gJ     remove the newline while preserving whitespace on line 2
@"     run the " register as a macro - input is used as a count for...
|      the "go to nth column" command
x      delete the character at the cursor

```

Thanks to @DJMcMayhem for 3 bytes!
> 3 votes

# Answer
# 05AB1E, 6 bytes

```
vNÊiy?

```

Try it online!

**Explanation**

```
v       # for each element, index (y,N) in input1
 NÊi    # if N is not equal to input2
    y?  # print y

```
> 3 votes

# Answer
# Pyth, 3 bytes

```
.DE

```

Try it here.

Takes index first.
> 3 votes

# Answer
# Java 8, ~~45~~ 41 bytes

```
s->n->new StringBuffer(s).deleteCharAt(n)

```

*Saved 4 bytes thanks to @OlivierGrégoire*

My first code golf answer in something other than C#, even if it isn't the shortest for Java yet.
> 3 votes

# Answer
# brainfuck, 14 bytes

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

```

Try it online!

Reads zero-based one-byte index immediately followed by the string.
> 3 votes

# Answer
# Python 3, 24 bytes

```
lambda n,a:a[:n]+a[n+1:]

```

Try it online!
> 2 votes

# Answer
# Jelly, 4 bytes

```
Jḟị³

```

Try it online!

**Explanation**

```
Jḟị³
J    - all indices of the input string
 ḟ   - except for the input index
  ị  - return the elements at those indices
   ³ - of the input string

```
> 2 votes

# Answer
# 05AB1E, 5 bytes

```
ā²ÊÏJ

```

Try it online!

```
ā     # push range(1, len(input string) + 1)
 ²Ê   # Check each for != to input index
   Ï  # Keep characters from input where this array is 1
    J # Join

```
> 2 votes

# Answer
# Japt, ~~3~~ 2 bytes

```
jV

```

Try it online!
> 2 votes

# Answer
# PHP, 42 Bytes

0 indexed

```
<?=substr_replace($argv[1],"",$argv[2],1);

```

Try it online!
> 2 votes

# Answer
# Befunge-98, ~~35~~ ~~27~~ 25 bytes

*-4 bytes thanks to @eush77*

```
&#;1-:!#v_~,;
_@#:~;#~<;,

```

Try it online!

1-indexed, note that the input has a trailing null-byte.
> 2 votes

# Answer
# R, ~~48~~ 47 bytes

(1 byte saved through use of `el()` thanks to Giuseppe)

```
function(s,n)cat(el(strsplit(s,""))[-n],sep="")

```

Split the string into its individual characters, remove the nth and then concatenate again.

There may well be a better solution, strsplit() is quite unwieldy as it returns a list.
> 2 votes

# Answer
# **PHP, 41 bytes, 35 bytes excluding ?php**

```
<?php $argv[1][$argv[2]]='';echo$argv[1];

```

0-indexed

TIO
> 2 votes

# Answer
# Cubically, ~~46~~ ~~56~~ 34 bytes

```
R3D1R1$:7~?6{(~@7-0)6}~(~-0=7&6@7)

```

*(0-based index)*

Try it online! You must change `&6` to `?6&` on TIO due to a bug in the interpreter.

### How it works

```
R3D1R1$:7~?6{(~@7-0)6}~(~-0=7&6@7)
R3D1R1                             Set the top face to 1
      $                            Get next numeric input
       :7                          Set notepad to input
         ~                         Read (skip) next character (space)
          ?6{        }             If notepad is nonzero
             (     )6              While notepad is nonzero
              ~@7                  Print next inputted character
                 -0                Subtract 1 from notepad
                      ~            Read (skip) next character
                       (         ) Loop indefinitely
                        ~          Get next character
                         -0=7&6    Exit program if input is -1 (EOF)
                               @7  Output the input

```
> 2 votes

# Answer
# , 6 1 byte

```
_

```

# Test Cases

```
q)"abcde"_0
"bcde"
q)"abcde"_1
"acde"
q)"a != b"_2
"a = b"
etc.

```
> 2 votes

# Answer
# JavaScript (ES6), ~~39~~ ~~34~~ 33 bytes

```
n=>s=>s.replace(/./g,c=>n--?c:"")

```
* ~~5~~ 6 bytes saved thanks to Arnauld.
> 1 votes

# Answer
# PowerShell, 25 Bytes

3 Options, all the exact same bytecount.

```
$a,$b=$args;$a|% *ve $b 1

$args[1]|% *ve $args[0] 1

param($a,$b)$a|% *ve $b 1

```

calls `.Remove` on the string, using the number as an arg.
> 1 votes

# Answer
## C (gcc) - ~~45~~ 44 bytes

-1 Thanks to @Niel !

```
f(s,n)char*s;{for(;*s;++s)n--&&putchar(*s);}

```

alternative, 45 bytes :

```
g(s,n)char*s;{s[n++]=0;printf("%s%s",s,s+n);}

```

try it online
> 1 votes

# Answer
# Javascript (ES6), 48 bytes

```
x=>i=>x.substring(0,i-1)+x.substring(i,x.length)

```

### Or this (55 bytes)

```
n=[],x=>i=>x.split``.forEach((_,i)=>i==x?0:n.push(_))

```
> 1 votes

# Answer
# Chip, 115 bytes

```
*Z~S
,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?

`*Z~S`

This suppresses output on the first byte, because we don't want to print the index. That'd be silly.

`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 suppress output (`S`) for that character, effectively removing it from the string.
> 1 votes

# Answer
# , 8 bytes

```
{.,1}.}.

```

Uses zero-based indexing.

Try it online!

## Explanation

```
{.,1}.}.  Input: integer n (LHS), string s (RHS)
      }.  Drop the first n chars of s
   1}.    Drop one char from that
{.        Take the first n chars of s
  ,       Join them

```
> 1 votes

# Answer
# Bash, ~~83~~ ~~24~~ 22 bytes

```
echo ${1::$2-1}${1:$2}

```

24 bytes answer given by Digital Trauma

-2 bytes, quotation marks not needed

My first GodeGolf answer, any feedback is apreciated
> 1 votes

# Answer
# (s)ed - 6 bytes

1-based indexing.

```
s/.//n

```

Explanation:

```
s       # substitute command.
 /./    # match any single char.
   //   # substitution is empty.
     n  # Only match the 'n'th occurrence in a line.

```
> 1 votes

# Answer
## Excel, 29 bytes

```
=LEFT(A1,A2)&MID(A1,A2+2,9^9)

```

Assumes input in cells `A1` (string) and `A2` (integer, 0-indexing).

Takes the left part of the string with `LEFT` and the right part - actually a substring starting on position `A2+2` and `9^9` characters long (which is more then the max string length in one cell: 32,767 characters).
> 1 votes

# Answer
## R, 45 bytes

```
pryr::f(sub(paste0("(.{",n-1,"})."),"\\1",s))

```
> 1 votes

# Answer
# SmileBASIC 3, 23 bytes

We have character indexing, why not use it? Set a character index to the empty string to delete it.

Defines a command `A` which prints the output. Uses 0-indexing.

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

```
> 1 votes

# Answer
# C, ~~57~~ 50 bytes

```
#define f(s,n)for(i=n;s[i];i++)s[i]=s[i+1];puts(s)

```

0-indexed, naturally. I call this macro with:

```
int main(int argc, char **argv)
{
    if (argc != 3)
        return;
    f(argv[1],atoi(argv[2]));
}

```
> 1 votes

# Answer
# Lua, ~~51~~ 38 bytes

*Lowered to 38 bytes thanks to Jo King*

```
x,y=...print(y:sub(1,x-1)..y:sub(x+1))

```

Try it online!

Just like everything else in Lua this is 1-indexed.

### Explanation

Lua uses a table called `arg` to store arguments and the function `sub()` returns a substring of the string passed.

This is my first code golf entry, please be nice :)
> 1 votes

# Answer
Rebol, Red - 12 bytes

```
 remove at s n

```
> 1 votes

# Answer
# Attache, 13 bytes

```
{_[0:#_^^_2]}

```

Try it online!

## Explanation

```
{_[0:#_^^_2]}
{           }    anonymous lambda (_ = 1st argument, _2 = 2nd argument)
   0:#_          range from 0 to the length of _
       ^^_2      ...without the 2nd argument
 _[        ]     obtain characters from _ using that range

```
> 1 votes

# Answer
# Runic, 48 bytes

```
   /~~{ R:1(?\~@
/3{\?)0:\S{-1/
\s3s}}1-U}:irui<

```

Try it online!

Not all test cases work at the moment: a few (more) flaws discovered in the parser.

* *Numbers* are read *as numerical values* and don't `u`nconcatenate (I need to call `.ToString()` on the popped object, then split the result into a char array; this will match intended spec of "doing operations to the best of the execution context's ability with the given stack values)
* Spaces (and other white space) are input value separators (I need to readd the control character demarcation; got lost in the previous attempts to fix the next issue). After fixing inputs such as `a != b` would need to be passed as `a\ !=\ b`
* Input needs a trailing newline (have not discovered a fix to this yet)

Other test cases work (and are considered 0-indexed).

## Explanation

Program starts in the lower right (red), reads a string, unconcatenates it, reverse it (so the first character is at the top of the stack; behavior is so that `u` followed by `q` results in concatenation in the desired order, and `q` works the way it does because `>'a'bq`, \>\`ab\`q, and `>"ab"` should all have the same result). Then the program reads the integer value and assumes (per question spec) that it is in the range \[0,L), values above this range will simply loop (effective `%`). This value is duplicated and stored at the bottom of the stack for later.

The lower left portion (yellow) is the section responsible for shifting the string around on the stack N times, where N is the input value. The `3s3s` portion rotates the top 2 items on the stack below the 3rd (which results in the front-most character in the string being rotated to the end without affecting the positions of the two counters with the next two `}` rotates). It exits this branch along the top (green), heading right and popping 2 values (the loop counter and then the character to discard) and rotating the saved input value back to the top.

The top right (blue) then loops the remaining characters back into place in reverse, exiting the loop (purple) towards the `@` which discards the remaining loop counter and prints the stack top to bottom.

*Picture has a mistake, along the bottom are some stack manipulators, `}}}{` and in typing up this post I noticed that `}{` cancels out and saves 3 bytes.*
> 1 votes

# Answer
# Factor, 10 bytes

```
remove-nth

```

Try it online!
> 1 votes

# Answer
# Befunge-93, 26 bytes

```
&>1# -#,:#~_~~>:# 1#~+#,_@

```

Try it online!

1-indexed, does NOT require a null byte at the end of the string because that's lame. However, if you really want to get all "let's screw with the input format to make the code shorter", here is one that saves 3 bytes by assuming a null terminator:

```
&>1# -#,:#~_~~>:#~ #,_@

```
> 1 votes

# Answer
# Perl 5, 19 bytes

18 bytes of code + `-p` flag

```
substr($_,<>,1)=""

```

Try it online!

`substr($_,<>,1)` returns `1` character at index `<>` (the 2nd input) in the string `$_` (the input). And `=""` changes it to `""`. And `$_` is implicitely printed at the end thanks to `-p` flag.
> 0 votes

# Answer
# Go, 50 bytes

1-indexed because we're all human, I think.

```
func f(s string,n int)string{return s[:n-1]+s[n:]}

```

Try it online!
> 0 votes

# Answer
# Lua, 37 bytes

Uses 0 indexing

```
s,i=...
print(s:sub(1,i)..s:sub(i+2))

```

Try it online!
> 0 votes

# Answer
## QBIC, 28 bytes

```
B=@ `+B?_t_s;,:|+_sB,a+2,_lB

```

This is an adaptation of my Substring Subtraction answer.

Explanation:

```
B=@ `+B     Prepend a space to the input string
?           PRINT
 _t           a trimmed version (drops the space again)
   _s         SUBSTRING
     ;,:|       Read B$ from cmd line, read n from cmd line
                SUBSTRING with a stirng and a positive N takes chars 1-N from the left.
   +_sB       Plus a second substring
     ,a+2       Starting behind the removee-index
     ,_lB       taking all the remaining characters

```

This could go all the way down to 22 bytes if I didn't need that hacky space prepended. Time to change Substring-behaviour for this use-case...

```
?_s;,:-1|+_sA,a+1,_lA

```
> 0 votes

# Answer
# Braingolf, ~~38~~ 37 bytes

```
VVR<lMMv.M2+-[R<vv]R$_v.?1-[R<v]|R&@;

```

Try it online!

0-based index

As always with Braingolf, the TIO link includes the entire Python3 parser. The code is the 2nd argument, the index is the 3rd argument, and the string is the 4th argument.
> 0 votes

# Answer
# Retina, 29 bytes

```
1`\d+
$*
+`(	+)	(.)
$2$1
	.

```

Try it online!

The index and the string are on the same line separated by one tab. The index is zero-based.
> 0 votes

# Answer
# Brain-Flak, 39 bytes

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

```

Try it online!

This has a one byte penalty for the `-c` flag which enables ASCII input and output. This takes the first parameter as a character code, which OP has allowed.

So the input is

```
0x01abcde

```

This uses zero indexing. Unfortunately, TIO doesn't allow null bytes in input, but this works locally so it's not an issue.
> 0 votes

# Answer
# Swift - 86 bytes (0-indexed)

```
func l(s:String,n:Int){var a=s;a.remove(at:a.index(a.startIndex,offsetBy:n));print(a)}

```

Function that can be used as `l(s:"abcdefg",n:3)`

**Check it out!**

---

# Swift - 120 bytes

Since I thought the above is quite boring, I came up with another solution:

```
func l(s:String,n:Int){let b=s.startIndex;print(s[b...s.index(b,offsetBy:n-1)]+s[s.index(b,offsetBy:n+1)..<s.endIndex])}

```

Works as the one below, it's just more interesting.
> 0 votes

# Answer
# shortC, 36 bytes

```
Df(s,n)Oi=n;s[i];i++)s[i]=s[i+1];Js)

```

See my plain C answer for how to call the macro.
> 0 votes

# Answer
# REXX 30 Bytes

```
parse arg p x
say delstr(x,p,1)

```
> 0 votes

# Answer
## Batch, 56 bytes

```
@set/ps=
@set/ai=%1+1
@call echo %%s:~0,%1%%%%s:~%i%%%

```

Takes `n` 0-indexed as a command-line parameter and reads `s` from STDIN.
> 0 votes

# Answer
## \>\<\>, 24 bytes

```
i:0(?v$1-:}?!~{
;?(3l<o{

```

Try it online, or at the fish playground

Takes the string as input from STDIN, and assumes the number for the index is already on the stack; outputs to STDOUT. It's 1-indexed.

The fish reads the string one character at a time, except it forgets the *n*th one after it reads it. It then prints the stack (in reverse) until there are only two (junk) things left.

Example: `4` and `Boarfish` becomes `Boafish`.
> 0 votes

# Answer
# Braingolf, 23 bytes

```
VRMv.1-[R<v]R$_[R>v]R&@

```

Try it online!

Not at all golfy
> 0 votes

# Answer
# Excel, 20 bytes

Different approach from previous Excel answer.

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

```
=REPLACE(B1,A1,1,"")

```
> 0 votes

# Answer
# QBasic, 49 bytes

Uses 1-indexing.

```
INPUT n
LINE INPUT s$
?LEFT$(s$,n-1)+MID$(s$,n+1)

```

Reads a number and a string, and then prints the leftmost `n-1` characters of the string plus everything from index `n+1` to the end of the string.
> 0 votes

# Answer
# T-SQL, 28 bytes

```
SELECT STUFF(s,n,1,'')FROM t

```

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

I'm assuming **n** is 1-based, so I can pass it straight into the SQL Stuff function. `STUFF` inserts or replaces the characters at the given location, and in my case I'm replacing a single character with a blank.
> 0 votes

# Answer
# \>\<\>, 9 bytes

```
i$:&?o&1-

```

Try it online!

Takes in the number via the `-v` flag and the string through STDIN. This is 0 indexed and ends with an error. You can add 5 bytes to avoid the error.

### Explanation:

```
i           Get inputted character
 $          Swap and bring counter to the top
  :&        Store a copy in the register
    ?o      If the counter is not zero, print the character
      &1-   Restore and decrement the counter

```
> 0 votes

# Answer
# Backhand, 12 bytes

```
{I>{{[ ~:oi_

```

Try it online!

Gets the inputted number followed by the string. 1 indexed.
> 0 votes

# Answer
# 05AB1E, 4 bytes

```
IõIǝ

```

Try it online or verify all test cases.

or alternatively

```
õŠŠǝ

```

Try it online or verify all test cases.

**Explanation:**

```
I       # Take the first string input
 õ      # Push an empty string
  I     # Take the second index-integer input
   ǝ    # Replace the character at the given index with the empty string

õ       # Push an empty string
 ŠŠ     # Triple-swap twice; a,b,c → c,a,b → b,c,a (implicitly using the two inputs)
        #  (`c` is the empty string here, `a` and `b` the input)
   ǝ    # Replace the character at the given index with the empty string

```
> 0 votes

# Answer
# Forth (gforth), 45 bytes

```
: f tuck - 1- -rot 2dup type + 1+ swap type ;

```

Try it online!

0-indexed, n should be on top of the stack

### Explanation

Prints the string up to the given character, then prints the remainder of the string after the given character

### Code Explanation

```
\ since a lot of stack manipulation is happening, I will be including a listing of the
\ stack after each step. s = string address, g = length of string, n = char to remove
: f          \ starts a new word definition                                     | s g n
  tuck -     \ store a copy of n, then get the length of the end of the string  | s n g-n
  1-         \ subtract 1 from the length of the end ( to not output junk)      | s n g-n-1
  -rot       \ move the end-string length to the back of the stack              | g-n-1 s n
  2dup type  \ duplicate the address and length of the first output, then print | g-n-1 s n
  + 1+       \ get the starting address for the second output                   | g-n-1 s+n+1
  swap type  \ swap to get in proper order, then print                          |
;            \ end word definition                                              |

```
> 0 votes

# Answer
# Stacked, 17 bytes

```
{%y:0\#'..x-keep}

```

Try it online!

## Explanation

```
{%y:0\#'..x-keep}    anonymous lambda, takes input on the stack
{%              }    parameters: x, y
  y:                 push y twice             [y, y]
    0\               push 0 beneath           [y, 0, y]
      #'             push size of TOS         [y, 0, size(y)]
        ..           range                    [y, range(0, size(y))]
          x-         subtract x from this     [y, range(0, size(y)) - x]
                     (thus x-x = 0)
            keep     keep respective chars    [the answer]
                     this removes the character at the `x`th index

```
> 0 votes

# Answer
# MBASIC, ~~46~~ 45 bytes

```
1 INPUT N,S$:PRINT LEFT$(S$,N-1);MID$(S$,N+1)

```

Just slamming substrings together, 1-indexed.

Output:

```
? 4,314151
31451

? 5,1234.5
12345

? 4,+-*/
+-*

? 3,a != b
a = b

? 2,abcde
acde

? 1,abcde
bcde

```
> 0 votes

# Answer
## PHP, 43 Bytes

**Try it online**

run as pipe.

**Code**

```
<?=strtr(($s=$argv)[0],[$s[0][$s[1]]=>""]);

```

**Explanation**

```
<?=strtr(($s=$argv)[0],        # Set a shorter name for the $argv arguments var
          [$s[0][$s[1]]=>""]); # Replace for "" in the position

```
> 0 votes

# Answer
## JavaScript 30 bytes

```
(n,[...s])=>(s[n]='',s.join``)

```

Try it online!
> 0 votes

# Answer
# Tcl, 37 bytes

```
proc R n\ s {string repl $s $n $n ""}

```

Try it online!
> 0 votes

# Answer
# Vyxal, 1 byte

Try it Online!

I don't know why I didn't use the built in
> 0 votes

# Answer
# Thunno 2, 1 byte

```
Ɗ

```

Attempt This Online!

Built-in.
> 0 votes

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


title: How long is my number?

text:
# Question
Title: How long is my number?
## Challenge

Given an integer \\$Q\\$ in the range \\$-2^{100} ≤ Q ≤ 2^{100}\\$, output the number of digits in that number (in base 10).

## Rules

Yes, you may take the number as a string and find its length.

All mathematical functions are allowed.

You may take input in any base, but the output must be the length of the number in base 10.

Do not count the minus sign for negative numbers. The number will never have a decimal point.

Zero can either have one or zero digits.

Assume the input will always be a valid integer.

## Examples

```
Input > Output

-45 > 2
12548026 > 8
33107638153846291829 > 20
-20000 > 5
0 > 1 or 0

```

## Winning

Shortest code in bytes wins.

# Answer
> 14 votes
# Brachylog, 1 byte

```
l

```

Try it online!

Another builtin solution, but this one has the shortest name (unless someone finds a language which does this task in zero bytes). This should work in both Brachylog 1 and Brachylog 2.

This is a function submission (the TIO link contains a command-line argument that causes the interpreter to run an individual function rather than a whole program), partly because otherwise we'd have to spend bytes on output, partly because Brachylog's syntax for negative numbers is somewhat unusual and making this program a function resolves any potential arguments about input syntax.

It's often bothered me that most of Brachylog's builtins treat negative numbers like positive ones, but that fact ended up coming in handy here. I guess there are tradeoffs involved with every golfing language.

# Answer
> 44 votes
# Taxi, 1118 bytes

```
1 is waiting at Starchild Numerology.Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.Go to Chop Suey:n 1 r 1 l 4 r 1 l.Pickup a passenger going to Crime Lab.'-' is waiting at Writer's Depot.Go to Writer's Depot:n 1 l 3 l.Pickup a passenger going to Crime Lab.Go to Crime Lab:n 1 r 2 r 2 l.Switch to plan "n" if no one is waiting.-1 is waiting at Starchild Numerology.[n]0 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 r 1 l 1 l 2 l.Pickup a passenger going to Cyclone.Pickup a passenger going to Addition Alley.Go to Cyclone:e 1 l 2 r.[r]Pickup a passenger going to Cyclone.Pickup a passenger going to Addition Alley.Go to Zoom Zoom:n.Go to Addition Alley:w 1 l 1 r.Pickup a passenger going to Addition Alley.Go to Chop Suey:n 1 r 2 r.Switch to plan "f" if no one is waiting.Pickup a passenger going to Sunny Skies Park.Go to Sunny Skies Park:n 1 l 3 l 1 l.Go to Cyclone:n 1 l.Switch to plan "r".[f]Go to Addition Alley:n 1 l 2 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:n 1 r 1 r.Pickup a passenger going to Post Office.Go to Post Office:n 1 l 1 r.

```

Try it online!

Ungolfed:

```
1 is waiting at Starchild Numerology.
Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to Chop Suey.
Go to Chop Suey: north 1st right 1st left 4th right 1st left.
Pickup a passenger going to Crime Lab.
'-' is waiting at Writer's Depot.
Go to Writer's Depot: north 1st left 3rd left.
Pickup a passenger going to Crime Lab.
Go to Crime Lab: north 1st right 2nd right 2nd left.
Switch to plan "n" if no one is waiting.
-1 is waiting at Starchild Numerology.
[n]
0 is waiting at Starchild Numerology.
Go to Starchild Numerology: south 1st right 1st left 1st left 2nd left.
Pickup a passenger going to Cyclone.
Pickup a passenger going to Addition Alley.
Go to Cyclone: east 1st left 2nd right.
[r]
Pickup a passenger going to Cyclone.
Pickup a passenger going to Addition Alley.
Go to Zoom Zoom: north.
Go to Addition Alley: west 1st left 1st right.
Pickup a passenger going to Addition Alley.
Go to Chop Suey: north 1st right 2nd right.
Switch to plan "f" if no one is waiting.
Pickup a passenger going to Sunny Skies Park.
Go to Sunny Skies Park: north 1st left 3rd left 1st left.
Go to Cyclone: north 1st left.
Switch to plan "r".
[f]
Go to Addition Alley: north 1st left 2nd left.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: north 1st right 1st right.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st left 1st right.

```

Explanation:

```
Pickup the input and split it into individual characters
Pickup the value 1.
If the first character a hyphen, add -1. Otherwise, add 0.
Keep picking up characters and adding 1 until you're out.
Convert the running total to a string and print to stdout.

```

# Answer
> 21 votes
## Mathematica, 13 bytes

```
IntegerLength

```

There's a built-in... returns `0` for `0`.

# Answer
> 16 votes
# dc, 3

```
?Zp

```

Note that normally `dc` requires negative numbers to be given with `_` instead of the more usual `-`. However, in this case, either may be used. If `-` is given, then `dc` treats this as a subtraction on an empty stack, throws `dc: stack empty`, and then continues with the rest of the number; Thus the result is no different.

Try it online.

```
?    # input
 Z   # measure length
  p  # print

```

# Answer
> 14 votes
## Retina, 2 bytes

```
\d

```

Try it online!

Retina doesn't really know what numbers are, so the input is treated as a string and we simply count the digit characters.

# Answer
> 6 votes
# 05AB1E, 2 bytes

```
Äg

```

Try it online! or Try All Tests!

```
Ä  # Absolute value
 g # Length

```

# Answer
> 6 votes
## Alice, 16 bytes

```
//; 'q<)e
o!@i -

```

Try it online!

### Explanation

Finding a half-decent layout for this was quite tricky. I'm still not super happy with it because of the spaces, the `<` and the `;`, but this is the best I could do for now.

String length is one of those very common built-ins that doesn't exist in Alice, because its input is a string and its output is an integer (and all Alice commands are strictly integers to integer or strings to strings). We can measure a string's length by writing it to the tape in Ordinal mode and then finding its end in Cardinal mode.

```
/      Reflect to SE. Switch to Ordinal. While in Ordinal mode, the IP will bounce
       diagonally up and down through the code.
!      Store an implicit empty string on the tape, does nothing.
;      Discard an implicit empty string, does nothing.
i      Read all input as a string.
'-     Push "-".
<      Set the horizontal component of the IP's direction to west, so we're bouncing
       back now.
-      Remove substring. This deletes the minus sign if it exists.
'i     Push "i".
;      Discard it again.
!      Store the input, minus a potential minus sign, on the tape.
/      Reflect to W. Switch to Cardinal. The IP immediately wraps to the
       last column.
e)     Search the tape to the right for a -1, which will be found at the end
       of the string we stored there.
<      Does nothing.
q      Push the tape head's position, which is equal to the string length.
'<sp>  Push " ".
;      Discard it again.
/      Reflect to NW. Switch to Ordinal. The IP immediately bounces off
       the top boundary to move SW instead.
o      Implicitly convert the string length to a string and print it.
       IP bounces off the bottom left corner, moves back NE.
/      Reflect to S. Switch to Cardinal.
!      Store an implicit 0 on the tape, irrelevant.
       The IP wraps back to the first line.
/      Reflect to NE. Switch to Ordinal. The IP immediately bounces off
       the top boundary to move SE instead.
@      Terminate the program.

```

I also tried taking care of the minus sign in Cardinal mode with `H` (absolute value), but the additional mode switch always ended up being more expensive in my attempts.

# Answer
> 6 votes
# brainfuck, 37 bytes

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

```

Output is by byte value.

Try it online!

### Explanation

```
-[+>+[+<]>+]>->  Constant for 45 (from esolangs wiki)
,                Read a byte of input
[-<->]           Subtract that byte from 45
<[>+>]           If the result is nonzero then increment a cell and move to the right
                 (0 means it was a minus; so not counted)
,[<+>,]          Read a byte and increment the cell to its left until EOF is reached
<.               Print the cell that was being incremented

```

# Answer
> 5 votes
# PHP, 23 Bytes

```
<?=-~log10(abs($argn));

```

Try it online!

log of base 10 of the absolute value plus one cast to int

for zero as input log10 gives back `INF` which is interpreted as false

The better way is to replace `$argn` with `$argn?:1` +3 Bytes

# PHP, 27 Bytes

```
<?=strlen($argn)-($argn<0);

```

string length minus boolean is lower then zero

+2 Bytes for string comparision `$argn<"0"`

Try it online!

## PHP, 32 Bytes

```
<?=preg_match_all("#\d#",$argn);

```

Try it online!

Regex count all digits

## 35 Bytes

```
<?=strlen($argn)-strspn($argn,"-");

```

Try it online!

string length minus count `-`

strspn

# Answer
> 5 votes
# Fortran 95 (gfortran), ~~121~~ ~~96~~ 95 bytes

```
program c
character b
call get_command_argument(1,b,length=i)
print*,i-index(b,'-')
end program

```

Explanation:
Subtracts the index of the '-' sign from the length of the argument.
Arrays start at 1 in Fortran, and index() returns 0 if symbol not found.

*Edit: Switched to implicit integer "i", also consolidated argument getter.*

*Edit: -1 byte thanks to @Tsathoggua*

# Answer
> 5 votes
# GNU AWK, 18 17 15 bytes

```
$1=gsub(/\w/,1)

```

Substitutes every number character (except for the minus sign) alphanumeric character of the input for another character (here, the number 1), and assigns the number of substitutions to the output.

Thanks for cnamejj and manatwork for helping me saving some bytes!

Try it online!

# AWK, 17 bytes

```
$1=gsub(/[^-]/,1)

```

This is a previous answer, that should work on any Awk version, not only GNU's.

Try it online!

# Answer
> 3 votes
# PowerShell, 24 Bytes

```
"$args"-replace'-'|% Le*

```

casts the "absolute" value of the input args to a string and gets the 'length' property of it.

1 byte shorter than `"".Length`

until someone finds a better way to get the abs of a number in PS this is probably as short as it will get.

# Answer
> 3 votes
# 05AB1E, 2 bytes

```
þg

```

Try it online!

```
   # Implicit input [a]...
þ  # Only the digits in [a]...
 g # length of [a]...
   # Implicit output.

```

# Answer
> 3 votes
# Ruby, ~~15~~ 11+1 = ~~16~~ 12 bytes

Uses the `-n` flag.

```
p~/$/-~/\d/

```

Try it online!

### Explanation

```
                  # -n flag gets one line of input implicitly
p                 # Print
 ~/$/             # Position of end of line (aka string length) in input
     -            # minus
      ~/\d/       # Position of first digit (1 if negative number, 0 otherwise)

```

# Answer
> 2 votes
# Python 2, ~~31~~ 22 bytes

*-9 bytes thanks to Rod.*

```
lambda i:len(`abs(i)`)

```

Try it online!

# Answer
> 2 votes
# Jelly, 2 bytes

```
DL

```

**Try it online!**

This does literally what was asked:

```
DL - Main link number n         e.g. -45
D  - convert to a decimal list       [-4,-5]
 L - get the length                  2

```

# Answer
> 2 votes
# CJam, 5 bytes

```
q'--,

```

String based.

Try it online!

9 bytes for a purely math-based solution:

```
riz)AmLm]

```

Or another 5 with base conversion:

```
riAb,

```

# Answer
> 2 votes
# JavaScript (ES6), ~~27~~ ~~26~~ ~~25~~ 24 bytes

Takes input as a string.

```
s=>s.match(/\d/g).length

```
* Saved two bytes thanks to Arnauld.

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

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

```

Try it online!

This is 62 bytes of code and +1 byte for the `-a` flag.

I tried two other approaches, but unfortunately both of them were longer:

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

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

```

This *should* be a very short answer. In fact, if we didn't have to support negative numbers, we could just do:

```
([]<>)

```

But we have to compare the first input with 45 (ASCII `-`) first, which is most of the byte count of this answer.

An arithmetic solution might be shorter.

# Answer
> 2 votes
# Japt, 5 bytes

```
a s l

```

Try it online!

# Explanation

```
 a s l
Ua s l
Ua     # take the absolute value of the input
   s   # and turn it into a string
     l # and return its length

```

# Answer
> 2 votes
# Ruby, 20 bytes

```
->a{a.abs.to_s.size}

```

# Answer
> 2 votes
# RProgN 2, 2 bytes

```
âL

```

Try it online!

Simply gets the absolute value of the input, and counts the digits.

# Answer
> 2 votes
# Pyth, 4 bytes

```
l`.a

```

Try it online!

All test cases

# Answer
> 2 votes
# Perl 5, 9 + 1 = 10 bytes

```
$_=y/-//c

```

Try it online!

Run with `-p` (1 byte penalty).

## Explanation

```
$_=y/-//c
            {implicit from -p: for each line of input}
   y/ //    In {the input}, replace
        c     everything except
     -        '-'
$_=         Store number of replacements back in $_
            {implicit from -p: output $_}

```

We treat the input as a string in order to handle numbers outside the 64-bit range. One interesting trick here is that we don't have to specify what we're replacing the nonhyphens *with*; we can still count the number of replacements that occur.

The TIO link uses `-l` in order to let us run the program on multiple data without the newlines between them interfering. If the program only has to run once, we can do without it, so long as there's no final newline on the input.

# Answer
> 2 votes
## R, 18 bytes

```
nchar(abs(scan()))

```

# Answer
> 2 votes
## JavaScript (ES6), 23 bytes

```
s=>`${s>0?s:-s}`.length

```

Different approach to Shaggy's answer.

# Answer
> 2 votes
# Java, ~~30~~ 24 bytes

```
i->(""+i.abs()).length()

```

Assumes `i` is a `BigInteger`. Also, the type is contextualized, so no imports are required, as shown in the test code.

## Test

```
// No imports
class Pcg120897 {
  public static void main(String[] args) {
    java.util.function.ToIntFunction<java.math.BigInteger> f =
        // No full class declaration past here
        i->(""+i.abs()).length()
        // No full class declaration before here
      ;
    System.out.println(f.applyAsInt(new java.math.BigInteger("-1267650600228229401496703205376"))); // -(2^100)
    System.out.println(f.applyAsInt(new java.math.BigInteger("1267650600228229401496703205376"))); // (2^100)
  }
}

```

## Saves

* 30 -\> 24 bytes : thanks to @cliffroot

# Answer
> 2 votes
# V (vim), 20 bytes

```
:s/-
C<C-r>=strlen(<C-r>")
<esc>

```

Try it online!

Remove minuses(if any), cut the line, and get its length.

Not sure if I need the `<esc>` at the end.

# Answer
> 2 votes
# Risky, 2 bytes

```
!?}*

```

Try it online!

```
! length
?     input
}   base convert
*     10

```

# Answer
> 2 votes
# FALSE, 14 bytes

```
^45=[1+^~][]#.

```

Try it online!

Explanation: If first character is '-' (ascii code 45), then push -1. Else push 0. Add 1 to number on stack until EOF character is reached.

# Answer
> 1 votes
# C++, ~~80~~ 76 bytes

```
#include<string>
int main(int,char**c){printf("%d",strlen(c[1])-(*c[1]<46));}

```

Prints the length of the argument, minuses 1 if the first character is a minus because `bool` guarantees conversion to `1` if `true` or `0` if `false`

* 4 bytes thanks to @Squidy for pointing out I can use `<46` instead of `=='-'`, and to deference the array instead of `[]`

# Answer
> 1 votes
# Alice, 10 bytes (non-competing)

```
 /d/
O@IHc

```

Try it online!

This is a non-competing solution, because at the time this challenge was posted the command `c` was bugged in the official (and only :D) interpreter. Martin Ender fixed it in the meanwhile, so this now works.

### Explanation

The instruction pointer passes through the two mirrors (`/`) multiple times, so it may be a bit difficult to follow. I'll try to explain it as clearly as I can, using cardinal directions (e.g. N is up, SW is down to the left...). I'll call `/1` the leftmost mirror, and `/2` the rightmost one.

```
Command    Direction    Comment
               E        Execution starts from the upper-left corner going right
   /1        E → SE     Passing through the mirror changes direction and switches
                        to ordinal mode (string operations)
   I        SE → NE     Push the input string to the stack, then bounce against
                        the bottom of the code
   /2       NE → S      Back to cardinal mode (numeric operations)
   H           S        Pop n, push abs(n). Execution wraps from bottom to top
   /2        S → SE     Ordinal mode again
   c        SE → NW     Pop s, push each char of s separatedly. Bounce against
                        the bottom right corner
   /2       NW → W      Cardinal mode
   d           W        Push the depth of the stack (which is now equal to
                        the number of characters in abs(input))
   /1     W → NW → SW   Pass through the mirror, then bounce agains the top
   O        SW → NE     Output the result, then bounce on the bottom left corner
   /1       NE → S      Last mirror, I promise
   @           S        Terminate execution

```

# Answer
> 1 votes
# REXX 22 Bytes

```
arg "-" a
say length(a)

```

Explanation: There is no distinction in Rexx between numbers and strings. The action you perform is what defines the type. The "typing" applies just to that action and can change at any time.

So, here the number (say -20) is treated as a string. The "arg" instruction (short for parse arg) tells Rexx to search for the first "-" and then put everything after it in the variable "a". If "-" is not found then everything goes in "a".

Try it here

REXX functions and instructions

# Answer
> 1 votes
# GNU Make, 78 bytes

Imperative style:

```
$(eval T=$1)$(foreach D,$(shell seq 9),$(eval T=$(subst $D,? ,$T)))$(words $T)

```

Functional style, 113 bytes:

```
$(eval 2?=$(shell seq 9))$(if $2,$(call $0,$(subst $(word 1,$2),? ,$1),$(wordlist 2,$(words $2),$2)),$(words $1))

```

Pure Make, 83 bytes:

```
$(eval T=$1)$(foreach D,0 1 2 3 4 5 6 7 8 9,$(eval T=$(subst $D,? ,$T)))$(words $T)

```

# Answer
> 1 votes
# Bash, 15 bytes

```
wc -L<<<${1//-}

```

Try it online!

Deletes `-` from input as array, and otputs length of longest line (wc -c returns one char more than length)

# Answer
> 1 votes
# TI-Basic (TI-84 Plus CE, OS 5.2+), 6 bytes

```
length(toString(abs(Ans

```

TI-Basic is a tokenized language; `length(` and `toString(` are two bytes each.

`Ans` is used as implicit input; the last (only) line's value is implicitly returned.

Pretty simple, takes the absolute value to get rid of a minus sign, converts to string, returns the length of the string.

A 6-byte mathematical approach that doesn't work for 0:

```
1+log(abs(Ans

```

# Answer
> 1 votes
# awk, 22 bytes

```
$1=length($1<0?-$1:$1)

```

Try it online!

All test cases

# Answer
> 1 votes
# JavaScript, 23 bytes

```
x=>`${x<0?-x:x}`.length

```

# Answer
> 1 votes
# Jelly, 5 bytes

```
A‘l⁵Ċ

```

Try it online!

# Answer
> 1 votes
# Pari/GP, 13 bytes

```
n->#digits(n)

```

Try it online!

# Answer
> 1 votes
# Excel VBA, 15 Bytes

Anonymous VBE immediate window function that takes input from `[A1]` and outputs to the VBE immediate window

```
?[Len(Abs(A1))]

```

# Answer
> 1 votes
# Bound, 4 bytes

```
ib_,

```

Explanation:

```
i # Get user input
b # Separate each digit of the top element into individual elements
_ # Put the total number of elements onto the stack
, # Remove all but the top element from the stack

```

Bound then prints the stack at the end of execution, so you can then see the result.

Try it online!

# Answer
> 1 votes
# GolfScript, 5 bytes

```
"-"-,

```

Try it online!

```
"-"-    # Remove all "-" in the input
    ,   # Get the length of the string

```

# Answer
> 1 votes
# APL (Dyalog Extended), 4 bytes

```
≢∘⍕|

```

Try it online!

# Answer
> 1 votes
# BRASCA, 15 bytes

```
iM:45S=[xx0]x!n

```

Try it online!

## Explanation

```
i                - Turn the ascii characters 0-9 to numbers
 M:45S=[  0]     - Move the bottom of the stack to the front and check if it's a minus
        xx       - If so: remove the minus
            x    - Remove any excess items on the stack
             !n  - Print the length as a number

```

# Answer
> 1 votes
# Whispers v2, 39 bytes

```
> Input
>> |1|
>> "2"
>> #3
>> Output 4

```

Try it online!

Boring answer. Get input, absolute value, convert to string, return length.

# Answer
> 1 votes
# Arn `-s`, 2 bytes

```
.|

```

Try it!

Take absolute value, `-s` takes size. Implicit casting.

# Answer
> 1 votes
# PowerShell Core, 20 bytes

```
$args|% *m '-'|% Le*

```

Try it online!

# Answer
> 1 votes
# Julia, 7 bytes

```
ndigits

```

Try it online!

# Answer
> 1 votes
# Vyxal, 2 bytes

```
ȧL

```

Try it Online!

```
 L # Length of...
ȧ  # Absolute value of...
   # Implicit input

```

# Answer
> 1 votes
# Factor \+ `project-euler.common`, 13 bytes

```
number-length

```

Try it online!

# Answer
> 1 votes
# K (ngn/k), 17 bytes

```
{#$$[x<0;x*-1;x]}

```

Try it online!

Can't handle big numbers correctly, e.g. `33107638153846291829`. Still decent though.

# Answer
> 1 votes
# K (ngn/k), 11 bytes

```
{#($x)^"-"}

```

Try it online!

Easy.

Explanation:

```
{#($x)^"-"}    Main function. Takes x as input
  ($x)         x as string
      ^"-"     Without string literal "-" (Remove negative symbol)
 #             Length

```

# Answer
> 1 votes
# Fig, \\$2\log\_{256}(96)\approx\\$ 1.646 bytes

```
LA

```

Try it online!

```
LA
L  # Length of
 A # The absolute value of the input

```

# Answer
> 0 votes
# Fourier, 30 bytes

```
I~S<0{1}{-2*S~S}S{0}{S^~S}SL^o

```

**Try it on FourIDE!**

Fourier doesn't have strings, so it uses logs instead. Bytes are wasted on supporting zero and negative numbers.

# Answer
> 0 votes
# MATL, 6 bytes

```
nGU0<-

```

Try it online!

### Explanation

```
n     % Implicitly input a string. Push its length
G     % Push input again
U     % Convert to number (floating-point double). Although integers with absolute
      % value exceeding 2^53 cannot be represented exactly, the sign is correct
0<    % Is it negative?
-     % Subtract. Implicitly display

```

# Answer
> 0 votes
# Befunge, 35 bytes

```
77*~`!1+:v
~0`#@    ># !#. #- #2_1+

```

Try it online!

```
77*~`!            add 49 to the stack and see if that is less than 50 (ascii for
                  '-')
1+:v              if there is a -, don't count it. Add 1 so we don't
                  have a zero at the top of the stack. Move down.
># !#. #- #2_1+   move right and add one to the total. (Will remove later)
~0`#@             Loop back around and take an input and make sure it is not end of
                  the string (-1, so we make sure it is > 0)
># !#. #- #2_1+   check to see if there was an input. If there was, add one to the
                  total. If not, move left. Subtract 2 because we added 1 at two
                  different locations. Print output and end program.

```

# Answer
> 0 votes
# Bean, 20 bytes

### Hexdump:

```
00000000: 2650 80d3 d080 a05d 2080 0921 8181 0020  &P.ÓÐ. ] ..!...
00000010: 8001 dc64                                ..Üd

```

### JavaScript equivalent:

```
a.match(/\d/g).length;

```

### Explanation:

Implicitly takes input as a decimal string in `a` and implicitly outputs the length of the match, which is all the decimal digits in the string. Returns `1` for input of `0`.

See Demo.

# Bean, 22 bytes

### Hexdump:

```
00000000: 2aa0 1f26 4ccc d3a0 8043 53a0 802d 2043  * .&LÌÓ .CS .- C
00000010: 9125 398b 253a                           .%9.%:

```

### JavaScript equivalent:

```
with(Math)((log10(abs(A))^0)+1);

```

### Explanation:

Implicitly takes input as a decimal integer in `A`, takes the absolute value, then log-base-10, XORs with `0`, then adds `1`.

When `A` is `0`, the returned value of `log10()` is `-Infinity`, and `-Infinity ^ 0` is `0` in JavaScript, so the returned value for `0` is `1`.

See Demo.

# Answer
> 0 votes
# , 7 bytes

```
#@":@**

```

Try it online!

All the solutions I came up with:

```
0>.@>.10^.>:@(**)
[:#10&#.inv
#@-.&'-'
#@":@**

```

The first one is math, the second is base conversion, the third takes a string as input, and the shortest takes a number.

The current solution looks like this:

```
              ┌─ #
        ┌─ @ ─┴─ ":
  ┌─ @ ─┴─ *
──┴─ *

```

The parent root is a hook between the upper tine and the lower tine. The lower tine (`*`) is a monad that calculates magnitude. The upper tine is a composition:

```
         ┌─ #
   ┌─ @ ─┴─ ":
@ ─┴─ *

```

This composes the upper tine (another composition) with `*`, in this case, a dyad. This is the dyad for multiplication. In the last tine:

```
   ┌─ #
@ ─┴─ ":

```

This calculates format (`":`) then length (`#`).

In English form, this is "multiply `x` times the sign of `x`, then convert this to a string, then take the length of this string". Basically, `abs.toString.length`.

# Answer
> 0 votes
# C#, 33 bytes

```
i=>Math.Abs(i).ToString().Length;

```

# Answer
> 0 votes
# MATL, 4 bytes

```
47>s

```

Inspired by Martin's Retina answer: count how many characters have code point exceeding 47 (this excludes the minus sign).

Try it online!

# Answer
> 0 votes
# Braingolf, 2 bytes

```
dl

```

### Explaination:

```
dl
    Implicit input from command-line args to stack
d   Pop last item from stack, split it into digits, and push each digit to the stack
 l  Push length of stack to the end of the stack
    Implicit output of last item on stack

```

# Answer
> 0 votes
# Brain-Flak, 48 + 3 ( `-a`) = 51 bytes

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

```

Try it online!

# Answer
> 0 votes
# C#, 28 bytes

```
s=>s.Replace("-","").Length;

```

# Answer
> 0 votes
# C#, 24 bytes

```
n=>$"{n>0?n:-n}".Length;

```

Inspired from @DomHastings answer.

# Answer
> 0 votes
# Chaincode, 5 bytes

```
pqL_+

```

## Explanation

```
pqL_+ print(
    +   succ(
   _      floor(
  L        log_10(
pq           abs(
               input())))))

```

# Answer
> 0 votes
# C, 43 bytes

```
f(char*s){printf("%d",strlen(s)-(*s==45));}

```

Try it online

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

```
CREATE PROC l @ BIGINT AS PRINT LEN(@)

```

Usage:

```
EXECUTE l @ = 9999999999

```

# Answer
> 0 votes
# Lua, 26 bytes

Replaces all occurrences of `'-'` with the empty string `''` and get length with `#`.

```
print(#(...):gsub('-',''))

```

Try it online!

# Answer
> 0 votes
# Perl 5, 9 bytes + 3 for -F flag=12 bytes

```
say@F-/-/

```

Run like `perl -F -E 'say@F-/-/'`. Takes a single number from stdin without a trailing newline. Can add the `-l` flag at the cost of an extra byte if you would rather have it accept a trailing newline.

The `-F` flag auto splits stdin into the array `@F`. In scalar context, `@F` evaluates to the length of the array, which is the number of characters in `$_` (which comes from stdin). `/-/` in a numerical context evaluates to 1 if `$_` has a minus sign in it or 0 if `$_` does not have a minus sign in it, so `@F-/-/` evaluates to the number of non-minus sign characters (i.e. the number of digit characters) read from stdin.

# Answer
> 0 votes
# C, ~~71~~ 38 bytes

* **-33 bytes** *FelipeNardiBatista*

**Try Online**

```
f(char*t){return*t?(*t>'-')+f(t+1):0;}

```

# Answer
> 0 votes
# Swift, 138 bytes

You would think there would be an easier way to do this.

```
import Foundation;var d:(String)->Int={return $0.trimmingCharacters(in:CharacterSet(charactersIn:"0123456789").inverted).characters.count}

```

You can try it here

Un-golfed:

```
import Foundation // Import the Foundation module

var d:(String)->Int={ // Create a closure that takes in a String and returns an Int

    return // Return the following

    $0.trimmingCharacters(in:  // Removes all characters in the following CharacterSet

        CharacterSet(charactersIn:"0123456789").inverted // Create a CharacterSet with all characters that are not digits

    ).characters.count // Get the length of the resulting String
}

```

# Answer
> 0 votes
# Axiom, 23 Bytes

```
f(x)==#(abs(x)::String)

```

# Answer
> 0 votes
# Desmos, 31 bytes

```
g=abs(a)
f(a)=floor(log(g+0^g))

```

Try it on Desmos!

# Answer
> 0 votes
# Batch, 101 bytes

```
@set/pi=
@set o=-1&if %i:~,1%==- set o=-2
:l
@set/ao+=1&if %i%. neq . set i=%i:~,-1%&goto:l
@echo %o%

```

---

### 89 bytes

```
@set/pi=
@if %i% lss 0 set/ai=-%i%
:l
@set/ao+=1&if %i% gtr 9 set/ai/=10&goto:l
@echo %o%

```

Only works for 32-bit numbers.

# Answer
> 0 votes
# MathGolf, 2 bytes

```
±£

```

Input as integers.

Try it online.

I'm actually surprised builtin `£` works on integers. I was expecting I would need an explicit cast, since that's the case with a lot of MathGolf's builtins.

**Explanation:**

```
±   # Get the absolute value of the (implicit) input-integer
 £  # Pop and get the length of this integer
    # (after which the entire stack is output implicitly as result)

```

# Answer
> 0 votes
# Japt, 2 bytes

```
ìl

```

Try it

```
ìl     :Implicit input of integer
ì      :Convert to digit array
 l     :Length

```

# Answer
> 0 votes
# Thunno 2, 2 bytes

```
Al

```

Attempt This Online!

`l`ength of the `A`bsolute value of the implicit input.

---
Tags: code-golf, number, integer
---