# 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.

• Oh, strings are allowed? What about digit arrays? – Dennis Aug 30 '16 at 3:30
• @Dennis No. Let's keep it to plain strings or plain ints. – Calvin's Hobbies Aug 30 '16 at 3:30
• If I take string input, should I handle 012? – Lynn Aug 30 '16 at 4:30
• @Lynn No. 012 would be falsy but you can assume it is not input. – Calvin's Hobbies Aug 30 '16 at 4:45
• @BradGilbertb2gills No. It should just satisfy the linked definition of truthy/falsy - meta.codegolf.stackexchange.com/questions/2190/… – Calvin's Hobbies Aug 30 '16 at 4:46

## 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

• Couldn't you remove a byte by making the start at 12 instead of 123? – var firstName Aug 31 '16 at 14:14
• It needs to not include 12. – xnor Aug 31 '16 at 16:02
• But we can assume it wouldn't be input? I'm confused – var firstName Aug 31 '16 at 19:00
• If you're talking about the comments, they're saying that if you take input as a string (which this is not), you can expect numbers to not have leading zeroes, so 12 will be given as "12" and not "012". – xnor Aug 31 '16 at 23:41

## Python, 24 bytes

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


Just a lot of condition chaining.

• Being able to compare a range that easily beats any language I already know. I had to look it up to see how it worked. – GuitarPicker Sep 1 '16 at 3:55
• Wow, if it wasn't for the word lambda I wouldn't have even guessed that was Python. That's horrific. – Steve Bennett May 9 '17 at 10:54

