Python Forum
Dice Roll (Find out how many rolls until specified streak)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dice Roll (Find out how many rolls until specified streak)
#5
Here is a shorter version of the infinite sequences method
>>> from random import randint
>>> import itertools as itt
>>> rolls = (randint(1, 6) + randint(1, 6) == 2 for _ in itt.repeat(None))
>>> sum_consec = (s := x and s + 1 for x in rolls)
>>> target = 4
>>> next(itt.dropwhile((lambda t: t[1] < target), enumerate(sum_consec, 1)))[0]
2378988
Reply


Messages In This Thread
RE: Dice Roll (Find out how many rolls until specified streak) - by Gribouillis - Jun-13-2021, 09:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with dice roll program kraco 4 2,193 Sep-22-2020, 02:06 PM
Last Post: kraco
  simple dice roll Byzas 1 2,405 Mar-21-2019, 02:29 AM
Last Post: ichabod801
Photo roll of the dice kyle007 0 1,781 Mar-11-2019, 01:58 AM
Last Post: kyle007
  unit test roll die saladgg 5 4,288 Nov-06-2018, 11:39 PM
Last Post: stullis
  Issue with my 'roll the dice simulation'-exercise (cannot break out of the loop) Placebo 2 3,595 Sep-30-2018, 01:19 PM
Last Post: Placebo
  Making a percentile dice roller and dice roller Fixer243 2 3,316 Sep-30-2018, 12:18 PM
Last Post: gruntfutuk
  Random Dice roll program th3h0bb5 1 5,621 Oct-18-2016, 09:25 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020