I thought the following for the userRPL but I do believe other calculators / programming modes would fit too.

The challenges are not so difficult to be solved, but are difficult to be solved quickly for fairly large list (100+ elements). Of course for sysRPL or other calculators the size where things needs to be optimized changes, propose one.

Feel free to pick any of the challenges, or even none . At least I will try to solve them slowly.

userRPL reference: it is assumed that the the minimum size of the input list adapts to fit the challenge, but it is never lower than 100.

#1
Input: a list of 3s and/or 5s

Output: the input list, if 3s and 5s as alternated in the input list. Otherwise the input list followed by "invalid".

#10 (similar to #6 actually)
input: given a list of positive integers.
output: verify that the input list has exactly N times the integer N when N is in the list. Produce the list if yes, otherwise "invalid"

#12 (Han saw that is similar to the #2, so feel free to pick one)
input: given a list of 3s and/or 5s.
output: transform a 3 in a 5 and a 5 in a 3.

Example(s):
{ 3 3 3 3 5 3 } -> { 5 5 5 5 3 5 }

#13 (thanks Han for the observations)
input: given a list of positive integers.
output: verify that the list is made up by the repetition of a sublist (the smaller generating sublist). Of course the case that the generating sublist is equal to the entire list is not interesting. Another point is that a sublist is generated by consecutive elements of the list, and we do not consider rotations. For example using the generating sublist { 1 2 3 } it is not allowed to produce this { 3 1 2 3 1 2 3 1 2 } . So necessarily the sub list if existing, starts from the head of the main list.
Return the number of times the generating sublist appears, "invalid" otherwise.

#14 (once again, thanks Han)
input: given a list of positive integers between 1 and 9 with __one__ 0.
(Han saw that if we do not limit the integers the chances to go in overflow are high. With integers between 1 and 9 one has still the chance to go in overflow, but not so easy)
output: given the max value in the list, say M. Compute the value of the part of the list before 0, interpreted as number in base (M+1), and then the value of the part of the list after 0 as number in base (M+1). Return the difference in base 10 as list of digits. Note that one has to multiply the digits by the proper power of 10, therefore is the difference is -1111 the digits are { -1 -1 -1 -1}

#15
input: given a list of positive integers with __one__ 0.
output: given the max value in the list, say M. Compute the value of the part of the list before 0, interpreted as number in base (M+1), and then the value of the part of the list after 0 as number in base (M+1). Return the sum, but as a list representing the number in base M+1.
{ 1 2 3 0 1 2 } -> {1 1 1} (base 4)
{ 3 4 2 1 0 5 6 7 5} -> { 1 1 3 1 6 } (base 8)

#16
input: numbers of this challenge as element of a list so 0882 is { 0 8 8 2}
- find a multiple of 117 that has the digits 0882
- find a prime number that has the digits 1 3 4
- find a cube of an integer that has the digits 6 4 0 9

output: The answers.

#17 (thanks for the note David)
input: a list of 4 positive integers
output: all the permutations of the list, In list form or in number, except the initial one.
For example { 1 2 3 4 } a permutation is { 2 3 4 1} or 2341

#18
input: all the list between { 1 0 0 0 } and { 9 9 9 9 } (list of digits between 1000 and 9999)
output: compute all the middle square sequences with seeds of 4 digits (see here ), stopping a sequence if the new "seed" is equal to the old one or if the sequence is longer than 10000 steps.

#18.1
Bonus of the #18 . Like the #18 but a lookup table for computations, when possible.

#19
input: considering lists as collection of digits in base 10 for integers (so no decimals, also leading zeroes are allowed)
output: given two lists, representing two numbers, produce:
addition
subtraction (by convention, the subtraction puts a minus sign on all the digits)
multiplication
integer division
(positive integer) power.

#20
(variant of this)
Input: a list of sublists. Every sublist is made out of 3 elements { A B C }.
A identifies a point (or a node on a graph), B identifies another point different from A, C identifies the connection between those two points. the nodes are identified by positive integers. The minimum positive integer for a node is 1, the maximum positive integer for a node is not greater than the square root of the size of the list in input. So if the list is long X elements (sublists) the maximum node can have an index that is 2*sqrt(X) rounded to the next integer.
A connection can be of type 1, 2 or 3. (handy numbers because those numbers can be derived from one another, like 1 + 2 = 3)
Type 1 allows only the goods of type 1 to pass, type 2 allows only the goods of type 2 to pass, type 3 allows both goods of type 1 and 2 to pass.
A sublist { A B C } is different from { B A C } it means that the graph is a directed graph.
Information may be duplicated, that is: { A B C} may appear multiple times in the input, of course the information contained in it counts only once. It may also happen that there exist { A B 1}, { A B 2} and { A B 3} in the list (multiple times), of course the higher information will be consider. This means that { A B 1 } and { A B 2 } can be converted to { A B 3} so all the rest is redundant. When there are { A B 1 } and { A B 3} then { A B 1 } is redundant.

