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);
}
}
Oh, strings are allowed? What about digit arrays? – Dennis – 2016-08-30T03:30:27.763
@Dennis No. Let's keep it to plain strings or plain ints. – Calvin's Hobbies – 2016-08-30T03:30:54.753
6If I take string input, should I handle
012
? – Lynn – 2016-08-30T04:30:08.440Does it have to return the same truth value? same false value? – Brad Gilbert b2gills – 2016-08-30T04:43:31.990
1@Lynn No.
012
would be falsy but you can assume it is not input. – Calvin's Hobbies – 2016-08-30T04:45:30.4331
@BradGilbertb2gills No. It should just satisfy the linked definition of truthy/falsy - http://meta.codegolf.stackexchange.com/questions/2190/interpretation-of-truthy-falsey/2194#2194
– Calvin's Hobbies – 2016-08-30T04:46:22.197