Skip to content

Instantly share code, notes, and snippets.

@So-Cool
Last active December 29, 2016 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save So-Cool/4c2c65b3864fc4d392eba8eef3ea7bc1 to your computer and use it in GitHub Desktop.
Save So-Cool/4c2c65b3864fc4d392eba8eef3ea7bc1 to your computer and use it in GitHub Desktop.
How to find a 'perfect 10'

Perfect10

How it works?

How to find a 'perfect 10'?

This simple algorithm applies Optional Stopping Time Theorem used for calculating optimal exercising time for American Options. Simply, it tells you whether your current partner is optimal.
Optimality is calculated in a sens of score represented by integer: 1--10, that you assign to your current partner. You also need to specify a few more parameters like:

  • score(1--10) of you current partner,
  • number of partners you already had(including your current partner),
  • how many more partners you think you can have,
  • the minimum score of a partner that you would date, and,
  • the maximum score of a partner that would date you.

How to run it?

For execution, you must have python installed. On UNIX-like systems do:

git clone git@gist.github.com:4c2c65b3864fc4d392eba8eef3ea7bc1.git perfect10
cd perfect10
python ./p10.py
#! /usr/bin/python
# snell envelope for dating
# imports
from time import sleep
if __name__ == '__main__':
print "Let's the hunt begin!"
# PARTNER SCORE
# check whether number was given
score = None
while not score :
try:
score = int( raw_input( "Please give score from 1 to 10 of your " +
"current partner:\n=>" ) )
if score <= 0 or score > 10 :
score = None
print "Number must be in range 1--10."
except ValueError:
print "It must be an integer in range 1--10."
# # PARTNERS BEFORE
# check whether number was given
previous = None
while not previous :
try:
previous = int( raw_input( "How many partners have you had?" +
"(including current one):\n=>" ))
if previous <= 0 :
previous = None
print "Number must be greater than 0."
except ValueError:
print "It must be an integer greater than 0."
# # partners intend to have
# check whether number was given
next = None
while not next :
try:
next = int( raw_input( "How many more partners do you intend to " +
"have?:\n=>" ) )
if next < 0 :
next = None
print "Number must be non-negative."
except ValueError:
print "It must be non-negative integer."
# your min
# check whether number was given
minS = None
while not minS :
try:
minS = int( raw_input( "What is the min score that you will date?" +
":\n=>" ) )
if minS < 1 and minS > 10 :
minS = None
print "Number must be in range 1--10."
except ValueError:
print "It must be an integer in range 1--10."
# your max
# check whether number was given
maxS = None
while not maxS :
try:
maxS = int( raw_input( "What is the max score that will date you?" +
":\n=>" ) )
if maxS < 1 and maxS > 10 :
maxS = None
print "Number must be in range 1--10."
except ValueError:
print "It must be an integer in range 1--10."
# print "a: ", score, " b: ", previous, " c: ", next, " d: ", minS, \
# " e: ", maxS
################################################################################
# Calculated snell envelope for each partner
snellEnvelope = []
# Simulate uniformly the first partner which you dated
first = range( minS, maxS+1 )
first = sum( first ) / float( len( first ) )
snellEnvelope.append( first )
# calculate for each partner
for i in range( 2, previous+next-1+1 ) :
count = 0
for j in range( minS, maxS+1 ) :
if j < snellEnvelope[-1] :
count += snellEnvelope[-1]
else :
count += j
snellEnvelope.append( float(count) / float(len(range(minS, maxS+1))) )
# Print the snell envelope
# print "The overall snell envelope:\n", snellEnvelope, "\n"
#print makeUp / brakUp
print "It seems like you have to..."
# build up emotions for 5 seconds
sleep( 5 )
print ".\n..\n...\n....\n.....\n......\n......."
if snellEnvelope[previous - 1] <= score :
print "makeUp!"
else :
print "........"
print "breakUp!"
print "........"
print ".......\n......\n.....\n....\n...\n..\n."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment