-2

I want to write a prolog program that needs a number to stay between 2 other numbers but to not have a specific number as his neighbour.

For exemple i have the numbers 1,2,3,4,5. I want for number 5 to stay between any other number except 4.

How can i do that?

false
  • 10,264
  • 13
  • 101
  • 209
Lame Fanello
  • 545
  • 1
  • 6
  • 15
  • You need to add more information. How does the predicate should look like? In the example you give `1,2,3,4,5` - should this be a list? Or just an interval? – false Apr 19 '17 at 15:00
  • It should be a list. I know that in other programs like C you need to use loop, but how can i a think like loop in prolog? – Lame Fanello Apr 20 '17 at 15:14
  • Before thinking about loops, think about how you would use it! Give an example for that first. – false Apr 20 '17 at 15:21
  • I was thinking if 'L4 = 4' and 'L5 = 5' then in prolog i would make something like 'L4 is L5 - 1 ; L4 is L5 + 1'. – Lame Fanello Apr 20 '17 at 17:41

1 Answers1

0

The solution to the problem is if 'L4 = 4' and 'L5 = 5' then in prolog i would make something like 'L4 is L5 - 2 ; L4 is L5 + 2' where L5 not(L5 = 1 ; L5 = 5). Then the compiler will show something like 1,4,2,5,3.

Lame Fanello
  • 545
  • 1
  • 6
  • 15