Created
May 8, 2015 12:54
-
-
Save jamescookie/d969dcf2c1a5bab9e716 to your computer and use it in GitHub Desktop.
Better than a/b testing: http://stevehanov.ca/blog/index.php?id=132
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random | |
Random rand = new Random() | |
def colours = ['blue', 'green', 'red', 'yellow'] | |
def likihood = [blue: 25, green: 22, red: 22, yellow: 5] | |
def views = [blue: 1, green: 1, red: 1, yellow: 1] | |
def clicks = [blue: 1, green: 1, red: 1, yellow: 1] | |
def percentages | |
for (def i = 0; i < 10000; i++) { | |
def colour | |
if (rand.nextInt(100) < 10) { | |
colour = colours[rand.nextInt(colours.size())] | |
} else { | |
percentages = colours.collectEntries { | |
[(it): clicks[it]/views[it]*100] | |
} | |
percentages = percentages.sort {a, b -> b.value <=> a.value} | |
colour = percentages.find {true}.key | |
} | |
views[colour] = views[colour] + 1 | |
if (rand.nextInt(100) < likihood[colour]) { | |
clicks[colour] = clicks[colour] + 1 | |
} | |
} | |
println clicks.sort {a, b -> b.value <=> a.value}.find{true} | |
println percentages | |
println views |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment