Thank you

I think it's going better, or at least I'm understanding a bit more.

The problem I had was another, quicksort was sending the whole list to
compare inside comp2.
I fixed it with these:
quickp=: 3 : 0
if. 1 >: #y do. y
else.
(quickp y lesser sel e),(y equal sel e),quickp y greater sel e=.y{~?#y
end.
)
lesser=:{{1=>x comp2 each y}}
equal=:{{2=>x comp2 each y}}
greater=:{{0=>x comp2 each y}}

Now the problem is another. I can find the element inside the original
list, but I can't search inside the sorted list, or store the sorted list.

quickp pp

┌┬──┬────┬───────────┬───────────┬─────────────┬─────────────────────────────┬─────────────────────────────┬───────┬───┬─┬─────────────┬───────────────┬───┬───────┬─────────┬─────────┬─┐

││┌┐│┌──┐│┌─┬─┬─┬─┬─┐│┌─┬─┬─┬─┬─┐│┌───┬───────┐│┌─┬─────────────────────┬─┬─┐│┌─┬─────────────────────┬─┬─┐│┌───┬─┐│┌─┐│3│┌───────┬─┬─┐│┌───────┬─┬─┬─┐│┌─┐│┌─┬─┬─┐│┌─┬─┬─┬─┐│┌───────┐│9│

││││││┌┐│││1│1│3│1│1│││1│1│5│1│1│││┌─┐│┌─┬─┬─┐│││1│┌───────────────────┐│8│9│││1│┌───────────────────┐│8│9│││┌─┐│4│││2││
││┌─────┐│4│4│││┌─────┐│4│4│4│││6│││7│7│7│││7│7│7│7│││┌─┬─┬─┐││ │

││└┘││││││└─┴─┴─┴─┴─┘│└─┴─┴─┴─┴─┘│││1│││2│3│4││││ ││┌─┬───────────────┐││ │
│││ ││┌─┬───────────────┐││ │ ││││1││ ││└─┘│ │││┌─┬─┐││ │ ││││┌─┬─┐││ │ │
││└─┘│└─┴─┴─┘│└─┴─┴─┴─┘│││8│7│6│││ │

││ ││└┘││ │ ││└─┘│└─┴─┴─┘│││ │││2│┌─┬───────────┐│││ │ │││
│││2│┌─┬───────────┐│││ │ │││└─┘│ ││ │ ││││4│4│││ │ │││││4│4│││ │ │ ││ │ │
││└─┴─┴─┘││ │

││ │└──┘│ │ │└───┴───────┘││ │││ ││3│┌─┬───────┐││││ │ │││ │││
││3│┌─┬───────┐││││ │ ││└───┴─┘│ │ │││└─┴─┘││ │ ││││└─┴─┘││ │ │ ││ │ │
│└───────┘│ │

││ │ │ │ │ ││ │││ ││ ││4│┌─┬─┬─┐│││││ │ │││ │││ ││ ││4│┌─┬─┬─┐│││││ │ ││ │
│ ││└─────┘│ │ │││└─────┘│ │ │ ││ │ │ │ │ │

││ │ │ │ │ ││ │││ ││ ││ ││5│6│0││││││ │ │││ │││ ││ ││ ││5│6│7││││││ │ ││ │
│ │└───────┴─┴─┘│└───────┴─┴─┴─┘│ │ │ │ │ │

││ │ │ │ │ ││ │││ ││ ││ │└─┴─┴─┘│││││ │ │││ │││ ││ ││ │└─┴─┴─┘│││││ │ ││ │
│ │ │ │ │ │ │ │ │

││ │ │ │ │ ││ │││ ││ │└─┴───────┘││││ │ │││ │││ ││ │└─┴───────┘││││ │ ││ │
│ │ │ │ │ │ │ │ │

││ │ │ │ │ ││ │││ │└─┴───────────┘│││ │ │││ │││ │└─┴───────────┘│││ │ ││ │
│ │ │ │ │ │ │ │ │

││ │ │ │ │ ││ ││└─┴───────────────┘││ │ │││ ││└─┴───────────────┘││ │ ││ │
│ │ │ │ │ │ │ │ │

││ │ │ │ │ ││ │└───────────────────┘│ │ │││ │└───────────────────┘│ │ ││ │
│ │ │ │ │ │ │ │ │

││ │ │ │ │ │└─┴─────────────────────┴─┴─┘│└─┴─────────────────────┴─┴─┘│ │
│ │ │ │ │ │ │ │ │

└┴──┴────┴───────────┴───────────┴─────────────┴─────────────────────────────┴─────────────────────────────┴───────┴───┴─┴─────────────┴───────────────┴───┴───────┴─────────┴─────────┴─┘

sorted=:quickp pp

|domain error: comp2

| ({.tx) <{.ty

cder''

0 0

   (1+i.#pp)*2=1 a&comp2\ quickp pp
|domain error: comp2
|   ({.tx)    <{.ty

So... any idea how to continue?

Rest of my code is in
https://github.com/JaumeGreen/adventofcode/tree/master/2022/day13 mostly in
explanation, but some of the newer changes only in log.

Thanks.

Missatge de Raul Miller <rauldmil...@gmail.com> del dia dt., 13 de des.
2022 a les 20:00:

> p.s. for the tacit stack issue, you did not include your definition of
> comp2, but if it's from aoc day 13, a plausible issue is that comp2
> would be returning _1 or 1 instead of 0 or 1 (which is what that
> quicksort implementation expects).
>
> That said, when debugging stack errors on recursive functions, it can
> be handy to use $:&([echo) so that you can see where the spam where
> the recursion goes wrong.
>
> --
> Raul
>
> On Tue, Dec 13, 2022 at 1:43 PM Jaume <greenni...@gmail.com> wrote:
> >
> > Hello all
> >
> > Still here and I've done all the days in J except for day 7, But that's
> not
> > why I'm here.
> >
> > So now I've done the first part, and I have a function that is too long
> to
> > copy that does comparisons in an iterative way (I had some stack
> problems).
> > Now I'm wanting to sort the elements using this function, but I don't
> know
> > how.
> >
> > All the sorting is done using the standard comparison, all the grading is
> > numerical, the quicksort implementation in
> > https://www.jsoftware.com/help/dictionary/cif.htm (and in
> > https://code.jsoftware.com/wiki/Essays/Quicksort) is giving me an error
> > even when trying with numbers.
> >
> > sel=: 1 : 'x # ['
> >
> > quicksort=: 3 : 0
> >
> > if. 1 >: #y do. y
> >
> > else.
> >
> > (quicksort y <sel e),(y =sel e),quicksort y >sel e=.y{~?#y
> >
> > end.
> >
> > )
> >
> > quicksort 15 2 9 10 4 0 13 13 18 7
> >
> > |noun result was required: quicksort
> >
> > | x#[
> >
> > |[-0]
> >
> >
> > And the tacit version, which I hope I modified correctly, it's also
> giving
> > me a stack error.
> >
> > less=:{{x comp2 y}}
> >
> > great=:{{y comp2 x}}
> >
> > quicksort=: (($:@(less#[) , (=#[) , $:@(great#[)) ({~ ?@#)) ^: (1<#)
> >
> > quicksort pp
> >
> > |stack error: comp2
> >
> > | y comp2 x
> >
> >
> > Any idea how can I sort the elements or correct the errors I have?
> >
> > Thanks
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


-- 
The fact that an opinion has been widely held is no evidence whatever that
it is not utterly absurd. -- Bertrand Russell
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to