(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.

• No way! That's magic! – YSC Aug 30 '16 at 13:43

# Brachylog, 9 bytes

h:2j:12+?


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

• This is brilliant! – datagod Sep 2 '16 at 16:54

# Python 2, 25 bytes

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


Test it on Ideone.

# 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:

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

• "I don't actually know quite how my answer works" you win the internet – Leaky Nun Aug 30 '16 at 5:09
• Nope. – Leaky Nun Aug 30 '16 at 9:20
• @LeakyNun I don't believe Ascii mode works on try it online. You are going to have to get the github version. – Post Rock Garf Hunter Aug 30 '16 at 13:33
• @WheatWizard ASCII mode definitely works on TIO. You can verify this by adding 48 ('0') to the top of the stack. Leaky nun is right, the algorithm (my algorithm) is wrong, because it just checks if the sum of the differences is 2 (which works if the difference is +3 and -1). Unfortunately, both of our answers are wrong. – James Aug 30 '16 at 17:24
• @WheatWizard This answer does not appear to be valid. Try it online! (My original answer wasn't either) – James May 8 '17 at 16:55

# Brainfuck, 32 bytes

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


Try it online!

Credits to Lynn for the core of the algorithm.

# Jelly, 6 bytes

DI⁼1,1


### 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.

• 012 doesn't return false, although it doesn't actually return anything... – Jamie Barker Aug 30 '16 at 16:23
• The input has to be an integer. As far as ast.literal_eval is concerned, 012 doesn't represent an integer. – Dennis Aug 30 '16 at 16:33

# 05AB1E, 5 bytes

¥XX‚Q


Explanation

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


Try it online

• I used 2Å1 instead of XX,, just for the heck of less commands (4 instead of 5). – Erik the Outgolfer Dec 3 '16 at 11:59
• @ErikGolferエリックゴルファー: and Å is writeable on my keyboard (as opposed to ‚) which is a benefit :) – Emigna Dec 3 '16 at 13:17
• ‚ (not the , I used) doesn't have a compose-key sequence too, while Å is oA on an en-US keyboard. – Erik the Outgolfer Dec 3 '16 at 14:29

# 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

• Maybe d1=Ep4= (I haven't tested thoroughly) – Luis Mendo Aug 30 '16 at 9:53
• Or dTTX= for 5 bytes – Luis Mendo Aug 30 '16 at 10:05
• @luismendo whaaa? How does that even work? I can't find documentation on T – James Aug 30 '16 at 14:53
• T is the literal true, and F is false. Neighbouring T and F stick together, so TT is [true true], which for these purposes is equivalent to [1 1]. See section 4.3 of the spec – Luis Mendo Aug 30 '16 at 14:59

## 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?
}


# Perl 6,  35 29 24 21  19 bytes

{.chars==3&&'0123456789'.index: $_} {$_ (elem) (123,*+111...789)}
^(:+ ):\1::\1$ Outputs 1 for truthy and 0 for falsey. Try it online (First line added to allow multiple testcases to be run). # Ruby, 3230 25 + 2 = 27 bytes +2 bytes for -nl flags. Takes input on STDIN and prints true or false. p"123456789"[$_]&.size==3


See it on repl.it: https://repl.it/DBn2/2 (Click on ▶️ and then type input into the console below.)

• Your tests show 12 going to true. – xnor Aug 30 '16 at 4:51
• @xnor Oops. That'll teach me to golf after bedtime. Fixed! – Jordan Aug 30 '16 at 5:11
• I thought -a does a split, not chop? Also, what does the & do? I'm using an older Ruby which throws an error. Anyway, it works perfectly at 26 bytes without it. – xsot Aug 30 '16 at 8:26
• Oops, I meant -l, not -a. &. is the "safe navigation" operator, added in Ruby 2.3. Without it inputs like 19, which aren't substrings if "123456789", will raise a NoMethodError. – Jordan Aug 30 '16 at 12:29
• @Jordan I'm not getting an error in 2.2. Maybe it's new in 2.3 too? – xsot Aug 30 '16 at 12:50

# 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

• Try to get rid of push pop inefficiencies. I can see a bunch in your code. They look like ...)({} but vary. If you push and pop without using the value you can condense it into one thing. I can link you to a version of your code with all of these golfed out if you want. – Post Rock Garf Hunter Aug 30 '16 at 4:20
• Here is my 76 byte golf of your program. I pretty much ran my brain-flak optimizer over your code with a few custom settings. – Post Rock Garf Hunter Aug 30 '16 at 4:43
• Nope. – Leaky Nun Aug 30 '16 at 7:42

# 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.

• I don't understand the code, but the algorithm is clever so have a +1. – Cyoce Sep 4 '16 at 3:40

# 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.

# 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.
• Welcome to PPCG! You can save some bytes by dropping the curly braces and return keyword: 30 bytes – Kirill L. Mar 14 '19 at 11:57
• – ASCII-only Mar 14 '19 at 12:50
• Nice first submission! – Embodiment of Ignorance Mar 14 '19 at 15:36

# 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!

• What's the point of [>>]<? Couldn't that just be >? – James Aug 30 '16 at 5:12
• I want to veer the program into failure (by throwing it off-track) if the cell under the pointer isn't zero at that point. – Lynn Aug 30 '16 at 5:21
• 42 bytes – Leaky Nun Aug 30 '16 at 5:51
• @LeakyNun That looks completely different; feel free to post it as a separate answer – Lynn Aug 30 '16 at 6:02
• @Lynn Done. – Leaky Nun Aug 30 '16 at 6:13

# 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.

• two bytes: (n-12) and n>99 – Titus Aug 30 '16 at 7:31
• @Titus Oh, very nice, +1 to you! – WallyWest Aug 30 '16 at 7:44
• => is ES6, not ES5. – Neil Aug 30 '16 at 7:50
• I believe it was decided in meta that you didn't have to count "f=" making this 26 bytes – Charlie Wynn Aug 30 '16 at 20:53
• @WallyWest I think it's because it's not necessary to have "f=" to use the function in every case, so why assume you need it for this case? People smarted than me decided it's fine so I just go with it ;) – Charlie Wynn Aug 30 '16 at 20:58

# Excel - 625735 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)

• Doesn't N<900 save you a byte, in which case you can also use N>99 instead of LEN(N)=3. – Neil Aug 30 '16 at 7:49
• 21 bytes: =REPT(LEFT(N),3)+12=N where N is the name of the reference cell. – Engineer Toast May 8 '17 at 19:02

# 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.

# 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.

• doesn't work if number is like 2345 – Maltysen Aug 30 '16 at 3:37
• @Maltysen Fixed – Business Cat Aug 30 '16 at 12:57

# 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.

• 21 bytes: =REPT(LEFT(N),3)+12=N where N is the name of the reference cell. – Engineer Toast May 8 '17 at 18:24

# 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.)

# Perl, 18 bytes

Includes +1 for -p

Run with the input on STDIN

123.pl <<< 123


123.pl:

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


# PHP, 31 bytes

<?=($n=$_GET[n])-12==$n[0]*111;  Check if first digit of (number minus 12) is multiple of 111 ## 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


# 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}


# 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>