Solved

calculations and sums (logic or prolog)

Posted on 2001-07-05
7
185 Views
Last Modified: 2011-10-03
hi
i have a 32 long number like
32392382832738273827382715273987
and i need a code wich finds a calculation where the result is the number
i want it also as small at it can be
so dont need a calculation like

1+1+1+1+1+1+1+1+.....
i need it more like 15^20^52
please write it in prolog or in a text

0
Comment
Question by:blizz50
7 Comments
 
LVL 3

Expert Comment

by:ygal02
ID: 6255819
The simplest way (if I understood you well) will be:

3*(10^31) + 2*(10^30) + 3*(10^29) + 9*(10^28) + ... + 8*10 + 7
Total of 32 parts.
You can add every two part if you want and you'll get something like:
32*(10^30) + 39*(10^28) + ... + 87
This will end up with only 16 parts, and so on. You can combine every two parts again so you'll have only 8 parts but the coefficients will become bigger and bigger, so you can decide which one is the best for you.

Good Luck !
0
 

Author Comment

by:blizz50
ID: 6255961
nono
in your comment you get per diit 8 symbols
the 1st number 3 would be
3*(10^31) thats to much
i will show you a example
(its not 32 long)
387420489
after running the programm you get
9^9
thats 3 symbols
you understand now?
i need a programm that finds  such a calculation for any number

0
 
LVL 6

Expert Comment

by:edey
ID: 6256030
or, and I'm sorry but I just couldn't resist, in base 32392382832738273827382715273987 the answer would be simply a constant - 10

GL
Mike
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:Neutron
ID: 6258791
Since it is Prolog you will use, you need the solution that has your 32digit number as a list.

If you want to make it simple, you can make 10 predicates which have a single digit as a list Head and rest of digits are the Tail, something like this:

[0|Rest]
[1|Rest]
[2|Rest]
...
[9|Rest]

So, head unifies with a digit. You would have an accumulating parameter which is in your initial call equal to 0 (zero).
If head unifies with 7, you just multiply accumulating parameter with 10 and add 7 and make a new call with tail and 10*oldAccumulatedParameter+7 as a new accumulated value. You end your recursion when the list is empty.

calculate( [], A ).
calculate( [0|Tail], A ):-calculate( Tail, A*10 ).
calculate( [1|Tail], A ):-calculate( Tail, A*10+1 ).
calculate( [2|Tail], A ):-calculate( Tail, A*10+2 ).
...
calculate( [9|Tail], A ):-calculate( Tail, A*10+9 ).
calculate( [H|Tail], A ):-!, fail.

I'm not using Prolog so in this code above there might be some syntax errors, but since you're programming in Prolog you should see my logic out of it anyway.

'Hope this helps,
    Ntr:)
0
 
LVL 4

Expert Comment

by:Neutron
ID: 6258803
If you want to control if the number is exactly 32digit, you can add another accumulating parameter, which you would increase in each new predicate call, so it would be a digit counter.
This parameter you would also set to zero in initial call.

Greetings,
    Ntr:)
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7487613

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - PAQ'd and pts removed
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7518906
Per recommendation, points NOT refunded and question closed.

Netminder
EE Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 177
mergeTwo  challenge 13 84
groupNoAdj 7 86
C Programming - If Statement 8 72
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
A short article about a problem I had getting the GPS LocationListener working.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now