Advertisement
Guest User

Katie's Three Dice Solution

a guest
May 3rd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.83 KB | None | 0 0
  1. from math import *
  2. from os import *
  3. from time import *
  4. from random import *
  5. """ Python program to Katie and Paul's three dice in a glass box solution! """
  6. """ Problem by standupmaths """
  7. """ by Calvin Pash """
  8. def roll():
  9.     print ('Rolling in 1 second')
  10.     sleep(1)
  11.     global d1
  12.     d1 = randint(1,6) ## roll
  13.     global d2
  14.     d2 = randint(1,6)
  15.     global d3
  16.     d3 = randint(1,6)
  17.     print ('Original values are: ' + str(d1) + ', ' + str(d2) + ', ' + str(d3))
  18.     print ()
  19.     global output1
  20.     global even
  21.     global evenlist
  22.     global evend1
  23.     global evend2
  24.     global evend3
  25.     global even1
  26.     global output2
  27.     global evenlist
  28.     global dicelist
  29.     global val36
  30.     global edge
  31.     d1 = d1
  32.     output1= int(d1) + int(d2) + int(d3)
  33.     output1=output1 % 6 ## modulus of sum of dice
  34.     if output1 == 0:
  35.         output1 = 6
  36.     print('Mod of dice values is ' + str(output1))
  37.     if output1 % 2 == 0: ## checks if even
  38.         even = 1 ## this will come in use later
  39.         d1 = 7 - d1
  40.         d2 = 7 - d2
  41.         d3 = 7 - d3
  42.     else:
  43.         even = 0    
  44.     evenlist = [] ## this is to check if there are two different even numbers
  45.     if d1 % 2 == 0:
  46.         evend1 = 1 ## created these values to reference if dice values are even
  47.     else:
  48.         evend1 = 0
  49.         evenlist.insert(1, 1)
  50.     if d2 % 2 == 0:
  51.         evend2 = 1
  52.     else:
  53.         evend1 = 0
  54.         evenlist.insert(1, 2)
  55.     if d3 % 2 == 0:
  56.         evend3 = 1
  57.     else:
  58.         evend1 = 0
  59.         evenlist.insert(1, 3)
  60.     if d2 == d1 or d2 == d3 or d1 == d3: ## this is just to make it different even #s
  61.         evenlist.insert(1, 4)
  62.     if len(evenlist) > 1: ## if more than one violation it knows that there arent 2 even #s
  63.         print ('There are not more than 2 different even numbers')
  64.         even1 = 0 ## this is the second even check
  65.     else:
  66.         print ('There are two different even numbers')
  67.         even1 = 1
  68.     if even1 == 1:
  69.         if evenlist.count(1) > 0: ## checks if first dice is odd
  70.             if even == 1:
  71.                 output2 = 7 - d1
  72.                 output() ## this is my other function and outputs the final values
  73.             else:
  74.                 output2 = d1
  75.                 output()
  76.         if evenlist.count(2) > 0: ## same for second
  77.             if even == 1:
  78.                 output2 = 7 - d2
  79.                 output()
  80.             else:
  81.                 output2 = d2
  82.                 output()
  83.         if evenlist.count(3) > 0: ## and third
  84.             if even == 1:
  85.                 output2 = 7 - d3
  86.                 output()
  87.             else:
  88.                 output2 = d3
  89.                 output()
  90.     if even1 == 0:
  91.         if output1 == 3 or output1 == 6: ## This is for the 2nd to last item on the chart
  92.             print ('D1 equals 3 or 6')
  93.             val36 = 1
  94.             dicelist = [d1, d2, d3] ## this is how I am checking the edge
  95.             dicelist.sort() ## so that I can check it once
  96.             if dicelist[0] == 2 and dicelist[1] == 2 and dicelist[2] == 5:
  97.                 print ('Edge is true')
  98.                 edge = 1
  99.                 if even == 1:
  100.                     output2 = 5
  101.                     output()
  102.                 else:
  103.                     output1 = 2
  104.                     output()
  105.             else:
  106.                 print ('Edge is false')
  107.                 edge = 0
  108.                 set(dicelist) ## this deletes all duplicates in list
  109.                 output2 = int(len(dicelist)) * 2
  110.                 """ above multiplies length of unique values by two since all
  111.                duplicate values are deleted """
  112.                 if even == 1:
  113.                     output2 = 7 - output2
  114.                 output()
  115.         else:
  116.             val36 = 0
  117. def output(): ## output function I was talking about
  118.     print ()
  119.     print ('Dice 1: ' + str(output1))
  120.     print ('Dice 2: ' + str(output2))
  121. cont = 'y'
  122. while cont == 'y':
  123.     print ('Three dice to Two dice roll')
  124.     ## system('cls')
  125.     roll()
  126.     if even == 1: ## All of this is to display a completed flowchart
  127.         if even1 == 1:
  128.             print('http://picpaste.com/dice11.png')
  129.         else:
  130.             if val36 == 1:
  131.                 if edge == 1:
  132.                     print('http://picpaste.com/dice1011.png')
  133.                 else:
  134.                     print('http://picpaste.com/dice1010.png')
  135.             else:
  136.                 print('http://picpaste.com/dice100.png')
  137.     else:
  138.         if even1 == 1:
  139.             print('http://picpaste.com/dice01.png')
  140.         else:
  141.             if val36 == 1:
  142.                 if edge == 1:
  143.                     print('http://picpaste.com/dice0011.png')
  144.                 else:
  145.                     print('http://picpaste.com/dice0010.png')
  146.             else:
  147.                 print('http://picpaste.com/dice000.png')
  148.     cont = input('Restart? (y/n)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement