容易记住但理论上不易制作的数字
您面临的挑战是用任何一种语言生成符合以下条件的统一随机数的程序/功能:
长度为5位数字
有两个单独的重复数字对
一组重复的数字位于开头或结尾,并且数字彼此相邻
奇数被另一对数字包围
两个数字对和另一个数字应该都是唯一的
您的程序可以自行决定是否支持带前导零的数字。如果支持前导零,则必须将其包括在输出中:06088,而不是6088。如果不支持前导零,则根本不应生成诸如06088的数字。
测试用例
接受的输出:
55373 55494 67611 61633 09033 99757 95944 22808 65622 22161
不接受的输出:
55555 77787 85855 12345 99233 12131 abcde 5033
在此pastebin链接中可以找到更多可接受的测试用例。
这些是用这个python程序制作的:
随机导入
对于我在范围(100)中:
如果random.randint(0,100)> = 50:#将对在开始时接触如果为true
temp = []#工作数组
temp.append(random.randint(0,9))#附加随机数字
temp.append(temp [0])#再次追加相同的数字
x = random.randint(0,9)
而x == temp [0]:
x = random.randint(0,9)
temp.append(x)#附加另一个唯一数字
y = random.randint(0,9)
而y == temp [0]或y == temp [2]:
y = random.randint(0,9)
temp.append(y)#附加另一个唯一数字,以及前一个唯一数字
temp.append(x)
否则:#在末尾放置触摸对
temp = []#工作数组
temp.append(random.randint(0,9))#附加随机数字
#虽然不唯一,请重试
x = random.randint(0,9)
而x == temp [0]:
x = random.randint(0,9)
temp.append(x)#附加另一个唯一数字
temp.append(temp [0])#再次追加相同的第0位数字
y = random.randint(0,9)
而y == temp [0]或y == temp [1]:
y = random.randint(0,9)
temp.append(y)#追加另一个唯一数字两次
临时附加(y)
tempstr =“”
对我而言:
tempstr + = str(i)
打印模板
这是代码高尔夫球,因此最短答案以字节为单位!
random并非统一表示