41
4
Numbers that are easy to remember yet theoretically not easily made
Your challenge is to make a program/function in any language that generates uniformly random numbers that fit these criteria:
Length is 5 digits
There are two separate repeated digit pairs
One set of repeated digits is at the beginning or end and the digits are next to each other
The odd number out is surrounded by the other pair of digits
The two digit pairs and the other number should all be unique
Your program may support numbers with leading zeroes or not, at your discretion. If leading zeroes are supported, they must be included in the output: 06088, not 6088. If leading zeroes are not supported, then numbers like 06088 should not be generated at all.
Test Cases
Accepted Outputs:
55373 55494 67611 61633 09033 99757 95944 22808 65622 22161
Not accepted outputs:
55555 77787 85855 12345 99233 12131 abcde 5033
More acceptable test cases can be found at this pastebin link.
These were made with this python program:
import random for i in range(100): if random.randint(0,100) >= 50: #Put pair touching at beginning if true temp = [] #working array temp.append(random.randint(0,9)) #append random digit temp.append(temp[0]) #append the same digit again x = random.randint(0,9) while x == temp[0]: x = random.randint(0,9) temp.append(x) #append another unique digit y = random.randint(0,9) while y == temp[0] or y == temp[2]: y = random.randint(0,9) temp.append(y) #append another unique digit, and the previous unique digit temp.append(x) else: #Put touching pair at end temp = [] #working array temp.append(random.randint(0,9)) #append random digit #While not unique, try again x = random.randint(0,9) while x == temp[0]: x = random.randint(0,9) temp.append(x) #append another unique digit temp.append(temp[0]) #append the same 0th digit again y = random.randint(0,9) while y == temp[0] or y == temp[1]: y = random.randint(0,9) temp.append(y) #append another unique digit twice temp.append(y) tempstr = "" for i in temp: tempstr += str(i) print tempstr
This is code-golf, so shortest answer in bytes wins!
Does every possible easy to memorize number have to be able to appear as output? Should the random choice be uniform? – Jonathan Frech – 2018-03-09T04:25:58.243
@JonathanFrech Yes and yes – drham – 2018-03-09T04:28:45.500
5I suggest "Possible outputs (probability>0)" and "Not possible outputs (probability=0)" rather than "Truthy" and "Falsy"—this seems more in line with what I think you're asking (and with the Python). – Khuldraeseth na'Barya – 2018-03-09T04:29:51.777
9Do we have to print an output like 09033 with a leading zero? – xnor – 2018-03-09T04:57:32.250
3
If the probability is uniform, can you specify that in the question. By default,
– Jo King – 2018-03-09T05:35:48.513random
does not mean uniformly so3maybe add 99233, for conveniewnce to understand – l4m2 – 2018-03-09T05:51:24.467
3Welcome to PPCG! Nice first challenge. – Jonathan Allan – 2018-03-09T13:19:09.893
@xnor, since some languages will most likely need to use numbers instead of arrays of numbers, you can decide whether or not you output numbers with leading zeroes. But do not output any numbers that are 4 or 3 in length because the zero(es) was/were chopped off – drham – 2018-03-09T15:47:23.100
@Downvoter what can I improve? – drham – 2018-03-09T21:34:48.427
"Outputs that have a pair of zeroes are not required to output the leading zero, but if omitted, make sure that you do not output something like 6088, chopping the first zero off." ... um, what? – mbomb007 – 2018-03-09T22:59:38.677
1@DLosc Yeah I'm sorry, I'm not quite sure how to word it. Your interpretation is correct. Please feel free to edit your alternate explanation in. – drham – 2018-03-09T23:49:25.033
@DLosc looks great, thanks – drham – 2018-03-10T07:08:29.083
It’s 0118-999-881-999-119-725......3 – Stan Strum – 2018-03-12T18:15:58.770