# Proportion of strings with ascending letters [closed]

## Challenge

• 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.

## Input

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

## Outputs

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

• The strings that are in ascending order of letters.

## Requirements

• The letters must come from the English alphabet.

• You cannot print the value of k.

## Examples

• 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.
• 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. – Wisław Nov 10 '19 at 13:34
• 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. – Nick Kennedy Nov 10 '19 at 13:37
• @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. – Nick Kennedy Nov 10 '19 at 13:39
• 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.. – Wisław Nov 10 '19 at 14:17
• What is the point of "must be truncated to two decimal places? – Jonathan Allan Nov 10 '19 at 19:39

# Jelly, 31 bytes

13 bytes to cater for the truncation requirement!

ØaẊ⁸Ð¡Ḋḣ€3ṢƑƇðL÷+⁵×ȷ2ḞṾs2j”.Ḋṭ⁸


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:

“ḃ»Ẋ⁸Ð¡⁼ƇḢ$ðL÷;⁸  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: 6ẋX€ỊƇ“ḃ»ẋðL÷;⁸  Try this one (only uses A, B, and C, and does not create any unordered strings) • Although it seems an unnecessary requirement, the current spec calls for truncation at 2 decimal places. – Nick Kennedy Nov 10 '19 at 19:32 • Thanks, I didn't notice that, what an odd requirement. Updated. – Jonathan Allan Nov 10 '19 at 19:41 • 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. – Nick Kennedy Nov 10 '19 at 19:42 • LOL what a mess – Jonathan Allan Nov 10 '19 at 19:46 • Neither of those suggestions work if 1 must prodce 1.00 either. – Jonathan Allan Nov 10 '19 at 19:50 # Japt, 25 bytes ;ÆBö3Ãf_¶ñ u»UÊ/N)h2)ú0,4  Try it • 20? – Shaggy Nov 10 '19 at 22:16 • @Shaggy I never knew that you could divide an array like that, and I forgot about N. Nice! – Embodiment of Ignorance Nov 10 '19 at 22:21 • Hooray for JS's implicit casting! – Shaggy Nov 10 '19 at 22:23 • Wait, N.h() won't work here due to the stupid & unnecessary requirement that the result be truncated to 2 decimal places. – Shaggy Nov 10 '19 at 22:36 • @Shaggy Fixed. It's really convenient that N.h() returns a string – Embodiment of Ignorance Nov 11 '19 at 1:18 # Pyth, 26 bytes FNQKO.PG3IqKSK=ZhZK;.RcZQ2  Try it online! Does what OP wants, +4 bytes due to truncation requirement. ## How it works FNQKO.PG3IqKSK=ZhZK;.RcZQ2 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 FNQI!O6=ZhZSO.PG3;.RcZQ2  Try it online! Cheat answer but since it only saves two bytes im not gonna bother. Also +4 due to truncation • How does the second one cheat? The two seem to behave the same – Embodiment of Ignorance Nov 11 '19 at 22:10 • 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) – 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* n=int(input()) o=[] a=['a','b','c'] x=0 for i in range(n): o+=[sample(a,3)] x+=a==o[-1] print('%.2f'%(x/n),o)  Try it online! • 90 bytes BD – Dead Possum Nov 10 '19 at 13:13 • Please see the (hopefully final) edit. – TheSimpliFire Nov 10 '19 at 14:18 • 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). – Jonathan Allan Nov 10 '19 at 20:24 # J, 44 bytes ((4j2":%~),@,~[:u:97+26/:~@?~]#3:)1#.0=?@$&6


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

(];~4j2":(%~#))[:<@u:"1[:(97+(-:/:~)"1#])26?~#&3


Try it online!

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

• Strings in your first submission dont seem to be in ascending order – frank Nov 11 '19 at 2:00
• @frank ty. fixed now. – Jonah Nov 11 '19 at 5:21