冰封雪舞
发表于 2018-3-25 19:11:22
塔利班 发表于 2018-3-22 21:45
又写了个又臭又长的lambda
, ,
我测试了下,貌似你这lambda分不出上边大小.
塔利班
发表于 2018-3-25 19:20:39
本帖最后由 塔利班 于 2018-3-25 19:25 编辑
冰封雪舞 发表于 2018-3-25 19:11
, ,
我测试了下,貌似你这lambda分不出上边大小.
好像是没分出来,我给的权值低了,那就10换20= =
塔利班
发表于 2018-3-25 19:30:12
冰封雪舞 发表于 2018-3-25 19:06
你这个纯属考颜值糊弄人,两个筛子仍一样的点数,按两个一样大小的筛子数值分大小,如果出现两个这种情况 ...
改了权值就对了,忘了考虑最小112和最大4,5,6情况了
冰封雪舞
发表于 2018-3-25 20:55:38
塔利班 发表于 2018-3-25 19:30
改了权值就对了,忘了考虑最小112和最大4,5,6情况了
恩,按照你这个公式,你那个权值好像只要大于12就可以了,佩服了,天才的思路,牛逼,给你点个赞。
塔利班
发表于 2018-3-25 20:58:27
冰封雪舞 发表于 2018-3-25 20:55
恩,按照你这个公式,你那个权值好像只要大于12就可以了,佩服了,天才的思路,牛逼,给你点个赞。
没有,多谢指出错误,我写了第一种,第二种极限情况在脑子里过的不全,跟大家一起学习真好,
要不带着错误就忘了,
你也挺细心的,每个人的代码都敲下,我是超级囫囵吞枣。。哎,毛毛躁躁
凌九霄
发表于 2018-3-27 16:54:29
nononoyes 发表于 2018-3-23 17:47
num= input('请输入掷骰子的次数:')
num = int(num)
list1 = []
按照题目规则,(5,5,4)应该排在(6,1,6)前面才对
凌九霄
发表于 2018-3-27 16:58:12
import itertools
import random
dicelist = list(itertools.product(range(1, 7), repeat=3))# 生成骰子全部可能的排列点数,得到顺序排列的列表
dicestatus = random.sample(dicelist, random.randint(2, 10))# 打乱秩序,模拟随机掷出骰子得到的排列
print("生成的随机骰子点数组合:")
print(dicestatus)
def tocompare(dice):
outlist = []
tlist = []
olist = []
# 查找(x,x,x)型组合
for x in dice:
if x == x == x:
outlist.append(x)
outlist.sort(reverse=True)
# 查找(x,x,y)型组合
for y in dice:
if y == y and y != y:
tlist.append(y)
tlist.sort(reverse=True)
# 不符合上面两种类型的组合
for z in dice:
if z != z:
olist.append(z)
olist.sort(key=lambda x: sum(x), reverse=True) #根据每轮点数和的大小反向排序
return outlist + tlist + olist
print("按照指定的大小规则排序:")
print(tocompare(dicestatus))
nononoyes
发表于 2018-3-27 17:44:13
凌九霄 发表于 2018-3-27 16:54
按照题目规则,(5,5,4)应该排在(6,1,6)前面才对
两个一样的,先比较两个一样的点数,如果还相同,再比较第三个的点数
Pythoner_3.21
发表于 2018-4-4 16:43:14
import random
i = 1
result=[]
same1=[]
same2=[]
same3=[]
while i <=20:
a = random.randint (1,6)
b = random.randint (1,6)
c = random.randint (1,6)
if a == b == c:
same3.append((a,b,c))
elif a == b or b == c or a == c:
same2.append((a,b,c))
else:
same1.append((a,b,c))
i += 1
same3.sort(key=lambda x:x,reverse=True)# 按照第一个元素的大小排序
for each in same3:
result.append(each)
mylist=[]
for k in range(len(same2)):
for num in same2:
if same2.count(num) == 2:
m=num
elif same2.count(num) == 1:
n=num
mylist.append()
mylist.sort(key=lambda x:x,reverse=True) #先按n的大小排序
mylist.sort(key=lambda x:x,reverse=True) # 再按m的大小排序
for each in mylist:
result.append(same2])
same1.sort(key=sum,reverse=True) # 按照元素的和的大小排序
for each in same1:
result.append(each)
print(result)
新手潘包邮
发表于 2018-5-12 14:21:00
def fun():
lst = [(4, 1, 1), (2, 2, 2), (5, 6, 1), (4, 3, 6), (2, 4, 3), (1, 1, 1),
(4, 3, 6), (6, 3, 3), (1, 3, 6), (4, 4, 3), (6, 2, 2), (1, 5, 2),
(5, 6, 6), (1, 4, 6), (2, 1, 6), (1, 3, 3), (6, 6, 5)]
lst1 = []
lst2 = []
lst3 = []
for i in lst:
if len(set(i)) == 3:
lst3.append(i)
elif len(set(i)) == 2:
lst2.append(i)
else:
lst1.append(i)
lst1 = sorted(lst1, key = lambda x: max(x), reverse = True)
def fun2(x):
if x == x or x == x:
return x
else :
return x
lst2 = sorted(lst2, key = fun2, reverse = True)
lst3 = sorted(lst3, key = sum, reverse = True)
print(lst1,lst2,lst3)
fun()
776667
发表于 2018-6-28 17:01:40
本帖最后由 776667 于 2018-6-28 17:04 编辑
from random import randint
def fun169(x):
list_dice_all = []
for i in range(x):
dice =
list_dice_all.append(tuple(dice))
list_dice_three = sorted()[::-1]
list_dice_two =
list_dice_nope =
list_dice_nope.sort(key=lambda x:sum(x),reverse=True)
list_dice_two_sorted = []
for i in range(1,7)[::-1]:
for j in range(1,7)[::-1]:
for n in list_dice_two:
if n.count(i) == 2 and n.count(j) == 1:
list_dice_two_sorted.append(n)
return list_dice_three + list_dice_two_sorted + list_dice_nope
if __name__ == '__main__':
x = input('请输入掷骰次数:')
print(fun169(int(x)))
请输入掷骰次数:30
[(5, 5, 5), (6, 6, 4), (2, 6, 6), (6, 1, 6), (5, 5, 3), (5, 5, 2), (4, 4, 3), (3, 3, 6), (3, 3, 4), (1, 1, 3), (3, 6, 4), (6, 4, 3), (6, 4, 2), (6, 1, 5), (3, 5, 4), (4, 5, 3), (2, 4, 6), (2, 3, 6), (6, 2, 3), (1, 6, 4), (6, 2, 3), (6, 3, 2), (1, 6, 3), (6, 1, 3), (2, 5, 3), (4, 3, 2), (4, 2, 3), (1, 4, 3), (1, 4, 2), (1, 2, 4)]
>>>
小木子c
发表于 2018-7-20 20:31:09
import random
list1 =
list3 = []
#生成结果列表
for i in range(8):
list2 = []
for j in range(3):
data = random.choice(list1)
list2.append(data)
list3.append(tuple(list2))
list4 = []
list5 = []
list6 = []
for each in list3:
#三个点数一样
if each == each == each:
list4.append(each)
list4.sort()
list4.reverse()
#有两个点数一样
elif each == each or each== each or each == each:
list5.append(each)
list8 = []
for each in list5:
if each == each:
list8.append(each)
elif each== each:
tup = (each,each,each)
list8.append(tup)
elif each == each:
tup = (each,each,each)
list8.append(tup)
list8.sort()
list8.reverse()
#点数都不相同
else:
list6.append(each)
dict1 = {}
Sum_list = []
list7 = []
for each in list6:
Sum = each + each + each
Sum_list.append(Sum)
dict1 = each
Sum_list.sort()
Sum_list.reverse()
for each in Sum_list:
list7.append(dict1)
print(list4+list8+list7)
子沙
发表于 2018-9-4 17:58:14
def fun_169(m):
list1=[]
list2=[]
list3=[]
for i in m:
if i==i and i==i:
list1.append(i)
elif i==i or i==i or i==i:
list2.append(i)
else:
list3.append(i)#将三种分别放入三个列表中
list1=sorted(list1,reverse=True)#列表1排序
temp=max(list(max(j) for j in list2))+1
for k in range(len(list2)):
if list2==list2:
list2=(list2*temp+list2,)+list2
elif list2==list2:
list2=(list2*temp+list2,)+list2
else:
list2=(list2*temp+list2,)+list2
list2=sorted(list2,reverse=True)
for p in range(len(list2)):
list2=list2#列表2排序,原理:先从每一组中演化出一个数字,即相同的那个数乘以temp再加上余下的那个数,将此数添加到每组的最前面,排序后再删去
for l in range(len(list3)):
list3=(sum(list3),)+list3
list3=sorted(list3,reverse=True)
for q in range(len(list3)):
list3=list3#列表3排序
list1.extend(list2)
list1.extend(list3)
print(list1)
fun_169([(4,1,1),(2,2,2),(5,6,1),(4,3,6),(2,4,3),(1,1,1),(4,3,6),(6,3,3),(1,3,6),(4,4,3),(6,2,2),(1,5,2),(5,6,6),(1,4,6),(2,1,6),(1,3,3),(6,6,5)])
foxiangzun
发表于 2019-1-25 23:27:59
import random
def getRollScore():
rollTime = 20
list1, list2, list3 = [], [], []
for i in range(rollTime):
list1.append((random.randint(1, 6), random.randint(1, 6), random.randint(1, 6)))
print('原始点数列表:', end='')
print(list1, end='\n-----------\n')
for i in list1[:]:
if len(set(i)) == 3:
list3.append(i)
list1.remove(i)
elif len(set(i)) == 2:
list2.append(i)
list1.remove(i)
if len(list3) > 1:
numCompare(list3)
if len(list2) > 1:
for i in range(len(list2) - 1):
tempTup = ()
for j in range(len(list2) - i - 1):
if (sum(list2) - sum(set(list2))) < (sum(list2) - sum(set(list2))):
tempTup = list2
list2 = list2
list2 = tempTup
elif (sum(list2) - sum(set(list2))) == (
sum(list2) - sum(set(list2))):
if sum(list2) < sum(list2):
tempTup = list2
list2 = list2
list2 = tempTup
if len(list1) > 1:
numCompare(list1)
for i in list2:
list1.append(i)
for i in list3:
list1.append(i)
print('排序后的列表:', end='')
print(list1)
def numCompare(list1):
for i in range(len(list1) - 1):
tempTup = ()
for j in range(len(list1) - i - 1):
if sum(list1) < sum(list1):
tempTup = list1
list1 = list1
list1 = tempTup
return list1
getRollScore()
kinkon
发表于 2022-9-7 14:15:13
本帖最后由 kinkon 于 2022-9-7 14:39 编辑
from collections import Counter
def f169(arr):
p3, p2, p1 = list(),list(),list()
for a in arr:
if a == a == a:
p3.append(a)
elif a != a != a:
p1.append(a)
else:
p2.append(a)
p3.sort(reverse = True)
p2.sort(key=lambda x: x if x == x or x == x else x, reverse = True)
p1.sort(key=sum, reverse = True)
return p3 + p2 + p1
arr = [(4, 1, 1), (2, 2, 2), (5, 6, 1), (4, 3, 6), (2, 4, 3), (1, 1, 1), (4, 3, 6), (6, 3, 3), (1, 3, 6), (4, 4, 3), (6, 2, 2), (1, 5, 2), (5, 6, 6), (1, 4, 6), (2, 1, 6), (1, 3, 3), (6, 6, 5)]
print(f169(arr))