Dyalog's International Problem Solving Competition (Phase I) – Code Golf Edition


Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. However, this is a (common theme is manipulation of data of any type and structure, especially special handling of empty data) version of the Phase I problems – open to any language. Enjoy!


Write ten complete programs (or functions, etc.) to solve the below problems using any one language. The point is that you must select a language that is good at various tasks, as opposed to the common golfing strategy of choosing the right tool for the (single) task. You may not use one solution as subroutine in another solution, and your score is the total byte count of all ten programs together.

Passing all the test cases is sufficient to be a valid submission.

Closing Date

18 August 2016.

Related: possibility of real world prizes

If you chose to use Dyalog APL (free download), you may also want to participate in the original competition, but note that the objective there is to submit quality code – not necessarily short code. If you are a student, you can win USD 100 for Phase I. Phase II (not included here) can win you up to USD 2000 and a free trip to Scotland.

The problems

Problem 1 – Statistics - Mean

Write a program that takes a numeric array and gives the mean (average) of the array.

Test cases:

Problem 2 – Statistics - Median

Write a program that takes numeric data and gives the median of the data. The median is the number separating the higher half of the data from the lower half. The median can be found by arranging all the observations from lowest value to highest value and picking the middle one. If there is an even number of observations, then there is no single middle value; the median is then defined to be the mean of the two middle values.

Test cases:

Problem 3 – Statistics - Mode

Write a program that takes a numeric list and gives the mode, most common value, of the list. If more than one number occurs the greatest number of times, return all such numbers.

Test cases:
[2,2,1,4,3,2,5,1,2]2 or [2]

Problem 4 – Just Meshing Around

Write a program that takes strings or two numeric lists and gives the inputs shuffled into a string/list formed by alternately taking successive elements from each input. (This is known as a Faro shuffle.) The inputs do not have to be the same length. Begin with the first input.

Test cases:
'Dyalog' 'APL''DAyPaLlog'
'APL' 'Dyalog''ADPyLalog'
[1,3,5,7] [2,4,6,8][1,2,3,4,5,6,7,8]
'' 'Hello''Hello'
'Hello' '''Hello'
'' ''''

Problem 5 – You're Unique, Just Like Everyone Else

Write a program that takes a list or string and gives elements or characters that occur only once in the input.

Test cases:
'hello world''he wrd'

Problem 6 – Shorter Ones to the Front

Write a program that takes a list and sorts it by the length of each element. Note: an element of the list can be single number, in which case it must be counted as length 1.

Test cases:
[[2,4,3],[4,5],1,[7,3]][1,[4,5],[7,3],[2,4,3]] (sorting is not necessary)

Problem 7 – 3's and 5's

Write a program that takes a numeric list and returns all elements that are divisible by 3 or 5.

Test cases:
[-1,-2,-3,-4,-5,-6,-7,-8,-9,-10][-10,-9,-6,-5,-3] (sorting is not necessary)

Problem 8 – Separating Out the Negative

Write a program that takes a numeric list and gives a two element list whose first element contains the values less than 0 (zero) in the input and the second element contains all values greater than or equal to 0 (zero).

Test cases:

Problem 9 – Delimited Text

Write a program that takes two strings where the first string is delimiters in the second string. The program should give the delimited text as a list of strings.

Test cases:
',' 'comma,delimited,values'['comma','delimited','values']
' ' 'break up words'['break','up','words']
',' ','['','']
',' 'hello world'['hello world']
',' ''['']
',;' 'multi,delimited;values'['multi','delimited','values']

Order Total

Write a program which takes list of prices and a list which indicates the count ordered of each corresponding item and gives the total cost for the order.

Test cases: [2.99,4.99,1.99] [5,0,2]18.93
[2.99,4.99,1.99] [0,0,0]0
[123.00] [0]0
[2.00 0.00] [3,4]6
[] []0

I have explicit permission to post this challenge here from the original author of the competition. Feel free to verify by following the provided link and contacting the author. I gave the original competition author the link to this page within the minute I posted it, so they can check if I submit someone's answer as my own.


Posted 2016-08-10T18:04:25.337

Reputation: 37 779

Question was closed 2016-08-10T19:49:33.317

1Multi-part challenge and duplicates... – Leaky Nun – 2016-08-10T18:10:46.133

@LeakyNun The point is that you must select a language that is good at various tasks, as opposed to the common golfing strategy of choosing the right tool for the (single) task. – Adám – 2016-08-10T18:12:29.803

@LeakyNun common theme is manipulation of arrays of any type – Adám – 2016-08-10T18:13:14.930

Really? Nested array and non-array in Task 2? – Leaky Nun – 2016-08-10T18:14:07.807

@LeakyNun Yep. That's part of the challenge to handle multiple structures. – Adám – 2016-08-10T18:15:02.557

In some of your test cases, the input is not an array. Also, for at least the first couple, the expected output is 0 for an empty array, which is mathematically inaccurate, IIRC(Should be undefined, I think). – Jeremy – 2016-08-10T18:15:03.583

@Jeremy I never stated that it had to fit with mathematics. I provided the specific test cases to cover edge cases like that. – Adám – 2016-08-10T18:15:56.540