Output: a list of nodes that can reach every other node in the list sending goods of type 1 or type 2. (it should be a clique in graph terms)

#21 Remove duplicates from a list
Input: a list of positive integers
output: the input, with duplicated removed, retaining relative positions of the first appearance of a number. (one can attack the simplified version first - no retain of the relative positions)

#23
Given a list of positive integers between 1 and 9.
Every element bigger than 0 can "jump" to the left or to the right of a number of positions equal to its value (of course without exceeding the limit of the list). If the number jumps in a position occupied by another number, the destination position gets incremented, while the source position gets zeroed.
Zeroes cannot be a destination. Only places with positive numbers.
The challenge is to find an algorithm that ensures that either there is a way
to end up with one position having the sum of all the numbers in the list, (printing the moves) or not.

##
due to those challenges DavidM started to create a new library in SysRPL to handle list processing, that is a great byproduct of this contest!
Moreover, although I suppose that several libraries of commands for processing lists - developed in RPL - exists and are available in public domain through forums, newsgroups, hpcalc.org, personal web sites, pdfs (see one minute marvels) and what not , I decided to be inspired at first by the commands created by David to define more challenges, even though some may be short. (I also guess that a lot of effort, unfortunately, was never shared by the authors about a lot of useful programs and knowledge)

#24 (inspired by LEQ)
Input: two lists of positive integers.
Output: report the numbers of mismatches between the two lists. That is, if the two lists have the same elements (although in different positions) it returns 0, otherwise the number of mismatching elements.

#25 (inspired by LCNT)
Input: two lists of positive integers, L1 and L2.
Output: the score computed by the following procedure.
- Given an element that is in L1 but not in L2, increment the score by the value of the element in the same position in L2. (remember L2 is not empty by the premise of the challenges). If L2 is smaller than L1. Use the position modulo the size of L2 to find a position in L2.
- Given an element that is in L2 but not L1, reduce the score by the element in L1 that is in the same position of the element in L2. If L1 is smaller than L2, use the same procedure above but to find the position in L1.
- Given an element that is both lists. Compute appearances_in(L1) - appearances_in(L2) then multiply the result by the sum of the elements in the positions of the occurrences of the element, in the list where the element is most numerous, of the list that has less occurrences of the element. If one list is smaller than another, use the modulo as explained above. Then add the result to the score.

#27 (inspired by LREPL )
Input: a list of positive integers, a list of positions, a list of sublists of the same number of the list of positions
Output: the original list expanded with the sublists inserted starting from the position mentioned in the list of positions

#28 (inspired by LDST )
Input: a list of positive integers
Output: grouping those integers in two sublists that shows the closest difference in terms of sums. If more than one result is possible, return only one of them.
{ 1 2 3 4 5 6 } -> { 1 2 3 4 } { 5 6 }

Example(s):
{ 1 2 3 4 5 6 } -> { 1 2 3 4 } { 5 6 }

#28b
Input: a list of positive integers
Output: given the sum of the elements of the list, find the smallest factor that divides the sum (if the result is prime, add one to the list, and to the sum), then split the list in a number of sublists equal to this factor in a way that the sum of the differences of the sum of every sublist is minimal. If the smallest factor is bigger than the list itself (say the smaller factor is 7 and the list is only size 6), then report it to the user and reject the task. If more than one result is possible, return only one of them.

#29 (inspired by rolling a dice K times and finding repetitions)
Input: a list of positive integers L1, a second list of positive integers L2.
Output: find all the cases the list L2 appears in the list L1 returning the first index of a match.

#30 (inspired by rolling a dice K times and doing statistics)
Input: two lists of positive integers, L1 and L2.
Output: the elements of L2 have a relationship with the elements of L1. We want to keep it and still order L2. Sothe poit is that the element L1j is related to the element L2j. Therefore we want L2 sorted, in ascending order. And L1 sorted as well to keep the relationship valid.

#31 frequencies
input: a list of positive integers L1
output: two lists (that could be also two columns of a matrix) L2 and L3. L2 is like L1 but with elements sorted and duplicates removed. L3 is the list that contains the occurrences of the elements of L2 in L1, obviously with corresponding positions

examples:
{ 2 3 2 3 1 2 } -> { 1 2 3 } { 1 3 2 }

#32 multiple GET
input: two lists of positive integers L1 and L2. L2 is the list of positions that we want to extract from L1 (note, positions can re repeated). Values in L2 cannot exceed the size of L1 of course.
output: the list of the elements that we want to extract

examples:
{ 5 4 3 2 1 } { 1 2 3 1 1 1 } -> { 5 4 3 5 5 5 }

#33 from list to balanced binary tree
(actually in #20 one could need to move from a list of connections to a list of lists, here we do the contrary).
input: a list of positive integers
output: a list of connections that represent a balanced binary tree. A connection is a sublist { S D } where S is the number of the source node, D is the number of the destination node. The root node is defined by the { 0 D } since zero is not belonging to the input list.

Example(s):
{ 1 2 3} -> { { 0 2 } { 2 1 } { 2 3 } }

#34 from list to search balanced binary tree
input: a list of positive integers (no duplicates. For that check the #20 or make a variant of this that is a bit more complicated)
output: a list of connections that represent a search binary tree. A connection is a sublist { S D } where S is the number of the source node, D is the number of the destination node. The root node is defined by the { 0 D } since zero is not belonging to the input list.

Example(s):
{ 1 2 3} -> { { 0 2 } { 2 1 } { 2 3 } }

#35 check if balanced binary tree
input: a list containing sublists of 2 elements like { {S1 D1} {S2 D2} .. {SN DN} } . A connection is a sublist { S D } where S is the number of the source node, D is the number of the destination node. The root node is defined by the { 0 D }. The input does not have duplicates, so { Sx Dx } appears only once (if you want to deal with duplicates, the #20 is there for you). Still it may be that the nodes reported are not even a tree, like { { 1 2} { 3 4 } { 5 6 } } Those nodes are not connected at all.
output: verify that the list represents a balanced binary tree (reporting 0 if not and 1 if yes). Bonus: reporting the height. Possible variant to make it easier: all the leaves tends to be completed on the left branches . That is, between two branches, if there are not enough nodes left, the left branch is filled first, then the right.

Example(s):
{ { 0 2 } { 2 1 } { 2 3 } } -> 1 "height":1

#36 return all the positions of sublists containing a given element
(stumbled while thinking about #35)
input: a list L! containing only sublists with positive integers (but no further sublists) and a positive integer
output: the positions of sublists in L1 containing the given integer.

#37 Possible non conflicting match day pairings (needed for tournament simulations)
Input: a list of positive integers indicating teams , so like {1 2 3 4} (4 teams). the list has size multiple of 2.
Output: all the possible match day pairings. That is: every match day is a list of sublists in the forum {A B} where A and B are the number of two teams, and the team A appears only in one pairing as well as the team B. All the teams appear in the list of pairings for one day. The order of pairings does not matter, {A B} and {B A} are the same (it is not considered home and away).

#37b Possible non conflicting match day pairings picking the one having the smallest sum of differences between opponents
Input: a list of positive integers indicating teams , so like {1 2 3 4} (4 teams). the list has size multiple of 2. And a list of scores for each team, like { 0 2 1 5} (team4 has 5 points, team 3 only 1, team 2 two points, team 1 has no points).
Output: like the #37, but the program has to report only those match days that ensure that the pairings have the smallest total sum in terms of points difference between paired team.

#37c (variant of #37 suggested by pdo)
Like the 37, just instead of generating all the solutions, being able to generate a single solution with a proper input (input defined by the author of the solution). Plus the program should be able to generate all the solutions (no duplicates) given a range of inputs well defined. Caveat: the input cannot be the solution itself or a translation/compression of it in some other representation.

#38 (generating all the possible calendars of tournaments)
So you have solved #37 or #37c . Now we want to find all the possible calendars. That is:
- given N teams (even)
- A calendar is a collection of match days (see #37) that ensure that every team is paired against all the others just once (so in the collection there are N-1 match days).
- since the space of solution may be too large. The output is: given a specific input (defined by the author of the solution) all the match days in a valid calendar is returned. Plus the solution should ensure that all the calendars are returned (with no duplicates) if the program receives inputs from a well defined range. Caveat: the input cannot be the solution itself or a translation/compression of it in some other representation.

#39 Increasing/decreasing a value in a list (of integers or reals)
Input:
L3: a list of reals or integers (not mixed)
L2: the position to change
L1: the increase/decrease
Output: the list with the increment/decrement

#41 monotonic sum
Input: list of numbers.
output: increasing the sum of the elements sequentially. (like a sort of summation)

{ 34 7 92 5 } -> { 34 41 133 138 }

#42 the change-in-coins machine
Inspired from http://www.hpmuseum.org/forum/thread-3840.html
Input: an integer. Not too big (say, smaller than 1 million).
output: the top 5 combinations of the factors {1,2,5,10,20,50,100,200} in terms of smaller coins number. It is an optimization process and it is known that the greedy algorithms do not always work to find the smallest amount of coins to return, but the challenge here is to return the top5, not only the top1.
Note, if there are multiple combinations with the same amount of coins, say:
{50 20 10 10 10}
{50 20 20 5 5}
{20 20 20 20 20}
One can add the flavour that the one most preferred are the one that has the most of the same coins (to stack them nicely). In other words, {20 20 20 20 20} is the best one, then {50 20 10 10 10} then {50 20 20 5 5}.
The converse flavour is also true. To have variety in the pocket, so one can buy things without getting change back, one can give back the combination with the most variety first, so {50 20 20 5 5}, then {50 20 10 10 10} then {20 20 20 20 20}.

#42.1 the change-in-coins machine generic
Like the #42 only the factors composition is also given in input. So.
Input: an integer. Not too big (say, smaller than 1 million). Plus a list of positive integers (each different from the other) that we name as inputFactors.
output: the top 5 combinations of the inputFactors in terms of smaller coins number.

#43 This is ultra huge, long and difficult (but I did not want to lose the idea)
Seeing numbers as list of digits, implement addition, subtraction, division, multiplication and all the other operations to get really large results, although slowly.
One can do it as well with strings.
Inspiration: http://www.hpmuseum.org/forum/thread-10339.html

--

Every challenge has the following variants.

Variant type a
Solving the challenge processing the list with list operations (built in, from libraries like GoferList, self made, whatever) but not built "ad hoc" for the challenge. This to avoid to transform the list in stack elements, vectors, matrix or whatever within the main program.
Transforming a list is allowed only in functions to process lists, that should be created for generic lists, like a list of positive integers, and not for particular lists coming from this challenge (the generalized version may fit the particular case through clever inputs).
Of course if one wants to use the stack as variable space is ok (like duplicating the input list a couple of times), the point is that the list should not be "exploded/transformed in a non-list" to be processed.

Variant type b
You can transform the list in another container object (vector, matrix, list of lists), but still avoiding to use pure stack operations to process it. (well aside from little stack actions , like positioning inputs for a command for example "pos varList SWAP GET")

Variant type c
Do whatever you like to solve the problem.

edit: after solving some challenges (at first I just adapted them from the game manufactoria) I have to say that some are pretty pleasant.

In #4, it is not clear if the resulting list should be expanding in the event that the "addition" causes a carry on the most significant digit. For example, should { 1 1 1 } result in { 1 0 0 0 } or { 0 0 0 } ?

(04-20-2017 02:21 PM)Han Wrote: In #4, it is not clear if the resulting list should be expanding in the event that the "addition" causes a carry on the most significant digit. For example, should { 1 1 1 } result in { 1 0 0 0 } or { 0 0 0 } ?

(04-20-2017 02:21 PM)Han Wrote: In #4, it is not clear if the resulting list should be expanding in the event that the "addition" causes a carry on the most significant digit. For example, should { 1 1 1 } result in { 1 0 0 0 } or { 0 0 0 } ?

nice catch. {1 0 0 0} I fix it, fixed.

Additional question: should the list be of the exact size as the input if no carry happens? This is important because the lazy approach would simply always return a list whose size is one larger than that of the input.

EDIT: More comments:

#12 and #2 do not seem all that different

#14 could easily run into overflow problems if your list is a minimum of 100 elements; did you mean to return the number as a list of digits in base 10?

(04-20-2017 02:35 PM)Han Wrote: Additional question: should the list be of the exact size as the input if no carry happens? This is important because the lazy approach would simply always return a list whose size is one larger than that of the input.

yes. I thought to put your observation in the main post, but there are already examples showing this.

Quote:EDIT: More comments:

#12 and #2 do not seem all that different

True, so I put a note on the #12.

Quote:#14 could easily run into overflow problems if your list is a minimum of 100 elements; did you mean to return the number as a list of digits in base 10?

No I did not thought about the overflow. You are right. I put a cap on the positive integers, this does not strike out the problem completely but it is less easy to run in overflow.

@ han: thanks for your solutions. I will surely use them when I will pick up the prime language, that so far I had no time. Having "small and ad hoc" programs sometimes is complementary to explain some syntax.

I still have to attack the problem with the 50g making use of STREAM, DOLIST, DOSUBS or functions for lists. I don't believe it will be difficult, but to make it fast, that is difficult.

(04-20-2017 05:42 PM)pier4r Wrote: @han a question. If I read your code properly your solutions are of the variant #1 right? You are not exploding/transforming the list in other collections if I am not mistaken, correct?

Correct. The input lists are kept as lists. If the input list is modified, only its elements are modified (i.e. the input list is modified and returned as the output list). Otherwise, a newly created list is returned as the output. There is no transformation of any list into some other object type or structure.

I deviated from your instructions slightly in that when a list is "valid" I return a 1 (as opposed to the original list), although such a desired output can be easily achieved by changing the return statement to return the original list.

Many of the list processing shortcuts tend to misbehave if you provide them with lists containing no elements, 1 element, or invalid elements. For these challenges, I'm taking you at your word that the input won't include any of those situations.

I've played around with the first 12 of these so far, but am only including the first few here. My focus has been more on using the list commands than on performance considerations, and I suspect that most of what I've done could be sped up with a more brute-force approach.

As I mentioned above, I've intentionally coded these with the assumption that the input is exactly as described. In particular, I haven't done any kind of validation that the input contains the proper numbers. As such, the code is only functional for valid input, and will fail miserably with unexpected input. For that matter, it may fail with valid input, too. But it at least worked for the test cases I gave it.

I noted that the test failed almost immediately and so I started to estimate the probabilities.

If I'm not mistaken, the test will succeed - given a random list - with probability:
1/2 for 2 elements
1/4 for 3 elements
1/8 for 4 elements
1/2^(n-1) for n elements

so it is very likely to fail.
....

So after 2048 tests with a list of size 10 (output equal to 11 when valid).
1st: a lot of memory used, especially to save the results instead of deleting it accidentally.
2nd: the smaller the list, the faster the stack operations.
3rd: I got 2 elevens (list passed completely) and 7 tens (list failed at the last element)
The theory should have been 4 elevens and 8 tens, so I would assume that my code is not failing. To be sure as soon as possible I will code a function that instead of producing randomly a list of two values, will produce with a certain proportion random lists and valid lists.
4th: the average execution time per list of 10 elements was 0.26 seconds, per list of 100 elements was 1.9 seconds.

(04-21-2017 12:43 AM)DavidM Wrote: Many of the list processing shortcuts tend to misbehave if you provide them with lists containing no elements, 1 element, or invalid elements. For these challenges, I'm taking you at your word that the input won't include any of those situations.

Yes, I wanted to avoid annoying corner cases. Just a straight processing. I will have to compare your code with mine, your is way more compact. If you want to contribute in the comparison you are welcomed.

Oh, I just understood what your first challenge is doing (compare the nth element with the nth-1 element , I'm not sure about the last element ). That's a beauty! Asap I will compare speed (and results).

Instead someone with a prime may compare the code between han and didier, they do not look the same.

"verify that the list is made up by two identical (also the order) sublists. Return the number of sublists if valid, "invalid" otherwise"

If the sublists are identical then wouldn't the original list simply be generated by a single sublist? What is the significance of having two identical sublists? Also, should the program always return the largest proper sublist that generates the original list?

Han, nice catch again. First the "two sublists" is an error, should not have been there. One should identify the smaller generating sublist, that is not valid if the list is equal to the entire sublist. I mean if one has { 3 3 3 4} one could claim that the generating sublist is {3 3 3 4} and that's not interesting.

(04-21-2017 02:14 PM)pier4r Wrote: Han, nice catch again. First the "two sublists" is an error, should not have been there. One should identify the smaller generating sublist, that is not valid if the list is equal to the entire sublist. I mean if one has { 3 3 3 4} one could claim that the generating sublist is {3 3 3 4} and that's not interesting.

I will fix the main post as soon as I am with a computer.

Also, another comment on #14 -- are you sure you want to be using lists of size 100 or more (for the input) and requiring the output be an integer? If the list size is 100 or more, it may be better to return the result as a list of digits (again due to overflow). Limiting the integers to a max value of 9 only addresses one of the overflow issues. The other issue is from a large list with 0 being approximately close toward either end of the list.

Han, yes you convinced me. Actually I wanted to use that problem to push the boundaries of the math environment, handling big integers. But that's ok nevertheless. So changed the statements. Any further observation is welcomed.

Outclassed!
Let's see for the next challenges if I can step up the solution. Furthermore the solution of david are very quick. I wonder if working with the stack could be faster or just be barely faster.

PS: I will compare more RPL based results if those appears during those days. Otherwise someone else has to do it.