Exemplo n.º 1
0
def u_next_lax_wendroff(u_last, u_halfstep, delta_t, delta_x, j, time,
                        position):
    u_halfstep[j] = u_next_half_step(u_last, delta_t, delta_x, j, time,
                                     position)
    return u_last[j] - delta_t/delta_x*(f(u_halfstep[j])-f(u_halfstep[j-1])) \
           + delta_t*func.g3(u_halfstep, delta_x, j)\
           +(delta_t/2)*(func.s(time, position, u_halfstep, j)+func.s(time, position, u_halfstep, j-1))
Exemplo n.º 2
0
 def parse_argument_list(klass, args):
     ''' Collects options from the given argument list,
         returning any unparsable ones.
     '''#'''
     if klass._cache:
         print('Warning: Option%s %s set before command-line parsing' %
               (s(len(klass._cache)), expand_list(klass._cache.keys())))
     result = [arg for arg in args if not klass.parse_argument(arg)]
     return result
Exemplo n.º 3
0
 def handle_SMR(self, message):
     player_list = message.fold()[2:]
     num_players = len(player_list)
     num_winners = 0
     participants = {}
     if self.winners:
         def won(power, centers, winners=self.winners):
             return power in winners
     else:
         def won(power, centers):
             return centers > 0
     
     # Information-gathering loop
     for player in player_list:
         power,name,version,centers = player[:4]
         stats = participants.setdefault((name[0], version[0]), [0,0])
         if won(power, centers):
             num_winners += 1
             stats[0] += 1
         else: stats[1] += 1
     
     win_factor = num_players / num_winners
     scores = self.read_scores()
     self.log_debug(9, 'Initial scores:', scores)
     report = ['Ladder scores have been updated as follows:']
     
     # Scoring loop
     for key, stat_list in participants.iteritems():
         diff = (win_factor * stat_list[0]) - (stat_list[0] + stat_list[1])
         if scores.has_key(key): scores[key] += diff
         else: scores[key] = diff
         if diff < 0: gain = 'loses'
         else: gain = 'gains'
         change = abs(diff)
         report.append('%s (%s) %s %g point%s, for a total of %g.'
             % (key[0], key[1], gain, change, s(change), scores[key]))
     
     # Report results
     self.store_scores(scores)
     for line in report: self.send_admin(line); self.log_debug(9, line)
     if self.quit: self.close()
Exemplo n.º 4
0
from functions import simpleseive as s, is_prime
from time import clock as now

primes1 = s(9000,2)
primes2 = s(10000,2)

def test(list_of_primes):
    for i in range(len(list_of_primes)):
        for j in range(i + 1,len(list_of_primes)):
            if not is_prime(int(str(list_of_primes[i]) + str(list_of_primes[j])),primes2) or not is_prime(int(str(list_of_primes[j]) + str(list_of_primes[i])),primes2):                
                return False
    else:
        return True   
                 
#for i in range(4,len(primes1)):
#    print(i)
#    for j in range(3,i):
#        for k in range(2,j):
#            for l in range(1,k):
#                for m in range(l):
#                    if test([primes1[i],primes1[j],primes1[k],primes1[l],primes1[m]]):
#                        print([primes1[i],primes1[j],primes1[k],primes1[l],primes1[m]], sum([primes1[i],primes1[j],primes1[k],primes1[l],primes1[m]]))

n = now()




def pb60():
    c=0
    pairs = []
Exemplo n.º 5
0
def u_next_lax_friedrichs(u_last, delta_t, delta_x, j, time, position):
    return (u_last[j+1]+u_last[j-1])/2 - delta_t/(2*delta_x)*(func.f2(u_last[j+1])-func.f2(u_last[j-1])) \
           + delta_t*func.g2(u_last, delta_x, j)\
           + delta_t*func.s(time, position, u_last, j)
Exemplo n.º 6
0
def u_next_upwind(u_last, delta_t, delta_x, j, time, position):
    return u_last[j] - delta_t/delta_x*(func.f(u_last[j])-func.f(u_last[j-1])) \
           + delta_t*func.g(u_last, delta_x, j)\
           + delta_t*func.s(time, position, u_last, j)
Exemplo n.º 7
0
def u_next_half_step(u_last, delta_t, delta_x, j, time, position):
    return (u_last[j+1] + u_last[j] - delta_t /delta_x*(f(u_last[j+1]) - f(u_last[j])) \
           + delta_t*func.g3(u_last, delta_x, j)\
           + delta_t/2*(func.s(time, position, u_last, j+1)\
           +func.s(time, position, u_last, j)))/2
Exemplo n.º 8
0
def u_approx_mac_cormack(u_last, delta_t, delta_x, j, time, position):
    return u_last[j] - delta_t/delta_x*(func.f(u_last[j]) - func.f(u_last[j-1])) \
               + delta_t*func.g(u_last, delta_x, j)\
               + delta_t*func.s(time, position+delta_x, u_last, j)
Exemplo n.º 9
0
def u_next_mac_cormack(u_last, u_approx, delta_t, delta_x, j, time, position):
    return (u_approx[j]+u_last[j]- (delta_t)/(2*delta_x)*(func.f(u_approx[j+1])- func.f(u_approx[j]))\
            + delta_t*func.g(u_approx, delta_x, j)\
            + delta_t*func.s(time, position, u_approx, j))/2