Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't want to give a complete, working solution to a homework problem, but I'll describe in words how I would proceed from the code you've got right now. Right now your <code>increasing</code> and <code>decreasing</code> predicates test the entire list. By your definition, though, a hill is neither entirely increasing nor entirely decreasing. I would modify these predicates to have two arguments instead of one. The additional argument would be bound to the tail of the list which is not does not satisfy the increasing/decreasing criteria. Then, I'd modify hill slightly to use the new argument of <code>increasing</code> to test decreasingness not of the entire list, but of the portion after the initial increasing subsequence. Finally, I would use the new argument of <code>decreasing</code> to verify that there are no non-decreasing elements after the decreasing subsequence.</p> <p>If you need better hints, or if I seem to be talking nonsense (quite possible as I'm not that good with Prolog), just let me know and I'll try to clarify more.</p> <p><strong>Edit based on OP's comments:</strong> Alright, let's try something else. <code>L</code> is a hill if and only if <code>L</code> is a list of at least two monotone increasing elements ending with some element <code>M</code>, followed by a list of at least one monotone decreasing element starting with some element <code>N</code>, where <code>N &lt; M</code>. Can you translate that description to Prolog clauses?</p> <p><strong>Edit take two (SPOILER WARNING)</strong>:</p> <hr> <p>In your revised code, drop these three predicates: <code>increasing([]).</code>, <code>hill([]).</code>, and <code>hill(List) :- decreasing(List).</code>. This will almost give you a solution, but it will still fail, e.g. on <code>[3, 2, 1]</code>. Fixing this should be fairly easy, though.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload