Skip to content

Instantly share code, notes, and snippets.

@dshemetov
Last active December 4, 2019 06:45
Show Gist options
  • Save dshemetov/0b50fd4c1dd9567e9c040570169cc9fc to your computer and use it in GitHub Desktop.
Save dshemetov/0b50fd4c1dd9567e9c040570169cc9fc to your computer and use it in GitHub Desktop.
(* Part 1 *)
a = 273025; b = 767253;
t = Flatten[Table[FromDigits[{i, j, k, l, m, n}],
{i, 1, 9}, {j, i, 9}, {k, j, 9},
{l, k, 9}, {m, l, 9}, {n, m, 9}]];
Length@Select[t, MemberQ[Differences@IntegerDigits[#], 0] && a <= # <= b &]
(* Part 2 *)
f[n_] := Differences@IntegerDigits[n] /. Thread[Range[2, 9] -> 1]
g[n_] := f[n][[1 ;; 2]] == {0, 1} || f[n][[-2 ;; -1]] == {1, 0} ||
AnyTrue[Partition[f[n], 3, 1], # == {1, 0, 1} &]
Length@Select[t, g[#] && a <= # <= b &]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment