English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Spiders have got 8 legs, bugs have got 6 legs. There are some animals in the box and we know that together they have got X legs. Write program for calculation number of spiders and number of bugs in the box.

(Example: If there are 30 legs, there are 3 spiders and one bug (3*8 + 1*6 = 24 + 6 = 30), or five bugs and no spider (0*8 + 5*6 = 30).
thanks.

2007-03-27 19:01:57 · 2 answers · asked by WAW 1 in Computers & Internet Programming & Design

2 answers

If you have that many bugs in your box, i would suggest a root to clean the spider webs out of your box..

2007-03-27 19:05:25 · answer #1 · answered by toymod 5 · 0 1

You definitely need few predicates/Prolog functions for that. In fact 2 will do.

main(X)
helper(6, X) and helper(4, X)

Can't help beyond that, I had enough nightmares to last me a lifetime with 2 months of Prolog.

2007-03-28 02:29:41 · answer #2 · answered by Andy T 7 · 0 0

fedest.com, questions and answers