From Wikipedia:
In mathematics, a self-descriptive number is an integer m that in a given base b is b digits long in which each digit d at position n (the most significant digit being at position 0 and the least significant at position b−1) counts how many instances of digit n are in m.
We can find this with Prolog's constraint library like so:
:- use_module(library(clpfd)).
Vs = [X0, X1, X2, X3, X4, X5, X6, X7, X8, X9],
Vs ins 0..9,
global_cardinality(Vs, [0-X0, 1-X1, 2-X2, 3-X3, 4-X4, 5-X5, 6-X6, 7-X7, 8-X8, 9-X9]),
label(Vs).
And if we want to package it in a script:
#!/opt/homebrew/bin/swipl -f -q
:- initialization main.
:- use_module(library(clpfd)).
main :-
Vs = [X0, X1, X2, X3, X4, X5, X6, X7, X8, X9],
Vs ins 0..9,
global_cardinality(Vs, [0-X0, 1-X1, 2-X2, 3-X3, 4-X4, 5-X5, 6-X6, 7-X7, 8-X8, 9-X9]),
forall(label(Vs), format("~q\n", [Vs])),
halt(0).