Greetings,
This is my first post here so I would like to greet you all.
I started learning prolog and I must admit I'm having problems since its a totally different idea of programming, totally different from imperative type of thinking.
Here is my idea, actually i made an example i would like to solve in order to improve my knowledge.
If I'm given a number X, X>10 i would like to split its digits and store them in a list.
Example:
digits_in_list([],153,X).
X=[1,5,3].
I wrote some predicate but since I lack understanding how precisely prolog recursion works i cant menage to solve this.
My predicate:
add(X,[],[X]).
add(X,L,[X|L]).
digits_in_list([],X,[X]): -X<10.
digits_in_list([],X,L): -X1 is X mod 10,add(X1,L,Y),X is X //10.
This is my first post here so I would like to greet you all.
I started learning prolog and I must admit I'm having problems since its a totally different idea of programming, totally different from imperative type of thinking.
Here is my idea, actually i made an example i would like to solve in order to improve my knowledge.
If I'm given a number X, X>10 i would like to split its digits and store them in a list.
Example:
digits_in_list([],153,X).
X=[1,5,3].
I wrote some predicate but since I lack understanding how precisely prolog recursion works i cant menage to solve this.
My predicate:
add(X,[],[X]).
add(X,L,[X|L]).
digits_in_list([],X,[X]): -X<10.
digits_in_list([],X,L): -X1 is X mod 10,add(X1,L,Y),X is X //10.