• Construct n strings, each with three distinct letters, chosen randomly with equal probability.

  • Print the proportion k/n where k is the number of strings such that all three characters are in ascending order. Print also those k strings.


  • The only input is n (and thus it must be a positive integer).


  • The proportion k/n must be truncated to two decimal places.

  • The strings that are in ascending order of letters.


  • The letters must come from the English alphabet.

  • You cannot print the value of k.


  • Input: 6, Output: 0.16 agh

  • Input: 1, Output: 1.00 suv

  • Input: 9, Output: 0.22 hls jqr

How to Win

  • Fewest number of bytes wins.
  • 1
    \$\begingroup\$ Just curious: Why do you keep changing the examples? They are examples, not test cases! The output will obviously vary from run to run for any such program. The probability of making a word with 3 distinct letters which are in ascending order is exactly 1/6, and given n, the number k is a random variable that is binomially distributed with parameters (n, 1/6). The expected value for k is exactly n/6, and so the quotient k/n is just approximating 1/6. \$\endgroup\$ – Wisław Nov 10 '19 at 13:34
  • 2
    \$\begingroup\$ The problem remains that the generation of the strings is an unobservable requirement. Since there are only 6 possible orderings of three distinct characters, and only one of those is in strict ascending order, the same result would be obtained by throwing a die n times and showing the proportion of 6’s. \$\endgroup\$ – Nick Kennedy Nov 10 '19 at 13:37
  • \$\begingroup\$ @TheSimpliFire that makes them unobservable. For example, I think tio.run/##K/qfZvs/rTQvuSQzP0@jQjMtJz@/… would give the correct answers but doesn’t generate any strings. \$\endgroup\$ – Nick Kennedy Nov 10 '19 at 13:39
  • 1
    \$\begingroup\$ Outputing both a list of ascending word, and the quotient k/n seems a bit overkill. Maybe it makes sense to only output the ascending words? The quotient k/n can easily be computed from the list of ascending words. But perhaps one shouldn't change the challenge once its posted.. \$\endgroup\$ – Wisław Nov 10 '19 at 14:17
  • 4
    \$\begingroup\$ What is the point of "must be truncated to two decimal places? \$\endgroup\$ – Jonathan Allan Nov 10 '19 at 19:39

Jelly, 31 bytes

13 bytes to cater for the truncation requirement!


A monadic link which, given an integer, yields a list.

Try it online! (footer joins the list with spaces)

If (1) we remove the truncation requirement and (2) "The letters must come from the English alphabet" implies that we may choose any subset of three or more such letters then this 16 works:


Try this one (only uses A, B, and C)

If we may also avoid the unobservable creation of all the strings as part of of our code. then this 15 works:


Try this one (only uses A, B, and C, and does not create any unordered strings)

| improve this answer | |
  • \$\begingroup\$ Although it seems an unnecessary requirement, the current spec calls for truncation at 2 decimal places. \$\endgroup\$ – Nick Kennedy Nov 10 '19 at 19:32
  • \$\begingroup\$ Thanks, I didn't notice that, what an odd requirement. Updated. \$\endgroup\$ – Jonathan Allan Nov 10 '19 at 19:41
  • \$\begingroup\$ sorry to be a pain, but the official spec is to truncate rather than round. I don’t think Jelly has a built in, so (unless I’m missing something) it’s either convert to string and head, or it’s multiply by 100, floor, divide by 100. \$\endgroup\$ – Nick Kennedy Nov 10 '19 at 19:42
  • \$\begingroup\$ LOL what a mess \$\endgroup\$ – Jonathan Allan Nov 10 '19 at 19:46
  • \$\begingroup\$ Neither of those suggestions work if 1 must prodce 1.00 either. \$\endgroup\$ – Jonathan Allan Nov 10 '19 at 19:50

Japt, 25 bytes


Try it

| improve this answer | |
  • \$\begingroup\$ 20? \$\endgroup\$ – Shaggy Nov 10 '19 at 22:16
  • \$\begingroup\$ @Shaggy I never knew that you could divide an array like that, and I forgot about N. Nice! \$\endgroup\$ – Embodiment of Ignorance Nov 10 '19 at 22:21
  • \$\begingroup\$ Hooray for JS's implicit casting! \$\endgroup\$ – Shaggy Nov 10 '19 at 22:23
  • \$\begingroup\$ Wait, N.h() won't work here due to the stupid & unnecessary requirement that the result be truncated to 2 decimal places. \$\endgroup\$ – Shaggy Nov 10 '19 at 22:36
  • \$\begingroup\$ @Shaggy Fixed. It's really convenient that N.h() returns a string \$\endgroup\$ – Embodiment of Ignorance Nov 11 '19 at 1:18

Pyth, 26 bytes


Try it online!

Does what OP wants, +4 bytes due to truncation requirement.

How it works

FNQ                        - For N in Input
   K                       - K is equal to
    O.P 3                  - A random permutation length 3 of...
       G                   - The lowercase alphabet
         IqKSK             - If K is sorted
              =ZhZ         - Increment Z (which is autoinitialized to 0)
                  K        - Implicitly print K
                   ;  cZQ  - End loop, float division of Z by the input
                    .R   2 - Round to 2 decimal points

Pyth, 24 bytes


Try it online!

Cheat answer but since it only saves two bytes im not gonna bother. Also +4 due to truncation

| improve this answer | |
  • \$\begingroup\$ How does the second one cheat? The two seem to behave the same \$\endgroup\$ – Embodiment of Ignorance Nov 11 '19 at 22:10
  • \$\begingroup\$ It doesnt generate strings and check if theyre sorted; it only generates sorted strings with a 1/6 chance (which is the probability that a random string of length 3 will be sorted) \$\endgroup\$ – frank Nov 12 '19 at 17:26

Python 3, 131 bytes

It seems like having to print the string complicates the program...

from random import*
for i in range(n):

Try it online!

| improve this answer | |
  • \$\begingroup\$ 90 bytes BD \$\endgroup\$ – Dead Possum Nov 10 '19 at 13:13
  • 1
    \$\begingroup\$ Please see the (hopefully final) edit. \$\endgroup\$ – TheSimpliFire Nov 10 '19 at 14:18
  • \$\begingroup\$ Along with fixing to fit the new spec with respect to printing the strings it also needs to truncate rather than round (1->1.00, 0.166667->0.16, 0->0.00). \$\endgroup\$ – Jonathan Allan Nov 10 '19 at 20:24

J, 44 bytes


Try it online!

Note: This one does not actually construct the strings (the one below does) but its output has an identical probability distribution. I agree with Nick Kennedy on this point.

J, 48 bytes


Try it online!

Note: Because the required output does not have a homogeneous data type, J requires us to box it.

| improve this answer | |
  • \$\begingroup\$ Strings in your first submission dont seem to be in ascending order \$\endgroup\$ – frank Nov 11 '19 at 2:00
  • \$\begingroup\$ @frank ty. fixed now. \$\endgroup\$ – Jonah Nov 11 '19 at 5:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.