A286845 Every 3-digit number 'a' such that there exist two other 3-digit numbers, 'b' and 'c', such that a - b = c, and a,b,c collectively use every digit 1-9 exactly once.
459, 468, 486, 495, 549, 567, 576, 594, 639, 648, 657, 675, 693, 729, 738, 783, 792, 819, 837, 846, 864, 873, 891, 918, 927, 936, 945, 954, 963, 972, 981
Offset: 1
Programs
-
Java
import java.util.*; public class GenerateSequence {public static void main(String[] args) { Set
seq = new TreeSet (); for (long i = 987654321l; i > 123456789; i--) {Set set = new HashSet (); String number = Long.toString(i); if (!(number.contains("0"))) {for (int n = 0; n < 9; n++){set.add(number.charAt(n));} if (set.size() == 9) { if (Integer.valueOf(number.substring(0, 3)) - Integer.valueOf(number.substring(3, 6)) == Integer.valueOf(number.substring(6, 9))) { seq.add(Integer.valueOf(number.substring(0, 3)));} } } System.out.println(seq); } } -
Mathematica
With[{s = Select[Range[#/9, #] &[10^3 - 1], DigitCount[#, 10, 0] == 0 &]}, Select[s, Function[n, AnyTrue[s, Function[k, And[n - k > 0, FreeQ[#, i_ /; i == 0], Length@ # == 9] &@ Union@ Apply[Join, IntegerDigits@ {n, k, n - k}]]]]]] (* Michael De Vlieger, Aug 01 2017 *)
Comments