Created
March 5, 2022 15:57
-
-
Save ntoonio/62fa5933876e32d11cc8e62e33e40325 to your computer and use it in GitHub Desktop.
To settle a debate; when still having questions left to answer on a test with not enough time to do so - is it more effective to choose a single alternative and answer that for all questions (for example checking "A" on all) than to answer randomly
This file contains hidden or 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 random | |
import time | |
import sys | |
def createTest(a, n): | |
l = [] | |
for _ in range(0, n): | |
l.append([0 for _ in range(0, a)]) | |
l[-1][random.randint(0, a - 1)] = 1 | |
return l | |
def countCorrectRandom(l): | |
c = 0 | |
for li in l: | |
a = random.randint(0, len(li) - 1) | |
if li[a] == 1: | |
c += 1 | |
return c | |
def countCorrectStraight(l, a): | |
c = 0 | |
for li in l: | |
if li[a] == 1: | |
c += 1 | |
return c | |
def testOneList(): | |
a = random.randint(2, 10) | |
n = a * random.randint(3, 10) | |
l = createTest(a, n) | |
sCorrect = countCorrectStraight(l, random.randint(1, a) - 1) | |
rCorrect = countCorrectRandom(l) | |
return (sCorrect, rCorrect) | |
def runTests(tests): | |
sWin = 0 | |
rWin = 0 | |
ties = 0 | |
for _ in range(0, tests): | |
s, r = testOneList() | |
if s < r: | |
sWin += 1 | |
elif s > r: | |
rWin += 1 | |
else: | |
ties += 1 | |
print("Straight wins:", sWin) | |
print("Random wins:", rWin) | |
print("Ties:", ties) | |
print() | |
print("Diff:", sWin - rWin, "({}%)".format(abs(sWin - rWin) / tests * 100)) | |
winner = sorted([ | |
("Straight", sWin), | |
("Random", rWin), | |
("No one (tie)", ties) | |
], key=lambda tup: tup[1], reverse=True)[0][0] | |
print() | |
print(winner + " won!") | |
def main(): | |
try: | |
N = int(sys.argv[1]) | |
except: | |
N = 1 | |
print("Running", N, "tests...") | |
print() | |
startTime = time.time() | |
runTests(N) | |
endTime = time.time() - startTime | |
print() | |
print("Took %s seconds" % (endTime)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment