Beispiel #1
0
 def test_regression(self):
     from random import random as rnd
     from C import solve
     from time import time
     SIZE = 100000 # size of the regression (iterations)
     t1 = time()
     for _ in xrange(SIZE):
         # int(rnd() * (upper_bound - lower_bound) + lower_bound) for the parameter
         n = int(rnd() * (10 - 2)) + 2
         string = ""
         for i in xrange(n):
             string += (chr(ord('a') + int(rnd() * 23)))
         #print string
         subs = []
         for i in xrange(1, n):
             subs.append([string[:i], i - 1])
         for j in xrange(1, n):
             subs.append([string[-j:], j+i-1])
         print string
         print subs
         #print len(subs)
         #print n
         got = solve(subs)
         print got
         N = len(subs)
         self.assertTrue(got[:N/2] ==  'P'*(N/2) or got[:N/2] ==  'S'*(N/2)) 
         self.assertTrue(got[N/2:] ==  'P'*(N/2) or got[N/2:] ==  'S'*(N/2)) 
         
     t2 = time()
     print "regressionOK : "+str(t2 - t1)
Beispiel #2
0
 def test_regression(self):
     from random import random as rnd
     from C import solve
     from time import time
     SIZE = 1000  # size of the regression (iterations)
     t1 = time()
     for _ in xrange(SIZE):
         # int(rnd() * (upper_bound - lower_bound) + lower_bound) for the parameter
         got = solve((int(rnd() * (1000 - 0)) + 0),
                     (int(rnd() * (1000 - 1)) + 1))
         self.assertEqual(got, -1)
     t2 = time()
     print "regressionOK : " + str(t2 - t1)
Beispiel #3
0
def test(input, ans):
    ans = str(ans)

    s_in = StringIO.StringIO(input)
    s_out = StringIO.StringIO()
    sys.stdin = s_in; sys.stdout = s_out
    str(solve())
    sys.stdin = sys.__stdin__; sys.stdout = sys.__stdout__

    ans_tmp = s_out.getvalue().strip()

    if ans_tmp == ans:
        print "Correct %s -> %s" % (repr(input), repr(ans))
    else:
        print "Wrong!! %s should %s not %s" % (repr(input), repr(ans), repr(ans_tmp))
Beispiel #4
0
 def test_regression(self):
     from random import random as rnd
     from C import solve
     from time import time
     SIZE = 1000  # size of the regression (iterations)
     t1 = time()
     for i in xrange(SIZE):
         # int(rnd() * (upper_bound - lower_bound) + lower_bound) for the parameter
         sequence = sorted(
             [int(rnd() * (1000 - 0)) + 0 for _ in xrange(2 * (i + 2))])
         #print sequence
         b = []
         for i in xrange(len(sequence) / 2):
             num = sequence[i]
             b.append(num + sequence[-(i + 1)])
         #print b
         got = solve(b)
         #print got
         self.assertTrue(valid(b, got))
     t2 = time()
     print "regressionOK : " + str(t2 - t1)
    x *= sign
    digits = []

    while x:
        digits.append(digs[int(x % base)])
        x = int(x / base)

    if sign < 0:
        digits.append('-')

    digits.reverse()

    return ''.join(digits)
from C import solve

from math import factorial
for n in range(3, mn+1):
    nf = factorial(n)
    for b in range(3, mb):

        bb  = int2base(nf, b)

        k = len(bb) - len(bb.strip('0'))



        kk = solve(n, b)
        if kk != k:

            print(k, kk,int2base(nf, b), n , b)