# 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? Commented Aug 30, 2016 at 3:30
• @Dennis No. Let's keep it to plain strings or plain ints. Commented Aug 30, 2016 at 3:30
• If I take string input, should I handle 012?
– lynn
Commented Aug 30, 2016 at 4:30
• @Lynn No. 012 would be falsy but you can assume it is not input. Commented Aug 30, 2016 at 4:45
• @BradGilbertb2gills No. It should just satisfy the linked definition of truthy/falsy - meta.codegolf.stackexchange.com/questions/2190/… Commented Aug 30, 2016 at 4:46

# 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> # Jelly, 5 bytes 9ṡ3Vċ  Try it online! • Yay outgolfed the Dennis with a perfectly competing answer. Commented May 9, 2017 at 11:52 # 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. # Stax, 5 bytes ╡e╦ù┌  Run and debug it # 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! • This returns Truthy for input of 1234 or 4567, etc. tio.run/… Commented Mar 13, 2019 at 22:08 • @gwaugh fixed. Thanks. Commented Mar 13, 2019 at 22:13 • you could -1 byte by changing n<1000 to n<999 (or even n<790) since the highest Truthy number is 789 Commented Mar 13, 2019 at 22:15 • @gwaugh done. Thanks again Commented Mar 13, 2019 at 22:18 • 23, same as C# Commented Mar 14, 2019 at 12:55 # 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"). # 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. # 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? # 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  # Scratch, 70 69 bytes A simple question - a simple answer. • 1 byte has been golfed away following the kind suggestion of Dlosc. #### Pseudocode: ask and wait say ((answer-12) mod 111)=0 and answer<790 and answer>99  #### Block representation: • Can you save a byte by subtracting 12 instead of 123? Commented Apr 9 at 4:58 • @DLosc yes indeed, the result will be the same. Thanks! Commented Apr 9 at 6:45 # Brain-Flak, 118 + 3 = 121 bytes ([][()()()]<>)<>({}[({})()]<>)<>({}[{}()]<>)<>(<{{}}>)<>([]){{}{(<{}>)<>({}())<>}{}([])}<>{(<{}>)<>({}[()])<>}<>({}())  Try it online! ASCII version: take code-points as input, output \x00 for falsey or \x01 for truthy. ## 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]  ## Batch, 49 bytes @for /l %%a in (123,111,789)do @if %%a==%1 echo 1  • You need @ before echo 1 Commented May 15, 2017 at 11:59 # 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. ## 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); } }  # Javascript (ES5), 47 39 bytes function(n){return(n-12)%111==0&&i<1e3}  Old solution with 47 did not work correctly. • Old one returns true for 1234 Commented Sep 2, 2016 at 8:51 # 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 • This actually returns false-positives for a lot of inputs, including any three digit number where all three digits are the same like 111. It also errors out without delivering a falsey if the initial input is less than three characters. Commented Sep 2, 2016 at 19:43 • @CallumKerr You're right, I wrote this in a hurry. Let me fix it. Commented Sep 2, 2016 at 19:46 # 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. • Link to 3d? (filler text) Commented Sep 6, 2016 at 8:53 • yeah, forgot it... Adding it now! – joH1 Commented Sep 6, 2016 at 18:33 # JavaScript (ES6), 413938 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> # Japt, 6 5 bytes %#o¥C  Try it online! • I think you can change 12 to C to save a byte Commented May 12, 2017 at 13:32 # Julia 1.0, 18 bytes n->n∈123:111:789  Try it online! # 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.

# 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


# 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


# JavaScript (Node.js), 17 bytes

n=>n==n[0]*111+12


Try it online!