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);
}
}
012
? \$\endgroup\$ – Lynn Aug 30 '16 at 4:30012
would be falsy but you can assume it is not input. \$\endgroup\$ – Calvin's Hobbies Aug 30 '16 at 4:45