Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:17:02+00:00 2026-05-23T01:17:02+00:00

hi everyone I’m here again, this week I got this Homework: I should find

  • 0

hi everyone I’m here again, this week I got this Homework:

I should find all the numbers between 10 and 10000 which has property like the following example:

89 = 8^1 + 9^2
2427 = 2^1 + 4^2 + 2^3 + 7^4 = 2 + 16 + 8 + 2401

I have this in Haskell implemented, and it works just fine(I think) and return a List like this:

[89,135,175,518,598,1306,1676,2427]

and then I tried to write it in Prolog(as required too) like the following:

num(0).
num(1).
num(2).
num(3).
num(4).
num(5).
num(6).
num(7).
num(8).
num(9).

allNarc(X):- num(A),num(B),num(C),num(D),
             X = A*1000+B*100+C*10+D,Y = A**1+B**2+C**3+D**4,
             X =:= Y,X>10.
allNarc(X):- num(B),num(C),num(D),
             X = B*100+C*10+D,Y = B**1+C**2+D**3,
             X =:= Y,X>10.
allNarc(X):- num(C),num(D),
             X = C*10+D,Y = C**1+D**2,
             X =:= Y,X>10.

the result is something like this:

?- allNarc(X).
X = 1*1000+3*100+0*10+6 ;
X = 1*1000+6*100+7*10+6 ;
X = 2*1000+4*100+2*10+7 ;
X = 0*100+4*10+3 ;    <- 43
X = 0*100+6*10+3 ;    <- 63
X = 1*100+3*10+5 ;
X = 1*100+7*10+5 ;
X = 5*100+1*10+8 ;
X = 5*100+9*10+8 ;
X = 8*10+9 ;
false.

clearly 43 and 64 should not belong to this group and the result is just ugly, can anyone help me to get output like the result in my Haskell implementation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:17:03+00:00Added an answer on May 23, 2026 at 1:17 am

    Two points.

    1. when you say X = you are unifying the left and right sides of =. If you want X to be a number equal to evaluating the expression, use X is <expression here> .
    2. you want to prevent a zero in the first position: num(A), A \= 0, num(B), ...

    After making those changes I get:

    ?- allNarc(X).
    X = 1306 ? ;
    X = 1676 ? ;
    X = 2427 ? ;
    X = 135 ? ;
    X = 175 ? ;
    X = 518 ? ;
    X = 598 ? ;
    X = 89 ? ;
    no
    

    You could also use bagof to collect the values. e.g. bagof(X,allNarc(X),Narcs). Narcs is then a list of your values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

everyone. I'm new here and this is my first post. I'm creating a simple
everyone I got problem here I need to update a plist data in a
everyone! I couldn't find a tutorial explaining the right way to code this. I
Everyone here should know the 'or' statemens, usually glued to an die() command: $foo
everyone, i have no idea why this doesn't work hopefully someone here can help
Everyone has this huge massively parallelized supercomputer on their desktop in the form of
Everyone is familiar with this functionality. If you open up the the outlook address
Everyone uses source-code control to manage versions (right?) and this provides some level of
everyone. I know this is a far treated subject, but I've looked everywhere and
everyone. Here is a small VBA (Excel) function that i wrote, full of MsgBoxes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.