/* Electron configuration in Picat. http://codegolf.stackexchange.com/questions/37657/electron-configurations Also see https://en.wikipedia.org/w/index.php?title=Electron_shell&oldid=616749633#List_of_elements_with_electrons_per_shell Note: I skip hexdump and other golfing stuff... This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => all_configs(Config), Len = Config.length, println(len=Len), foreach(A in 1..Len) println(A=config(Config,A)) end, nl. % another approach go2 => foreach(I in 1..118) println(I=config2(I)) end, nl. config(Config,N) = [T : T in Config[N], T > 0]. all_configs(Config) => N = 7, L = new_list(N), D = [2,8,18,32,32,18,8], % the domains foreach(I in 1..N) L[I] :: 0..D[I] end, L[1] #> 0, foreach(I in 1..N-1) L[I] #= 0 #=> L[I+1] #= 0, L[I+1] #> 0 #=> L[I] #= D[I] end, Config=solve_all(L). config2(N) = X => D = [2,8,18,32,32,18,8], X = [1], I = 1, Sum = 0, while (Sum < N-1) Sum := sum(X), if X[I] == D[I] then I := I+1, X := X ++ [0] end, X[I] := X[I] + 1 end.