Skip to content

Instantly share code, notes, and snippets.

@trietptm
Created December 14, 2012 16:01
Show Gist options
  • Save trietptm/4286485 to your computer and use it in GitHub Desktop.
Save trietptm/4286485 to your computer and use it in GitHub Desktop.
Sum of digits of a number (in PROLOG) a simple snippet to find the sum of digits of a given number in PROLOG
sumofdigits(X, X) :- X<10.
sumofdigits(X, Y) :- X>=10, X1 is X // 10, X2 is X mod 10, sumofdigits(X1, Y1), Y is Y1 + X2.
@ZveiEliezerNir
Copy link

Thank man!
this one sure helped me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment