probabilty done
This commit is contained in:
parent
1ee37b4023
commit
47c104afec
@ -1,5 +1,10 @@
|
|||||||
50/50 for ever door all the time!
|
50/50 for ever door all the time!
|
||||||
|
|
||||||
|
[ total/ wins ]
|
||||||
|
switched [98179, 65319] not switched [97686, 32587] total [195865, 97906]
|
||||||
|
switched 66.53052078346693 % not switched 33.35892553692443 % all 49.98647027289204 %
|
||||||
|
|
||||||
|
|
||||||
The Monty Hall Problem
|
The Monty Hall Problem
|
||||||
======================
|
======================
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -46,7 +46,7 @@ class Controller:
|
|||||||
if do == 'n':
|
if do == 'n':
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
self.start()
|
return self.start()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
Controller()
|
Controller()
|
||||||
|
Binary file not shown.
4
exercises/1-monty-hall-problem/loop.sh
Normal file
4
exercises/1-monty-hall-problem/loop.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
for (( c=1; c<=100000; c++ ))
|
||||||
|
do
|
||||||
|
python3 controller.py
|
||||||
|
done
|
@ -18,6 +18,7 @@ class Doors:
|
|||||||
|
|
||||||
if self.selected == self.car:
|
if self.selected == self.car:
|
||||||
logDB( self.name, self.switch, True)
|
logDB( self.name, self.switch, True)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logDB( self.name, self.switch, False)
|
logDB( self.name, self.switch, False)
|
||||||
|
28
exercises/1-monty-hall-problem/stats.py
Normal file
28
exercises/1-monty-hall-problem/stats.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import sqlite3
|
||||||
|
|
||||||
|
conn = sqlite3.connect('default.db')
|
||||||
|
|
||||||
|
c = conn.cursor()
|
||||||
|
|
||||||
|
switched = [ 0, 0 ]
|
||||||
|
no_swich = [ 0, 0 ]
|
||||||
|
total = [ 0, 0 ]
|
||||||
|
c.execute( "SELECT * FROM games " )
|
||||||
|
result = c.fetchall()
|
||||||
|
for i in result:
|
||||||
|
if int( i[ 2 ] ) == 1:
|
||||||
|
# switched
|
||||||
|
switched[0] += 1
|
||||||
|
switched[1] += int( i[3] )
|
||||||
|
else:
|
||||||
|
# not switched
|
||||||
|
no_swich[0] += 1
|
||||||
|
no_swich[1] += int( i[3] )
|
||||||
|
|
||||||
|
total[0] += 1
|
||||||
|
total[1] += int( i[3] )
|
||||||
|
conn.commit()
|
||||||
|
c.close()
|
||||||
|
|
||||||
|
print( "switched", switched, "not switched", no_swich, "total", total)
|
||||||
|
print( 'switched', ( switched[1]/switched[0] )*100, "% not switched", ( no_swich[1]/no_swich[0] )*100, "% all", ( total[1]/total[0] )*100, "%" )
|
@ -1,24 +1,21 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
class View:
|
class View:
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
print( "Welcome to the Monty Hall Problem!")
|
pass
|
||||||
|
|
||||||
def get_name( self ):
|
def get_name( self ):
|
||||||
return input( "Please enter your name: " )
|
return "computer"
|
||||||
|
|
||||||
def display_doors( self ):
|
def display_doors( self ):
|
||||||
print( 'Doors: [ 1 ] [ 2 ] [ 3 ]' )
|
return random.randint( 1,3 )
|
||||||
return input( 'Select door: ' )
|
|
||||||
|
|
||||||
def host_twist( self, message ):
|
def host_twist( self, message ):
|
||||||
print( "The host will revel where one goat is..." )
|
return bool(random.getrandbits(1))
|
||||||
print( message )
|
|
||||||
print( "Would you like to change your selection? [n/y]" )
|
|
||||||
return input( "[no]: ")
|
|
||||||
|
|
||||||
def winner( self ):
|
def winner( self ):
|
||||||
print( "You WIN!!!" )
|
return ''
|
||||||
return input("Play again?[y]")
|
|
||||||
|
|
||||||
def loser( self ):
|
def loser( self ):
|
||||||
print( "You Lose!!!" )
|
return 'n'
|
||||||
return input("Play again?[y]")
|
|
BIN
exercises/2-bank-software/bank.db
Normal file
BIN
exercises/2-bank-software/bank.db
Normal file
Binary file not shown.
@ -1 +1,25 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
class db:
|
||||||
|
def __init__():
|
||||||
|
pass
|
||||||
|
def create_user( self, name, pin, permission ):
|
||||||
|
conn = sqlite3.connect(self.db_name)
|
||||||
|
c = conn.cursor()
|
||||||
|
|
||||||
|
c.execute( "SELECT * FROM user WHERE name LIKE (?)", (name) )
|
||||||
|
result = c.fetchall()
|
||||||
|
|
||||||
|
if len(result) == 0:
|
||||||
|
pin = hashlib.md5( pin )
|
||||||
|
c.execute( "INSERT INTO user ( name, pin, permission ) VALUES ( ?, ? )", ( name, pin.hexdigest(), permission ) )
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
c.close()
|
||||||
|
return True
|
||||||
|
|
||||||
|
else:
|
||||||
|
conn.commit()
|
||||||
|
c.close()
|
||||||
|
return False
|
@ -0,0 +1,294 @@
|
|||||||
|
import time
|
||||||
|
import random
|
||||||
|
|
||||||
|
class View:
|
||||||
|
def __init__( self, screen, curses ):
|
||||||
|
|
||||||
|
self.showDev = False
|
||||||
|
self.userName = None
|
||||||
|
|
||||||
|
self.curses = curses
|
||||||
|
# start the curses instance
|
||||||
|
self.screen = screen
|
||||||
|
|
||||||
|
# configure the whole screen
|
||||||
|
|
||||||
|
# set border for main screen
|
||||||
|
self.screen.border(0)
|
||||||
|
# hide KB input
|
||||||
|
self.curses.noecho()
|
||||||
|
|
||||||
|
self.curses.curs_set(0)
|
||||||
|
|
||||||
|
# idk, i have to look it up
|
||||||
|
self.screen.keypad(1)
|
||||||
|
|
||||||
|
# draw the main screen
|
||||||
|
self.screen.refresh()
|
||||||
|
|
||||||
|
# setup the header window
|
||||||
|
self.header = self.curses.newwin( 4, 35, 2, 3 )
|
||||||
|
self.header.border(0)
|
||||||
|
|
||||||
|
# setup the right header window
|
||||||
|
self.header_right = self.curses.newwin( 4, 35, 2, 38 )
|
||||||
|
self.header_right.border(0)
|
||||||
|
self.header_right.refresh()
|
||||||
|
|
||||||
|
# setup the body window
|
||||||
|
self.body = self.curses.newwin( 15, 50, 6 , 3)
|
||||||
|
# self.body.border(0)
|
||||||
|
|
||||||
|
# side bar
|
||||||
|
self.side_bar = self.curses.newwin( 15, 20, 6 , 53)
|
||||||
|
self.side_bar.border(0)
|
||||||
|
|
||||||
|
# dev console
|
||||||
|
self.dev = self.curses.newwin( 50, 70, 17 , 3)
|
||||||
|
self.dev.border(0)
|
||||||
|
|
||||||
|
#############################################
|
||||||
|
|
||||||
|
self.header_right.addstr( 1, 20, "Not logged in")
|
||||||
|
self.header_right.refresh()
|
||||||
|
|
||||||
|
def menu( self, sidebar=True ):
|
||||||
|
#listen for keyboard input
|
||||||
|
|
||||||
|
# hide KB input
|
||||||
|
self.curses.noecho()
|
||||||
|
|
||||||
|
if sidebar:
|
||||||
|
array = []
|
||||||
|
|
||||||
|
# check if there is a logged in user
|
||||||
|
if self.userName:
|
||||||
|
array.extend( [ "l log out", "p play" ] )
|
||||||
|
else:
|
||||||
|
array.extend( [ "l login", "n new user" ] )
|
||||||
|
|
||||||
|
#append things that are all ways in menu
|
||||||
|
array.extend( [ "", "c cedits", "Q Quit" ] )
|
||||||
|
|
||||||
|
# trigger side bar update
|
||||||
|
self.update_side_bar( array )
|
||||||
|
|
||||||
|
# loop to listen for user input
|
||||||
|
while True:
|
||||||
|
|
||||||
|
event = self.screen.getch()
|
||||||
|
|
||||||
|
# check if user is logged in
|
||||||
|
if self.userName:
|
||||||
|
if event == ord( "p" ) or event == ord( "P" ):
|
||||||
|
return { '_return_to': 'new_round' }
|
||||||
|
|
||||||
|
if event == ord( "h" ) or event == ord( "H" ):
|
||||||
|
return { '_return_to': 'home' }
|
||||||
|
|
||||||
|
if event == ord( "l" ) or event == ord( "L" ):
|
||||||
|
return { '_return_to': 'logOut' }
|
||||||
|
else:
|
||||||
|
if event == ord( "n" ) or event == ord( "N" ):
|
||||||
|
return { '_next': 'sign_up' }
|
||||||
|
|
||||||
|
if event == ord( "l" ) or event == ord( "L" ):
|
||||||
|
return { '_next': 'login' }
|
||||||
|
|
||||||
|
|
||||||
|
# all ways
|
||||||
|
if event == ord( "c" ) or event == ord( "C" ):
|
||||||
|
return { '_next': 'about' }
|
||||||
|
|
||||||
|
if event == ord( "q" ) or event == ord( "Q" ):
|
||||||
|
# needs work...
|
||||||
|
self.curses.endwin()
|
||||||
|
exit()
|
||||||
|
else:
|
||||||
|
self.side_bar.addstr( 12, 2, "invalid choice." )
|
||||||
|
# draw the body
|
||||||
|
self.curses.flash()
|
||||||
|
self.side_bar.refresh()
|
||||||
|
|
||||||
|
def welcome( self, message=False ):
|
||||||
|
|
||||||
|
# write the header up
|
||||||
|
self.header.addstr( 1, 2, "Welcome to the RPN game!" )
|
||||||
|
#draw the header
|
||||||
|
self.header.addstr( 2, 2, "Go bears!" )
|
||||||
|
if self.showDev:
|
||||||
|
self.header.addstr( 2, 12, "-dev" )
|
||||||
|
|
||||||
|
self.header.refresh()
|
||||||
|
|
||||||
|
# short pause
|
||||||
|
time.sleep(.5)
|
||||||
|
|
||||||
|
self.body.clear()
|
||||||
|
self.body.refresh()
|
||||||
|
|
||||||
|
# write the body
|
||||||
|
self.body.addstr( 1, 3, "c cedits" )
|
||||||
|
self.body.addstr( 3, 3, "l login" )
|
||||||
|
self.body.addstr( 4, 3, "n new user" )
|
||||||
|
self.body.addstr( 6, 3, "Q Quit" )
|
||||||
|
|
||||||
|
# draw the body
|
||||||
|
self.body.refresh()
|
||||||
|
|
||||||
|
#listen for keyboard input
|
||||||
|
return self.menu()
|
||||||
|
|
||||||
|
def sign_up( self, message=False ):
|
||||||
|
|
||||||
|
# remove old body content
|
||||||
|
self.body.clear()
|
||||||
|
|
||||||
|
# allow user to see KB input
|
||||||
|
self.curses.echo()
|
||||||
|
|
||||||
|
# remove old content
|
||||||
|
self.side_bar.clear()
|
||||||
|
self.side_bar.refresh()
|
||||||
|
|
||||||
|
# write to body
|
||||||
|
self.body.addstr(2, 2, "Pick a new user name and pin:" )
|
||||||
|
# draw body
|
||||||
|
self.body.refresh()
|
||||||
|
|
||||||
|
# show error message
|
||||||
|
if message:
|
||||||
|
self.body.addstr( 7, 2, message )
|
||||||
|
self.body.refresh()
|
||||||
|
|
||||||
|
# ask for user name
|
||||||
|
self.body.addstr(3, 2, "user Name:" )
|
||||||
|
name = self.body.getstr(4, 2, 60)
|
||||||
|
|
||||||
|
self.body.addstr(5, 2, "Pin:" )
|
||||||
|
#self.body.refresh()
|
||||||
|
password = self.body.getstr(6, 2, 60)
|
||||||
|
|
||||||
|
return( { 'name':name, 'password':password, '_return_to': 'sign_up' } )
|
||||||
|
|
||||||
|
def login( self, message=False ):
|
||||||
|
|
||||||
|
# remove old body content
|
||||||
|
self.body.clear()
|
||||||
|
|
||||||
|
# remove old content
|
||||||
|
self.side_bar.clear()
|
||||||
|
self.side_bar.refresh()
|
||||||
|
|
||||||
|
# allow user to see KB input
|
||||||
|
self.curses.echo()
|
||||||
|
|
||||||
|
if message:
|
||||||
|
self.curses.flash()
|
||||||
|
self.body.addstr( 7, 2, message )
|
||||||
|
self.body.refresh()
|
||||||
|
|
||||||
|
self.body.addstr(2, 2, "Please log in with your user name and pin:" )
|
||||||
|
|
||||||
|
self.body.addstr(3, 2, "user Name:" )
|
||||||
|
name = self.body.getstr(4, 2, 60)
|
||||||
|
self.body.addstr(5, 2, "Pin:" )
|
||||||
|
|
||||||
|
self.body.refresh()
|
||||||
|
password = self.body.getstr(6, 2, 60)
|
||||||
|
|
||||||
|
# if error message
|
||||||
|
|
||||||
|
return( { 'name':name, 'password':password, '_return_to': 'login' } )
|
||||||
|
|
||||||
|
def update_side_bar( self, array ):
|
||||||
|
|
||||||
|
# remove old content
|
||||||
|
self.side_bar.clear()
|
||||||
|
self.side_bar.border(0)
|
||||||
|
left = 3
|
||||||
|
count = 1
|
||||||
|
for i in array:
|
||||||
|
self.side_bar.addstr( count, left, str(i) )
|
||||||
|
count += 1
|
||||||
|
# draw new content
|
||||||
|
self.side_bar.refresh()
|
||||||
|
|
||||||
|
def update_user( self, array ):
|
||||||
|
self.userName = array[0]
|
||||||
|
if not self.userName:
|
||||||
|
display = "Please log in"
|
||||||
|
else:
|
||||||
|
display = array[0]
|
||||||
|
# remove old content
|
||||||
|
self.header_right.clear()
|
||||||
|
self.header_right.border(0)
|
||||||
|
|
||||||
|
left = 33 - len( display )
|
||||||
|
|
||||||
|
self.header_right.addstr( 1, left, display )
|
||||||
|
# draw new content
|
||||||
|
self.header_right.refresh()
|
||||||
|
|
||||||
|
def about( self, message=False ):
|
||||||
|
# remove old body content
|
||||||
|
self.body.clear()
|
||||||
|
self.body.border(0)
|
||||||
|
|
||||||
|
self.side_bar.clear()
|
||||||
|
self.side_bar.refresh()
|
||||||
|
|
||||||
|
array = [
|
||||||
|
{
|
||||||
|
'name': "William Mantly",
|
||||||
|
'email': "wmantly@gmail.com",
|
||||||
|
'desc': "Designed and implemented the UI."
|
||||||
|
},{
|
||||||
|
'name': "Benjamin Himley",
|
||||||
|
'email': "benjaminhimley85@gmail.com",
|
||||||
|
'desc': "wrote rpn generator and controller,",
|
||||||
|
'desc2': "bugfix assit"
|
||||||
|
},{
|
||||||
|
'name': "Adolfo Reyes",
|
||||||
|
'email': "adolfo0620@gmail.com",
|
||||||
|
'desc': "bug hunter"
|
||||||
|
},{
|
||||||
|
'name': "Brendan Gilroy",
|
||||||
|
'email': "BDGilroy@gmail.com"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
random.shuffle(array)
|
||||||
|
|
||||||
|
line = 2
|
||||||
|
for i in array:
|
||||||
|
self.body.addstr( line, 2, i['name'] + ' - ' + i['email'] )
|
||||||
|
if 'desc' in i:
|
||||||
|
line += 1
|
||||||
|
self.body.addstr( line, 2, i['desc'] )
|
||||||
|
if 'desc2' in i:
|
||||||
|
line += 1
|
||||||
|
self.body.addstr( line, 2, i['desc2'] )
|
||||||
|
line += 2
|
||||||
|
self.body.refresh()
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
return self.menu()
|
||||||
|
|
||||||
|
def devConsole( self, message, sleep=2 ):
|
||||||
|
# side bar
|
||||||
|
if not self.showDev: return False
|
||||||
|
|
||||||
|
self.dev.clear()
|
||||||
|
self.dev.border(0)
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
for i in message:
|
||||||
|
count += 1
|
||||||
|
self.dev.addstr( count, 2, i )
|
||||||
|
print( i )
|
||||||
|
|
||||||
|
self.dev.refresh()
|
||||||
|
time.sleep( sleep )
|
||||||
|
|
||||||
|
##testing
|
@ -1 +1,41 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
def create_db():
|
||||||
|
conn = sqlite3.connect('bank.db')
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("DROP TABLE IF EXISTS 'user'")
|
||||||
|
c.execute("DROP TABLE IF EXISTS 'accounts'")
|
||||||
|
c.execute("DROP TABLE IF EXISTS 'transactions'")
|
||||||
|
c.execute("""
|
||||||
|
CREATE TABLE users (
|
||||||
|
id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT DEFAULT NULL,
|
||||||
|
created TEXT DEFAULT NULL,
|
||||||
|
permission TEXT DEFAULT NULL
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
c.execute("""
|
||||||
|
CREATE TABLE accounts (
|
||||||
|
id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER DEFAULT NULL REFERENCES users (id),
|
||||||
|
balance TEXT DEFAULT NULL,
|
||||||
|
name TEXT DEFAULT NULL,
|
||||||
|
opened TEXT DEFAULT NULL
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
c.execute("""
|
||||||
|
CREATE TABLE transactions (
|
||||||
|
id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
outgoing_id INTEGER DEFAULT NULL REFERENCES accounts (id),
|
||||||
|
incoming_id INTEGER DEFAULT NULL REFERENCES accounts (id),
|
||||||
|
type TEXT DEFAULT NULL,
|
||||||
|
amount TEXT DEFAULT NULL,
|
||||||
|
date TEXT DEFAULT NULL,
|
||||||
|
new field TEXT DEFAULT NULL
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
c.close()
|
||||||
|
|
||||||
|
create_db()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user