@Jeremy What would be a more appropriate term for data of any structure, of array isn't good? – Adám – 2016-08-10T18:17:03.103

@Adám I would just refer to it as numeric data. Calling [[1,2,3],[4,5]] an array is confusing – Jeremy – 2016-08-10T18:18:11.097

The consensus so far has been that multiple unrelated tasks are off-topic

– James – 2016-08-10T18:18:24.270

@Jeremy Done as you typed :-) – Adám – 2016-08-10T18:20:32.057

@DJMcMayhem As the author said in a previous comment, and in the post itself, the challenges are related by a common theme. – Rainbolt – 2016-08-10T18:22:28.357

@LeakyNun Typo. Fixed. Sorry. – Adám – 2016-08-10T18:23:40.073

I've written in an additional connection between the problems: Special handling of empty input is required in all sub-problems. – Adám – 2016-08-10T18:26:37.540

The challenges all say "Write a program..." Must each solution be a complete program (rather than, say, a function that returns an array or string)? What are the rules for input/output? – Jordan – 2016-08-10T18:26:45.043

@Jordan Write ten complete programs (or functions, etc.) – Adám – 2016-08-10T18:27:06.853

10/10 your array format that is half APL and half Python has made it useful in neither APL nor Python. – Leaky Nun – 2016-08-10T18:27:53.377

@Jordan I intentionally was not specific about input, as that is then left to the PPCG defaults, as widely discussed in meta. – Adám – 2016-08-10T18:28:01.073

@LeakyNun You want commas? – Adám – 2016-08-10T18:28:37.760

1@Adám Requiring the mean and median of [] to return 0 seems arbitrary. Something like NaN would make more sense. Also, I fail to see what the common theme to all tasks is – Luis Mendo – 2016-08-10T18:33:22.957

Each challenge is poorly specified, as a result of having a multi-part challenge. – Leaky Nun – 2016-08-10T18:33:23.437

@LeakyNun You've got commas (ouch). What's unclear? – Adám – 2016-08-10T18:34:21.010

NOTE: I've spent half an hour fixing things. I'll take a break now for an hour, and then I'll be back to answer/fix more issues. – Adám – 2016-08-10T18:36:48.710

@Adám If I wrote a list of what's unclear it would take me a day. – Leaky Nun – 2016-08-10T18:38:04.820

1@LeakyNun Not so clear that you couldn't answer... – Adám – 2016-08-10T18:38:49.320

@Adám I only aimed to pass all test-cases. – Leaky Nun – 2016-08-10T18:38:59.997

@LeakyNun I thought hard about the test cases. If you pass them, then you're fine. – Adám – 2016-08-10T18:39:36.727

1Does not make the specs clear. – Leaky Nun – 2016-08-10T18:40:37.177

@LeakyNun What if I include that? – Adám – 2016-08-10T18:44:34.557

If I create 10 different functions as my answer, would it be possible for me to share include (or its equivalent) between the functions (i.e. have them exist in the same program/file)? Or do I need to duplicate the include for each function that uses it? – Steven H. – 2016-08-10T18:48:15.310

@StevenH. They need to stand alone. – Adám – 2016-08-10T18:50:37.307

Does the mean challenge need to accept 2d arrays too? im slightly confused – downrep_nation – 2016-08-10T19:13:01.190

@downrep_nation Yes, as in the last test case. – Adám – 2016-08-10T19:36:27.963

1@Rainbolt, Adám, If there is no sort of interaction between the individual parts, a common theme is no sufficient relation to justify a multi-part challenge. For the full reasoning, see the meta post linked by DJMcMayhem. There is no good reason not to split this into multiple challenges. – Martin Ender – 2016-08-10T19:47:07.730

I'm closing this question as off-topic because it consists of multiple independent sub-challenges.

– Martin Ender – 2016-08-10T19:49:33.317

1@MartinEnder Would you suggest splitting or do you think that would just give rise to 10 closed-as-duplicates? – Adám – 2016-08-10T19:54:56.370

@Adám At a quick glance I'm pretty sure we've already done a few of them (which is exactly why these multi-part challenges are disallowed), you could check if some of them are new though and post those. – Martin Ender – 2016-08-10T19:58:09.790

FWIW; I think some of the individual challenges really deserve posting – Luis Mendo – 2016-08-10T21:35:05.300

@MartinEnder How is this?

– Adám – 2016-08-11T10:34:40.873

@LuisMendo Most are incorporated here.

– Adám – 2016-08-11T10:35:19.280



Pyth, 88 86 84 bytes

Problem 1: Mean (6 bytes)


Test suite.

Problem 2: Median (23 21 bytes)


Test suite.

Problem 3: Mode (7 bytes)


Test suite.

Problem 4: Interleave (3 bytes)


Test suite.

Problem 5: Unique (7 bytes)


Test suite.

Problem 6: Sort (6 bytes)


Test suite.

Problem 7: Divisibility (10 bytes)


Test suite.

Problem 8: Separate (10 bytes)


Test suite.

Problem 9: Split (12 bytes)


Test suite.

Problem 10: Dot-product (4 bytes)


Test suite.

Leaky Nun

Posted 2016-08-10T18:04:25.337

Reputation: 45 011