Recent Posts
Lua | 4 sec ago
None | 9 sec ago
None | 10 sec ago
ASM (NASM) | 29 sec ago
HTML | 34 sec ago
None | 35 sec ago
JavaScript | 37 sec ago
None | 54 sec ago
None | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By joel on the 20th of Feb 2008 12:29:05 PM Download | Raw | Embed | Report
  1. #!//usr/bin/env python
  2.  
  3. max_digit=12
  4. max_big=30
  5.  
  6. def get_add_operation():
  7.     import random
  8.     a=random.randint(1,max_big)
  9.     b=random.randint(1,a)
  10.     if random.random()<0.5:
  11.         return ('%d+%d?'%(a-b,b),a)
  12.     else:
  13.         return ('%d+%d?'%(b,a-b),a)
  14.  
  15. def get_mult_operation():
  16.     import random
  17.     a=random.randint(1,max_digit)
  18.     b=random.randint(1,max_digit)
  19.     return ('%dx%d?'%(a,b),a*b)
  20.  
  21. def get_minus_operation():
  22.     import random
  23.     a=random.randint(1,max_big)
  24.     b=random.randint(1,a)
  25.     return ('%d-%d?'%(a,b),a-b)
  26.  
  27. def get_div_operation():
  28.     import random
  29.     a=random.randint(1,max_digit)
  30.     b=random.randint(1,max_digit)
  31.     return ('%d/%d?'%(a*b,b),a)
  32.  
  33. op_funcs = [ get_add_operation, get_mult_operation, get_minus_operation, get_div_operation ]
  34.  
  35. def get_random_operation():
  36.     return random.choice(op_funcs)()
  37.  
  38. if __name__ == '__main__':
  39.     import time
  40.     import random
  41.     import cPickle
  42.     import sys
  43.     if len(sys.argv) < 2: raise "Usage : compute.py login"
  44.     ops_per_serie=15
  45.     try:
  46.         f=open("compute_stats_%s.pck" % sys.argv[1],"rb") #read stats on disk
  47.         operations=cPickle.load(f)
  48.         f.close()
  49.         op_list = operations.items()
  50.         op_list.sort(key=lambda i:sum(i[1][0])/len(i[1][0])) #sort by accuracy score
  51.         bad_ops = [a[0] for a in op_list if sum(a[1][0])/len(a[1][0]) < 0.9] #ops the user doesn't master
  52.         op_list.sort(key=lambda e:sum(e[1][1])/len(e[1][1]),reverse=True) #sort by answer time
  53.         bad_ops.extend([a[0] for a in op_list[:10]]) #ops the user is slow to answer
  54.         bad_ops=list(set(bad_ops)) #remove duplicates
  55.     except Exception, e:
  56.         operations={} #operations["5*2"] = [a,b,c,d,e] with a=1. if good, a=0. if wrong storing the 5 last results
  57.     before = time.time()
  58.     errors = 0
  59.     for i in range(ops_per_serie):
  60.         op_string,expected=get_random_operation()
  61.         if random.random() < len(bad_ops)/(1.5*ops_per_serie):#train user specifically on stuff he doesn't master
  62.             #print "training on bad op"
  63.             op_string,expected = random.choice(bad_ops)
  64.         #print len(bad_ops)/(1.5*ops_per_serie) #badop training probability
  65.         scores,answer_times=operations.get((op_string,expected),([],[]))
  66.         print op_string
  67.         before_op=time.time()
  68.         try:
  69.             answer = int(raw_input())
  70.         except:
  71.             answer = expected-1 # this should be always wrong
  72.         answer_time=time.time()-before_op
  73.         if len(scores) > 5 : scores.pop(0) # keep only 5 scores
  74.         if len(answer_times) > 5 : answer_times.pop(0) # keep only 5 timings
  75.         answer_times.append(answer_time)
  76.         if answer != expected:
  77.             errors += 1
  78.             scores.append(0.)
  79.             operations[(op_string,expected)] = (scores,answer_times)
  80.             print "WRONG!"
  81.         else:
  82.             scores.append(1.)
  83.             operations[(op_string,expected)] = (scores,answer_times)
  84.             print "good."
  85.     total_time = time.time() - before
  86.     print "Time: %.2fs, Errors : %d, Total points : %d" % (total_time,errors,100*ops_per_serie*(5.-errors)/total_time)
  87.     cPickle.dump(operations,open("compute_stats_%s.pck"%sys.argv[1],"wb"))
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: