Ejemplo n.º 1
0
#!/usr/bin/env python3
import sys
import math
import matplotlib.pyplot as plt
from collections import namedtuple as t
######################Helping definitions##########################
Point = t('Point', ['x', 'y'])

Line = t('Line', ['type', 'point', 'move', 'last'])

Intersection = t('Intersection', ['point', 'line_a', 'line_b'])


#######################Helping functions###########################
def data_parser(filepath):
    """
    Parse the data by splitting the line by commas, and making input
    to the char for dirrection, and int for the distance
    """
    with open(filepath, 'r') as f:
        wire1 = list([(x[0], int(x[1:])) for x in f.readline().split(",")])
        wire2 = list([(x[0], int(x[1:])) for x in f.readline().split(",")])
        return [wire1, wire2]


def plot_paths(line_list_list):
    """
    Plots a list of paths
    """
    fig, ax = plt.subplots()
    for line_list in line_list_list:
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-

from __future__ import print_function
from collections import namedtuple as t

# PubSub family
Publish = t('Publish', ['channel', 'message', 'callback'])
Subscribe = t(
    'Subscribe',
    ['channel_or_subscription_id', 'mode', 'observer', 'args'])
Unsubscribe = t('Unsubscribe', ['channel_or_subscription_id'])

# KV family
Read = t('Read', ['key', 'args', 'callback'])
Write = t('Write', ['key', 'value', 'callback'])
Delete = t('Delete', ['key', 'callback'])

# Search
Search = t('Search', ['prefix', 'callback'])

Authenticate = t('Authenticate', ['auth_delegate', 'callback'])

Start = t('Start', [])
Stop = t('Stop', [])
Dispose = t('Dispose', [])

ConnectingComplete = t('ConnectingComplete', [])
ConnectingFailed = t('ConnectingFailed', [])
ConnectionClosed = t('ConnectionClosed', [])
InternalError = t('InternalError', ['payload'])
Ejemplo n.º 3
0
              auth_ack.set()

      client.authenticate(role_auth_delegate, auth_callback)
      if not auth_ack.wait(10):
          raise RuntimeError('No authentication reply in reasonable time')

'''


from __future__ import print_function
from collections import namedtuple as t
import base64
import hashlib
import hmac

Authenticate = t('Authenticate', ['method', 'credentials', 'callback'])
AuthenticateOK = t('AuthenticateOK', [])
Handshake = t('Handshake', ['method', 'data', 'callback'])
HandshakeOK = t('HandshakeOK', ['data'])
Done = t('Done', [])
Error = t('Error', ['message'])


class AuthDelegate(object):
    def start(self):
        return Done()


class RoleSecretAuthDelegate(AuthDelegate):
    def __init__(self, role, role_secret):
        self.role = role
Ejemplo n.º 4
0
from collections import namedtuple as t

Str = t('Str', ['str'])
Num = t('Num', ['num'])
Id = t('Id', ['id'])
Bool = t('Bool', ['value'])
Decl = t('Decl', ['decl'])
Return = t('Return', ['expr'])
Assign = t('Assign', ['target', 'expr'])
Call = t('Call', ['callee', 'params'])
Index = t('Index', ['array', 'index'])
Func = t('Func', ['name', 'args', 'stmts'])
Stmts = t('Stmts', ['stmt', 'rest'])
If = t('If', ['condition', 'then', 'otherwise'])
While = t('While', ['condition', 'do'])
Ejemplo n.º 5
0
#!/usr/bin/env python3
import sys
import math
from collections import namedtuple as t
######################Helping definitions##########################
Planet = t('Planet', [
    'name',
    'parent',
    'child'
])

Orbit = t('Orbit', [
    'center',
    'child'
])

Traversal = t('Traversal', [
        'seen',
        'depth'
    ])
#######################Helping functions###########################
def data_parser(filepath):
    """
    Parse the data by splitting the line by commas, and making input
    to ints
    """
    orbit_list = []
    with open(filepath, 'r') as f:
        for line in f:
            center,orbit = line.split(")")
            orbit_list.append(Orbit(center.rstrip(),orbit.rstrip()))
#!/usr/bin/env python3

from collections import namedtuple as t
import json
import os
from subprocess import Popen, PIPE
import time

from test.utils import get_test_endpoint_and_appkey
_, test_appkey = get_test_endpoint_and_appkey()

PubAckConfig = t('PubAckConfig', ['size', 'tls', 'accel'])
PubNoAckConfig = t('PubNoAckConfig', ['size', 'tls', 'accel'])
SubConfig = t('SubConfig', ['size', 'tls', 'accel'])

ws_endpoint = "ws://rtm.local/"
wss_endpoint = "wss://rtm.local/"
script_dir = os.path.dirname(os.path.realpath(__file__))

sizes = [128, 512, 1024]
duration = 60
channel = 'py'

channel = 'lol'


def main():
    config_list = list(configs())
    for i, conf in enumerate(config_list):
        print('Bench {} out of {}'.format(i + 1, len(config_list)))
        cmd = conf_to_cmd(conf)
Ejemplo n.º 7
0
#!/usr/bin/env python3
import sys
import math
from collections import namedtuple as t
######################Helping definitions##########################
Range = t('Range', ['start', 'stop'])


#######################Helping functions###########################
def data_parser(filepath):
    """
    Parse the data by splitting the line by commas, and making input
    to the char for dirrection, and int for the distance
    """
    with open(filepath, 'r') as f:
        range_from, range_to = f.readline().split("-")
        return Range(int(range_from), int(range_to))


#########################Main functions############################
def solver_1star(d):
    """
    Test the conditions for each number, and accumulate in a loop
    """
    counter = 0
    for number in range(d.start, d.stop):
        have_pair = False
        never_decrease = True
        last_seen_digit = -1
        for digit in [int(i) for i in str(number)]:
Ejemplo n.º 8
0
from collections import defaultdict as t
F = lambda: [int(i) for i in input().split()]
n, x = F()
a = F()
d = t(int)
s = 0
c = 0
for i in a:
    s += i
    if s == x: c += 1
    if s - x in d:
        c += d[s - x]
    d[s] += 1
print(c)