Help with sanp!

Create a [Snap!]! block named !1571935682024 that moves the minimum number in that list to the first position and shifts the maximum number to the last one. During this process, your program should not change the order of all the other numbers of the list. Here is an example input list !1571935696547
This is the output list !1571935702750

Program Restrictions

  1. It is a reporter block, and it returns the updated list.
  2. The only parameter of the block is a list of numbers.

This problem is a lot harder than it seems, but I think I found a solution.

EDIT- My solution does not work.

In your signature, you may have the apostrophes around the wrong a.

Oops! :blush: Thanks for catching that! I saw you took down your algorithm? Did it not work?

I think it would be best not to give people a solution to what's obviously a homework problem.

Instead, help by asking questions, starting with "what have you tried?" That will encourage people to struggle with the problem themselves before asking for help. Then, when they show you some code, ask questions to get them to think about what they're doing from a different perspective. For instance, if you were asking for help and posted that code, I'd say "Do you have to sort the list to find the largest item?" because your program does way more work than it has to.

Good point. Should I take It down?

Nah, too late. Next time...

P.S. Don't use BLOCK VARIABLES in that situation; use the SCRIPT VARIABLES block. With BLOCK VARIABLES, the second (and later) time you call the block, that variable starts with the value it had last time, instead of starting at 0 again.

Good to now. I was wondering why they had that option if there were already script variables. Maybe add that to the manual?

It's in the manual! Page 28. And it's in the index. :~)

Whoops! I was looking at an older version of the Manual I found by searching, not going through SNAP!'s website.

It didn't work, and I tried fixing it multiple times, but I still couldn't get it to work.

Umm, I'm falling behind on this thread. What doesn't work?

My sorting algorithm

Did I miss part of your message? I don't see a sorting algorithm.

By the way, the original problem is ambiguous about whether or not you're supposed to modify the original list. My instinct is not to, so I'd be inclined to write
assuming that the list items are unique.

It's not very efficient, since it traverses the list three times. But it can be tweaked to avoid that, and one of the traversals happens at primitive speed.

I edited my post after it turned out my solution did not work in some cases. Yours looks a lot better than mine!

I posted script pics of my answers to the question, but I tested them after, not before. I don't know why I didn't test them before posting.

How do you skip the first two items in a list?

Put the list in an all but first reporter in an all but first reporter.

thank you for confirming that. I wanted a block with script variables that stay the same for the next time you ask for the block.

Here is an example of block variables: