content stringlengths 7 1.05M |
|---|
'''A confederação nacional de natacao precisa de um programa que leia o ano de nascimento de um atleta
e mostre sua categoria, de acordo com a idade
até 9 anos> MIRIM
até 14 anos: INFANTIL
até 19 anos JUNIOR
até 20 anos SENIOR
acima: MASTER''' |
# Q1
class Thing:
pass
example = Thing()
print(Thing)
print(example)
# Q2
class Thing2:
letters = 'abc'
print(Thing2.letters)
# Q3
class Thing3:
def __init__(self):
self.letters = 'xyz'
thing3 = Thing3()
print(thing3.letters)
# Q4
class Element:
def __init__(self, name, symbol, number):
self.name = name
self.symbol = symbol
self.number = number
hydrogen = Element('Hydrogen', 'H', 1)
# Q5
kargs = {'name': 'Hydrogen', 'symbol': 'H', 'number': 1}
hydrogen = Element(**kargs)
# Q6
class Element:
def __init__(self, name, symbol, number):
self.name = name
self.symbol = symbol
self.number = number
def dump(self):
print(f'Name:{self.name}, Symbol:{self.symbol}, Number:{self.number}')
hydrogen = Element('Hydrogen', 'H', 1)
hydrogen.dump()
# Q7
class Element:
def __init__(self, name, symbol, number):
self.name = name
self.symbol = symbol
self.number = number
def __str__(self):
return f'Name:{self.name}, Symbol:{self.symbol}, Number:{self.number}'
hydrogen = Element('Hydrogen', 'H', 1)
print(hydrogen)
# Q9
class Element:
def __init__(self, name, symbol, number):
self.__name = name
self.__symbol = symbol
self.__number = number
@property
def name(self):
return self.__name
@property
def symbol(self):
return self.__symbol
@property
def number(self):
return self.__number
def __str__(self):
return f'Name:{self.__name}, Symbol:{self.__symbol}, Number:{self.__number}'
# Q9
class Bear:
def eats(self):
return 'berries'
class Rabbit:
def eats(self):
return 'clover'
class Octothorpe:
def eats(self):
return 'campers'
bear = Bear()
rabbit = Rabbit()
octothorpe = Octothorpe()
bear.eats()
rabbit.eats()
octothorpe.eats()
# Q10
class Lasor:
def does(self):
return 'disintegrate'
class Claw:
def does(self):
return 'crush'
class SmartPhone:
def does(self):
return 'ring'
class Robot:
def __init__(self):
self.lasor = Lasor()
self.claw = Claw()
self.smartPhone = SmartPhone()
def does(self):
print(f'{self.lasor.does()} {self.claw.does()} {self.smartPhone.does()}')
robot = Robot()
robot.does()
|
j = 7
for i in range(1,(10),2):
for jump in range(0,3):
print("I={0} J={1}".format(i,j))
j = j - 1
j = 7
|
# def welcome():
# return 'Welcome to the Python' # basic function
#
# def uppercase_decorator(function): # parameter function
# def wrapper(): # function inside of uppercase
# func = function() # variable == function()
# make_uppercase = func.upper() # transforma o retorno da função chamada em upper
# return make_uppercase # retorno do retorno da função em CAPS
# return wrapper # chama a função wrapper que ira retornar o acima return make_uppercase
#
#
# g = uppercase_decorator(welcome) # chama a função com outra função e returna para 'g'
# print(g())
# Example below with decorator
def uppercase_decorator(function):
def wrapper():
func = function()
make_upper = func.upper()
return make_upper
return wrapper
@uppercase_decorator
def welcome():
return 'Hello Friend.'
print(welcome())
|
result = [
[0.6, 0.7],
{'a': 'b'},
None,
[
'uu',
'ii',
[None],
[7, 8, 9, {}]
]
]
|
def DependsOn(pack, deps):
return And([ Implies(pack, dep) for dep in deps ])
def Conflict(p1, p2):
return Or(Not(p1), Not(p2))
a, b, c, d, e, f, g, z = Bools('a b c d e f g z')
solve(DependsOn(a, [b, c, z]),
DependsOn(b, [d]),
DependsOn(c, [Or(d, e), Or(f, g)]),
Conflict(d, e),
a, z)
|
#
# PySNMP MIB module SW-LAYER2-PORT-MANAGEMENT-MIB (http://snmplabs.com/pysmi)
# ASN.1 source file:///Users/davwang4/Dev/mibs.snmplabs.com/asn1/SW-LAYER2-PORT-MANAGEMENT-MIB
# Produced by pysmi-0.3.4 at Wed May 1 15:12:34 2019
# On host DAVWANG4-M-1475 platform Darwin version 18.5.0 by user davwang4
# Using Python version 3.7.3 (default, Mar 27 2019, 09:23:15)
#
Integer, OctetString, ObjectIdentifier = mibBuilder.importSymbols("ASN1", "Integer", "OctetString", "ObjectIdentifier")
NamedValues, = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues")
ConstraintsUnion, ValueRangeConstraint, SingleValueConstraint, ValueSizeConstraint, ConstraintsIntersection = mibBuilder.importSymbols("ASN1-REFINEMENT", "ConstraintsUnion", "ValueRangeConstraint", "SingleValueConstraint", "ValueSizeConstraint", "ConstraintsIntersection")
NotificationGroup, ModuleCompliance = mibBuilder.importSymbols("SNMPv2-CONF", "NotificationGroup", "ModuleCompliance")
TimeTicks, MibIdentifier, NotificationType, Integer32, NotificationType, Unsigned32, MibScalar, MibTable, MibTableRow, MibTableColumn, IpAddress, iso, ModuleIdentity, Counter32, Gauge32, Bits, ObjectIdentity, enterprises, Counter64 = mibBuilder.importSymbols("SNMPv2-SMI", "TimeTicks", "MibIdentifier", "NotificationType", "Integer32", "NotificationType", "Unsigned32", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "IpAddress", "iso", "ModuleIdentity", "Counter32", "Gauge32", "Bits", "ObjectIdentity", "enterprises", "Counter64")
DisplayString, TextualConvention = mibBuilder.importSymbols("SNMPv2-TC", "DisplayString", "TextualConvention")
marconi = MibIdentifier((1, 3, 6, 1, 4, 1, 326))
systems = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2))
external = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20))
dlink = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1))
dlinkcommon = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 1))
golf = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2))
golfproducts = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 1))
es2000 = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 1, 3))
golfcommon = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2))
marconi_products = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 1)).setLabel("marconi-products")
marconi_es2000Prod = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 1, 28)).setLabel("marconi-es2000Prod")
swProperty = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 1, 28, 1))
marconi_mgmt = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2)).setLabel("marconi-mgmt")
es2000Mgmt = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28))
swL2Mgmt = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2))
swL2PortMgmt = MibIdentifier((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4))
swL2PortInfoTable = MibTable((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1), )
if mibBuilder.loadTexts: swL2PortInfoTable.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoTable.setDescription('A table that contains information about every port.')
swL2PortInfoEntry = MibTableRow((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1, 1), ).setIndexNames((0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoUnitIndex"), (0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoModuleIndex"), (0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoIndex"))
if mibBuilder.loadTexts: swL2PortInfoEntry.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoEntry.setDescription('A list of information for each port of the device.')
swL2PortInfoUnitIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1, 1, 1), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortInfoUnitIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoUnitIndex.setDescription('Indicates ID of the unit in the device.')
swL2PortInfoModuleIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1, 1, 2), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortInfoModuleIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoModuleIndex.setDescription('Indicates ID of the module on the unit.')
swL2PortInfoIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1, 1, 3), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortInfoIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoIndex.setDescription('Indicates ID of the port on the module.')
swL2PortInfoType = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1, 1, 4), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4, 5, 6, 7))).clone(namedValues=NamedValues(("portType-100TX", 1), ("portType-100FX", 2), ("portType-GIGA-MTRJSX", 3), ("portType-GIGA-MTRJLX", 4), ("portType-GIGA-SCSX", 5), ("portType-GIGA-SCLX", 6), ("other", 7)))).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortInfoType.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoType.setDescription('Indicates the connector type of this port.')
swL2PortInfoDescr = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1, 1, 5), DisplayString().subtype(subtypeSpec=ValueSizeConstraint(0, 64))).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortInfoDescr.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoDescr.setDescription('Provides port type information in displayed string format.')
swL2PortInfoLinkStatus = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1, 1, 6), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3))).clone(namedValues=NamedValues(("other", 1), ("link-pass", 2), ("link-fail", 3)))).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortInfoLinkStatus.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoLinkStatus.setDescription('Indicates port link status.')
swL2PortInfoNwayStatus = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 1, 1, 7), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4, 5, 6, 7))).clone(namedValues=NamedValues(("other", 1), ("half-10Mbps", 2), ("full-10Mbps", 3), ("half-100Mbps", 4), ("full-100Mbps", 5), ("half-1Gigabps", 6), ("full-1Gigabps", 7)))).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortInfoNwayStatus.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortInfoNwayStatus.setDescription('This object indicates the port speed and duplex mode.')
swL2PortCtrlTable = MibTable((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2), )
if mibBuilder.loadTexts: swL2PortCtrlTable.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlTable.setDescription('A table that contains control information about every port.')
swL2PortCtrlEntry = MibTableRow((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1), ).setIndexNames((0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortCtrlUnitIndex"), (0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortCtrlModuleIndex"), (0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortCtrlIndex"))
if mibBuilder.loadTexts: swL2PortCtrlEntry.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlEntry.setDescription('A list of control information for each port of the device.')
swL2PortCtrlUnitIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 1), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortCtrlUnitIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlUnitIndex.setDescription('Indicates ID of the unit in the device.')
swL2PortCtrlModuleIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 2), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortCtrlModuleIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlModuleIndex.setDescription('Indicates ID of the module on the unit.')
swL2PortCtrlIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 3), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortCtrlIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlIndex.setDescription('This object indicates the device port number.(1..Max port number).')
swL2PortCtrlAdminState = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 4), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4))).clone(namedValues=NamedValues(("other", 1), ("disabled", 2), ("enabled", 3), ("notAvailable", 4)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlAdminState.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlAdminState.setDescription('This object decides the port to be enabled or disabled.')
swL2PortCtrlLinkStatusAlarmState = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 5), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4))).clone(namedValues=NamedValues(("other", 1), ("disabled", 2), ("enabled", 3), ("notAvailable", 4)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlLinkStatusAlarmState.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlLinkStatusAlarmState.setDescription('Depends on this object to determine to send a trap or not when link status changes.')
swL2PortCtrlNwayState = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 6), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4, 5, 6, 7, 8, 10))).clone(namedValues=NamedValues(("other", 1), ("nway-enabled", 2), ("nway-disabled-10Mbps-Half", 3), ("nway-disabled-10Mbps-Full", 4), ("nway-disabled-100Mbps-Half", 5), ("nway-disabled-100Mbps-Full", 6), ("nway-disabled-1Gigabps-Half", 7), ("nway-disabled-1Gigabps-Full", 8), ("notAvailable", 10)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlNwayState.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlNwayState.setDescription('Chooses the port speed, duplex mode, and N-Way function mode.')
swL2PortCtrlFlowCtrlState = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 7), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3))).clone(namedValues=NamedValues(("other", 1), ("disabled", 2), ("enabled", 3)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlFlowCtrlState.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlFlowCtrlState.setDescription('Sets IEEE 802.3x compliant flow control function as enabled or disabled. And IEEE 802.3x compliant flow control function work only when the port is in full duplex mode.The setting is effective the next time you reset or power on the hub.')
swL2PortCtrlBackPressState = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 8), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3))).clone(namedValues=NamedValues(("other", 1), ("disabled", 2), ("enabled", 3)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlBackPressState.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlBackPressState.setDescription('Depends on this object to determine to enable or disable the backpressure function when the port is working in half duplex mode.')
swL2PortCtrlLockState = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 9), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4))).clone(namedValues=NamedValues(("other", 1), ("disable", 2), ("enable", 3), ("notAvailable", 4)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlLockState.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlLockState.setDescription('The state of this entry. The meanings of the values are: other(1) - this entry is currently in use but the conditions under which it will remain so are different from each of the following values. disable(2) - Port lock funtion disable. enable(3) - Locking a port provides the CPU with the ability to decide which address are permitted to reside on such port, who knows about these address, and unknown packet forwarding to/from such ports. This is a way to prevent undesired traffic from being received or transmmited on the port.')
swL2PortCtrlPriority = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 10), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4, 5))).clone(namedValues=NamedValues(("other", 1), ("default", 2), ("force-low-priority", 3), ("force-high-priority", 4), ("notAvailable", 5)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlPriority.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlPriority.setDescription('The priority queueing for packets received on this port, except for BPDU/IGMP packets and packets with unknown unicast destination address. IGMP and BPDU packets are always routed with high priority; packets with unknown unicast destination addresses are always routed with low priority. Other packets follow the rules below: other(1) - this entry is currently in use but the conditions under which it will remain so are different from each of the following values. default(2) - A packet is normally classified as low priority, unless at least one of the following is true: (a)The packet contained a TAG (per 802.1Q definition) with the priority greater or equal to 4. (b)The address-table entry for the destination address had Pd=HIGH. force-low_priority(3) - A packet is normally classified as low priority. force-high_priority(4) - A packet is normally classified as high priority.')
swL2PortCtrlStpState = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 11), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4))).clone(namedValues=NamedValues(("other", 1), ("disabled", 2), ("enabled", 3), ("notAvailable", 4)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlStpState.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlStpState.setDescription("The state of STP(spanning tree algorithm) operation on this port. That's meaning the port whether add in the STP. The value enabled(3) indicates that STP is enabled on this port, as long as swDevCtrlStpState is also enabled for this device. When disabled(2) but swDevCtrlStpState is still enabled for the device, STP is disabled on this port : any BPDU packets received will be discarded and no BPDU packets will be propagated from the port.")
swL2PortCtrlHOLState = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 12), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4))).clone(namedValues=NamedValues(("other", 1), ("disabled", 2), ("enabled", 3), ("notAvailable", 4)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlHOLState.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlHOLState.setDescription("The object provides a way to prevent HOL (Head Of Line) blocking between ports. HOL protection may prevent forwarding a packet to a blocking port. The idea relies on the assumption that it is better to discard packets destined to blocking ports, then to let them consume more and more buffers in the input-port's Rx-counters because eventually these input ports may become totally blocked. The meanings of the values are: other(1) - this entry is currently in use but the conditions under which it will remain so are different from each of the following values. disabled(2) - HOL function disable. enabled(3) - HOL function enable.")
swL2PortCtrlBcastRisingAct = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 13), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4, 5))).clone(namedValues=NamedValues(("other", 1), ("do-nothing", 2), ("blocking", 3), ("blocking-trap", 4), ("notAvailable", 5)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlBcastRisingAct.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlBcastRisingAct.setDescription('This object indicates the system action when broadcast storm rising threshold is met. other(1) - this entry is currently in use but the conditions under which it will remain so are different from each of the following values. do-nothing(2) - no action. blocking(3) - the port can discard any coming broadcast frame. blocking-trap(4) - the port can discard any coming broadcast frame. And the device can send a broadcast rising trap.')
swL2PortCtrlBcastFallingAct = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 14), Integer32().subtype(subtypeSpec=ConstraintsUnion(SingleValueConstraint(1, 2, 3, 4, 5))).clone(namedValues=NamedValues(("other", 1), ("do-nothing", 2), ("forwarding", 3), ("forwarding-trap", 4), ("notAvailable", 5)))).setMaxAccess("readwrite")
if mibBuilder.loadTexts: swL2PortCtrlBcastFallingAct.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlBcastFallingAct.setDescription('This object indicates the device action when broadcast storm falling threshold is met. other(1) - this entry is currently in use but the conditions under which it will remain so are different from each of the following values. do-nothing(2) - no action. forwarding(3) - the port has returned to normal operation mode. forwarding-trap(4) - the port has returned to normal operation mode. And the device can send a broadcast falling trap.')
swL2PortCtrlClearCounter = MibScalar((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 2, 1, 15), Integer32()).setMaxAccess("writeonly")
if mibBuilder.loadTexts: swL2PortCtrlClearCounter.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortCtrlClearCounter.setDescription('Sets choosed port to clear counter. First of all, any unsigned integer can be used to set.')
swL2PortStTable = MibTable((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3), )
if mibBuilder.loadTexts: swL2PortStTable.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStTable.setDescription('A list of port statistic Counter entries.')
swL2PortStEntry = MibTableRow((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1), ).setIndexNames((0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortStUnitIndex"), (0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortStModuleIndex"), (0, "SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortStIndex"))
if mibBuilder.loadTexts: swL2PortStEntry.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStEntry.setDescription('This entry include all the port statistic Counter which support by the device, like Bytes received, Bytes Sent ...')
swL2PortStUnitIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 1), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStUnitIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStUnitIndex.setDescription('Indicates ID of the unit in the device.')
swL2PortStModuleIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 2), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStModuleIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStModuleIndex.setDescription('Indicates ID of the module on the unit.')
swL2PortStIndex = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 3), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStIndex.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStIndex.setDescription('This object indicates the device port number.(1..Max port number)')
swL2PortStByteRx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 4), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStByteRx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStByteRx.setDescription('swDevCtrlCounterMode = 2(switched-frames) : This counter is incremented once for every data octet of good packets(unicast + multicast + broadcast) received. swDevCtrlCounterMode = 3(all-frames) : This counter is incremented once for every data octet of good packets(unicast + multicast + broadcast packets) and for local and dropped packets.')
swL2PortStByteTx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 5), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStByteTx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStByteTx.setDescription('This counter is incremented once for every data octet of a transmitted good packet.')
swL2PortStFrameRx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 6), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFrameRx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFrameRx.setDescription('swDevCtrlCounterMode = 2(switched-frames) : This counter is incremented once for every good packet(unicast + multicast + broadcast) received. swDevCtrlCounterMode = 3(all-frames) : This counter is incremented once for every good packet(unicast + multicast + broadcast packets) and for local and dropped packets received.')
swL2PortStFrameTx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 7), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFrameTx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFrameTx.setDescription('This counter is incremented once for every transmitted good packet.')
swL2PortStTotalBytesRx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 8), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStTotalBytesRx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStTotalBytesRx.setDescription('This counter is incremented once for every data octet of all received packets. This include data octets of rejected and local packets which are not forwarded to the switching core for transmission. This counter should reflect all the data octets received on the line. Note: A nibble is not counted as a whole byte.')
swL2PortStTotalFramesRx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 9), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStTotalFramesRx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStTotalFramesRx.setDescription('This counter is incremented once for every received packets. This include rejected and local packets which are not forwarded to the switching core for transmission. This counter should reflect all packets received on the line.')
swL2PortStBroadcastFramesRx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 10), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStBroadcastFramesRx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStBroadcastFramesRx.setDescription('swDevCtrlCounterMode = 2(switched-frames) : This counter is incremented once for every good broadcast packet received. swDevCtrlCounterMode = 3(all-frames) : This counter is incremented once for every good broadcast packet received and for local and dropped broadcast packets.')
swL2PortStMulticastFramesRx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 11), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStMulticastFramesRx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStMulticastFramesRx.setDescription('swDevCtrlCounterMode = 2(switched-frames) : This counter is incremented once for every good multicast packet received. swDevCtrlCounterMode = 3(all-frames) : This counter is incremented once for every good multicast packet received and for local and dropped multicast packets. This counter does not include broadcast packets.')
swL2PortStCRCError = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 12), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStCRCError.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStCRCError.setDescription('This counter is incremented once for every received packet which meets all the following conditions: 1. Packet data length is between 64 and 1536 bytes inclusive. 2. Packet has invalid CRC. 3. Collision event, late collision event and receive error event have not been detected.')
swL2PortStOversizeFrames = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 13), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStOversizeFrames.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStOversizeFrames.setDescription('The number of good frames with length more than 1536 bytes.')
swL2PortStFragments = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 14), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFragments.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFragments.setDescription('This counter is incremented once for every received packet which meets all the following conditions: 1. Packet data length is less than 64 bytes or packet withourt SFD and is less than 64 bytes in length. 2. Packet has invalid CRC. 3. Collision event, late collision event and receive error event have not been detected.')
swL2PortStJabber = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 15), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStJabber.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStJabber.setDescription('The number of frames with length more than 1536 bytes and with CRC error or misaligned.')
swL2PortStCollision = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 16), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStCollision.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStCollision.setDescription('The number of Collisions.')
swL2PortStLateCollision = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 17), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStLateCollision.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStLateCollision.setDescription('The number of Late Collision(collision occurring later than 576th transmitted bit).')
swL2PortStFrames_64_bytes = MibScalar((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 18), Counter32()).setLabel("swL2PortStFrames-64-bytes").setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFrames_64_bytes.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFrames_64_bytes.setDescription('This counter is incremented once for every received and transmitted packet with size of 64 bytes. This counter includes rejected received and transmitted packets.')
swL2PortStFrames_65_127_bytes = MibScalar((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 19), Counter32()).setLabel("swL2PortStFrames-65-127-bytes").setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFrames_65_127_bytes.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFrames_65_127_bytes.setDescription('This counter is incremented once for every received and transmitted packet with size of 65 to 127 bytes. This counter includes rejected received and transmitted packets.')
swL2PortStFrames_128_255_bytes = MibScalar((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 20), Counter32()).setLabel("swL2PortStFrames-128-255-bytes").setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFrames_128_255_bytes.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFrames_128_255_bytes.setDescription('This counter is incremented once for every received and transmitted packet with size of 128 to 255 bytes. This counter includes rejected received and transmitted packets.')
swL2PortStFrames_256_511_bytes = MibScalar((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 21), Counter32()).setLabel("swL2PortStFrames-256-511-bytes").setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFrames_256_511_bytes.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFrames_256_511_bytes.setDescription('This counter is incremented once for every received and transmitted packet with size of 256 to 511 bytes. This counter includes rejected received and transmitted packets.')
swL2PortStFrames_512_1023_bytes = MibScalar((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 22), Counter32()).setLabel("swL2PortStFrames-512-1023-bytes").setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFrames_512_1023_bytes.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFrames_512_1023_bytes.setDescription('This counter is incremented once for every received and transmitted packet with size of 512 to 1023 bytes. This counter includes rejected received and transmitted packets.')
swL2PortStFrames_1024_1536_bytes = MibScalar((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 23), Counter32()).setLabel("swL2PortStFrames-1024-1536-bytes").setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFrames_1024_1536_bytes.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFrames_1024_1536_bytes.setDescription('This counter is incremented once for every received and transmitted packet with size of 1024 to 1536 bytes. This counter includes rejected received and transmitted packets.')
swL2PortStFramesDroppedFrames = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 24), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStFramesDroppedFrames.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStFramesDroppedFrames.setDescription('This counter is incremented once for every received dropped packet.')
swL2PortStMulticastFramesTx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 25), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStMulticastFramesTx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStMulticastFramesTx.setDescription('The number of multicast frames sent. This counter does not include broadcast packets.')
swL2PortStBroadcastFramesTx = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 26), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStBroadcastFramesTx.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStBroadcastFramesTx.setDescription('The number of broadcast frames sent.')
swL2PortStUndersizeFrames = MibTableColumn((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 2, 2, 28, 2, 4, 3, 1, 27), Counter32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: swL2PortStUndersizeFrames.setStatus('mandatory')
if mibBuilder.loadTexts: swL2PortStUndersizeFrames.setDescription('This counter is incremented once for every received packet which meets all the following conditions: 1. Packet data length is less than 64 bytes. 2. Packet has valid CRC. 3. Collision event, late collision event and receive error event have not been detected.')
swEventPortPartition = NotificationType((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 1, 3) + (0,1)).setObjects(("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoUnitIndex"), ("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoModuleIndex"), ("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoIndex"))
if mibBuilder.loadTexts: swEventPortPartition.setDescription('The trap is sent whenever the port state enter the Partion mode when more than 61 collisions occur while trasmitting.')
swEventlinkChangeEvent = NotificationType((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 1, 3) + (0,2)).setObjects(("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoUnitIndex"), ("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoModuleIndex"), ("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoIndex"))
if mibBuilder.loadTexts: swEventlinkChangeEvent.setDescription('The trap is sent whenever the link state of a port changes from link up to link down or from link down to link up')
swEventBcastRisingStorm = NotificationType((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 1, 3) + (0,3)).setObjects(("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoUnitIndex"), ("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoModuleIndex"), ("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoIndex"))
if mibBuilder.loadTexts: swEventBcastRisingStorm.setDescription('The trap indicates that broadcast higher rising threshold. This trap including the port ID')
swEventBcastFallingStorm = NotificationType((1, 3, 6, 1, 4, 1, 326, 2, 20, 1, 2, 1, 3) + (0,4)).setObjects(("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoUnitIndex"), ("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoModuleIndex"), ("SW-LAYER2-PORT-MANAGEMENT-MIB", "swL2PortInfoIndex"))
if mibBuilder.loadTexts: swEventBcastFallingStorm.setDescription('The trap indicates that broadcast higher falling threshold. This trap including the port ID')
mibBuilder.exportSymbols("SW-LAYER2-PORT-MANAGEMENT-MIB", swL2PortStCRCError=swL2PortStCRCError, swL2PortStFrames_1024_1536_bytes=swL2PortStFrames_1024_1536_bytes, swL2PortCtrlModuleIndex=swL2PortCtrlModuleIndex, swL2PortStLateCollision=swL2PortStLateCollision, swL2PortStOversizeFrames=swL2PortStOversizeFrames, systems=systems, swL2PortInfoTable=swL2PortInfoTable, golfcommon=golfcommon, swL2PortCtrlAdminState=swL2PortCtrlAdminState, swL2PortStByteRx=swL2PortStByteRx, swL2PortCtrlEntry=swL2PortCtrlEntry, es2000=es2000, swL2PortStFragments=swL2PortStFragments, swL2Mgmt=swL2Mgmt, swL2PortCtrlClearCounter=swL2PortCtrlClearCounter, swL2PortStJabber=swL2PortStJabber, dlinkcommon=dlinkcommon, es2000Mgmt=es2000Mgmt, swL2PortInfoNwayStatus=swL2PortInfoNwayStatus, swL2PortStUnitIndex=swL2PortStUnitIndex, swL2PortInfoUnitIndex=swL2PortInfoUnitIndex, swL2PortStFrames_128_255_bytes=swL2PortStFrames_128_255_bytes, swL2PortStModuleIndex=swL2PortStModuleIndex, swL2PortCtrlStpState=swL2PortCtrlStpState, marconi=marconi, swL2PortCtrlLockState=swL2PortCtrlLockState, swL2PortInfoType=swL2PortInfoType, swL2PortStTotalBytesRx=swL2PortStTotalBytesRx, swL2PortStTable=swL2PortStTable, swL2PortMgmt=swL2PortMgmt, swL2PortInfoIndex=swL2PortInfoIndex, swEventBcastFallingStorm=swEventBcastFallingStorm, swL2PortStMulticastFramesRx=swL2PortStMulticastFramesRx, swL2PortStFramesDroppedFrames=swL2PortStFramesDroppedFrames, swL2PortStFrames_64_bytes=swL2PortStFrames_64_bytes, swL2PortStMulticastFramesTx=swL2PortStMulticastFramesTx, swL2PortCtrlFlowCtrlState=swL2PortCtrlFlowCtrlState, marconi_products=marconi_products, swL2PortStFrames_65_127_bytes=swL2PortStFrames_65_127_bytes, swL2PortStUndersizeFrames=swL2PortStUndersizeFrames, swL2PortStBroadcastFramesTx=swL2PortStBroadcastFramesTx, dlink=dlink, swL2PortStEntry=swL2PortStEntry, external=external, golfproducts=golfproducts, swL2PortStIndex=swL2PortStIndex, swL2PortStFrameRx=swL2PortStFrameRx, marconi_mgmt=marconi_mgmt, golf=golf, swL2PortInfoLinkStatus=swL2PortInfoLinkStatus, swL2PortCtrlTable=swL2PortCtrlTable, swL2PortCtrlLinkStatusAlarmState=swL2PortCtrlLinkStatusAlarmState, swL2PortCtrlHOLState=swL2PortCtrlHOLState, swL2PortCtrlBackPressState=swL2PortCtrlBackPressState, swL2PortStByteTx=swL2PortStByteTx, swL2PortStTotalFramesRx=swL2PortStTotalFramesRx, swL2PortStFrames_256_511_bytes=swL2PortStFrames_256_511_bytes, swEventBcastRisingStorm=swEventBcastRisingStorm, swL2PortCtrlUnitIndex=swL2PortCtrlUnitIndex, swL2PortStFrames_512_1023_bytes=swL2PortStFrames_512_1023_bytes, swL2PortInfoModuleIndex=swL2PortInfoModuleIndex, swL2PortCtrlBcastFallingAct=swL2PortCtrlBcastFallingAct, swL2PortStFrameTx=swL2PortStFrameTx, swL2PortInfoEntry=swL2PortInfoEntry, swProperty=swProperty, swL2PortStBroadcastFramesRx=swL2PortStBroadcastFramesRx, swEventPortPartition=swEventPortPartition, marconi_es2000Prod=marconi_es2000Prod, swEventlinkChangeEvent=swEventlinkChangeEvent, swL2PortStCollision=swL2PortStCollision, swL2PortCtrlBcastRisingAct=swL2PortCtrlBcastRisingAct, swL2PortInfoDescr=swL2PortInfoDescr, swL2PortCtrlPriority=swL2PortCtrlPriority, swL2PortCtrlNwayState=swL2PortCtrlNwayState, swL2PortCtrlIndex=swL2PortCtrlIndex)
|
# -*- coding: utf-8 -*-
if 1 == 1:
print ("1 é igual a 1")
if not 1 == 2:
print ("1 é diferente de 2")
if True:
print ("Bloco True executado")
if False:
print ("Bloco False não será executado") |
'''Uma empresa decidiu fazer um levantamento em relação aos candidatos que se apresentarem para preenchi- mento de vagas em seu quadro de funcionários. Supondo que você seja o programador dessa empresa, faça um programa que leia, para cada candidato, a idade, o sexo (M ou F), e a experiência no serviço (S ou N). Para encerrar a entrada de dados, digite a idade igual a zero. O programa também deve calcular e mostrar:¶
O número de candidatos do sexo feminino.
O número de candidatos do sexo masculino.
A idade média dos homens que já tem experiência no serviço.
A porcentagem dos homens com mais de 45 anos entre o total dos homens.
O número de mulheres com idade inferior a 21 anos e com experiência no serviço.
A menor idade entre as mulheres que já tem experiência no serviço.'''
menor_idade_fem = 150
quant_fem = 0
quant_exp_fem = 0
quant_masc = 0
quant_exp_masc = 0
quant_idade_masc = 0
soma_idade_masc = 0
while True:
idade = int(input('Digite a sua idade: '))
if idade == 0:
break
sexo = input("Digite o seu sexo (M ou F)\n")
experiencia = input("Têm experiência no serviço (S ou N)\n")
if sexo == "F":
quant_fem = quant_fem + 1
if experiencia == "S":
if menor_idade_fem > idade:
menor_idade_fem = idade
if idade <= 21:
quant_exp_fem = quant_exp_fem + 1
if sexo == "M":
quant_masc = quant_masc + 1
if experiencia == "S":
soma_idade_masc = soma_idade_masc + idade
quant_exp_masc = quant_exp_masc + 1
if (idade >= 45):
quant_idade_masc = quant_idade_masc + 1
if quant_fem == 0:
menor_idade_fem = 0
print(f'O número de candidatos do sexo feminino: {quant_fem}')
print(f'O número de candidatos do sexo masculino: {quant_masc}')
print(
f'A idade média dos homens que já tem experiência no serviço: {soma_idade_masc / quant_exp_masc}')
print(
f'A porcentagem dos homens com mais de 45 anos entre o total dos homens: {quant_idade_masc}')
print(
f'O número de mulheres com idade inferior a 21 anos e com experiência no serviço: {quant_exp_fem}')
print(
f'A menor idade entre as mulheres que já tem experiência no serviço: {menor_idade_fem}') |
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: sample_11.1
Description :
date: 2022/2/18
-------------------------------------------------
"""
class Vector2d:
typecode = 'd'
def __init__(self, x, y):
self.x = float(x)
self.y = float(y)
def __iter__(self):
return (i for i in (self.x, self.y))
|
class Queue:
# Constructor to initiate queue
def __init__(self, queue=None):
if queue is None:
queue = []
self.queue = queue
# push to append an item into queue
def push(self, value):
self.queue.append(value)
# front to return starting element from queue
def front(self):
if Queue.empty(self) is False:
return self.queue[0]
else:
raise IndexError("You are trying to front in an empty queue.")
# pop to remove front element from queue
def pop(self):
if Queue.empty(self) is False:
self.queue.pop(0)
else:
raise IndexError("You are trying to pop in an empty queue.")
# to check queue size
def size(self):
return len(self.queue)
# to check queue is empty or not
def empty(self):
if self.size() > 0:
return False
else:
return True
# to see elements of queue
def display(self):
return self.queue
|
class EnumType(object):
# Internal data storage uses integer running from 0 to range_end
# range_end is set to the number of possible values that the Enum can take on
# External representation of Enum starts at 1 and goes to range_end + 1
def __init__(self, initial_value):
self.set(initial_value)
def load_json(self, json_struct):
self.set(json_struct)
def json_serializer(self):
# Returns a string
# This could be changed to encode enums as integers when transmitting messages
if self.value < 0:
return None
else:
return type(self).possible_values[self.value]
def __str__(self):
return str(self.json_serializer())
def get(self):
# Returns an integer, using the external representation
return self.value + 1
def set(self, value):
# The value to set can be either a string or an integer
if type(value) is str:
# This will raise ValueError for wrong assignments
try:
self.value = type(self).possible_values.index(value)
except ValueError:
raise ValueError('', value, type(self).possible_values)
elif type(value) is int:
if value >= 0 and value <= type(self).range_end:
# External representation of Enum starts at 1, internal at 0. External value 0 by default
# to indicate empty object.
value = value - 1
self.value = value
else:
raise ValueError('', value, type(self).range_end)
else:
raise TypeError('', value, 'string or integer')
|
# -*- coding: utf-8 -*-
#
class LineLoop(object):
_ID = 0
dimension = 1
def __init__(self, lines):
self.lines = lines
self.id = 'll{}'.format(LineLoop._ID)
LineLoop._ID += 1
self.code = '\n'.join([
'{} = newll;'.format(self.id),
'Line Loop({}) = {{{}}};'.format(
self.id, ', '.join([l.id for l in lines])
)])
return
def __len__(self):
return len(self.lines)
|
# Binary search
def binary_search(A: list, x: int):
i = 0
j = len(A)
while i < j:
m = (i + j) // 2
if A[m] == x:
return True
elif A[m] > x:
j = m
else:
i = m + 1
return False
def recursive_binary_search(A: list, x: int, start: int, end: int):
if end >= start:
m = start + (end - start) // 2
if A[m] == x:
return m
elif A[m] > m:
return recursive_binary_search(A, start, m - 1, x)
else:
return recursive_binary_search(A, m + 1, end, x)
else:
return -1 |
class BaseDBDriver():
"""
This will stub the most basic methods that a GraphDB driver must have.
"""
_connected = False
_settings = {}
def __init__(self, dbapi):
self.dbapi = dbapi
def _debug(self, *args):
if self.debug:
print ("[GraphDB #%x]:" % id(self), *args)
def _debugOut(self, *args):
self._debug("OUT --> ", *args)
def _debugIn(self, *args):
self._debug("IN <-- ", *args)
def connect(self):
"""
Performs connection to the database service.
connect() -> self
"""
raise NotImplementedError('Not Implemented Yet')
def query(self, sql):
"""
Performs a query to the database.
query( sql ) -> dict
"""
raise NotImplementedError('Not Implemented Yet')
def disconnect(self):
"""
Performs disconnection and garbage collection for the driver.
connect() -> self
"""
raise NotImplementedError('Not Implemented Yet')
class BaseEdgeDriver(object):
"""
Base driver for managing Edges.
This will provide CRUD & search operations to be extended by
drivers.
"""
def __init__(self, driver):
self.driver = driver
def create(self, eType, origin, destiny, data = {}):
"""
create(eType, origin, destiny [, data]) -> dict
Creates an edge from *origin* to *destiny*
"""
raise NotImplementedError('Not Implemented Yet')
def update(self, eType, criteria = {}, data = {}):
"""
update(eType [, criteria [, data]]) -> dict
Update edges mathing a given criteria
"""
raise NotImplementedError('Not Implemented Yet')
def delete(self, eType, criteria = {}):
"""
delete(eType [, criteria]) -> dict
Delete edges mathing a given criteria
"""
raise NotImplementedError('Not Implemented Yet')
def find(self, eType, criteria = {}):
"""
find(eType [, criteria]) -> list
Find an edge for a given criteria.
"""
raise NotImplementedError('Not Implemented Yet')
class BaseVertexDriver(object):
"""
Base driver for managing Vertexes.
This will provide CRUD & search operations to be extended by
drivers.
"""
def __init__(self, driver):
self.driver = driver
def create(self, vType, data = {}):
"""
create(vType, [, data]) -> dict
Create a Vertex
"""
raise NotImplementedError('Not Implemented Yet')
def update(self, vType, criteria = {}, data = {}):
"""
update(vType, criteria, data) -> dict
Update a Vertex given a criteria
"""
raise NotImplementedError('Not Implemented Yet')
def delete(self, vType, criteria = {}):
"""
delete(vType, criteria) -> dict
Delete a Vertex given a criteria
"""
raise NotImplementedError('Not Implemented Yet')
def find(self, vType, criteria = None):
"""
find(vType [, criteria]) -> list
Look for vertexes matching criteria.
"""
raise NotImplementedError('Not Implemented Yet')
|
class Solution:
def numberOfLines(self, widths: List[int], s: str) -> List[int]:
s = list(s); lines = 1; line = 0
while s:
if line + widths[ord(s[0])-97] > 100:
lines += 1; line = 0
else:
line += widths[ord(s.pop(0))-97]
return [lines, line] |
Lakh = 100 * 1000
Crore = 100 * Lakh
biggerNumbers = {
100 : "sau",
1000 : "hazaar",
Lakh : "laakh",
Crore : "karoD"
}
|
class Match:
def __init__(self):
self.date = ""
self.round = ""
self.tournament = ""
self.home = ""
self.score = ""
self.away = ""
self.channels = ""
|
#پروژه بانک
#نوشته شده توسط امیر حسین غرقی
class Bank:
def Create(self):
self.first_name = input( 'Enter first name : ')
self.last_name = input("Enter your last name : ")
self.phone_number = input("Enter your phone number, sample : 0912*****54 :")
self.value = float(input("Enter your start value : "))
while self.value < 0 :
print("First value can not be negative !")
self.value = float(input("Enter your start value : "))
def Add(self):
self.to_add = float(input("How much do you want to add? "))
while self.to_add < 0 :
print("Can't be negative! try again ")
self.to_add = float(input("How much do you want to add? "))
self.value += self.to_add
print ("your balance is :", self.value)
def Sub(self):
self.sub_from = float(input("how much do you want to take? "))
while self.sub_from < 0 and self.sub_from > self.value:
print("Cant be negative! try again ")
self.sub_from = float(input("how much do you want to take? "))
self.value -= self.sub_from
print ("your balance is :", self.value)
def Show(self):
print(self.first_name, self.last_name,"phone number", self.phone_number,"account balance", self.value)
#------main---------------------------------
print("""
Wellcome
here are your choices:)
press 1 to create an account;
press 2 to deposit to your account;
press 3 to withdraw from the account
press 4 to show your info;
press 0 to exit;
""")
customer = Bank()
while True :
print("""
Wellcome
here are your choices:)
press 1 to create an account;
press 2 to deposit to your account;
press 3 to withdraw from the account
press 4 to show your info;
press 0 to exit;
""")
menu = int(input(""))
if menu == 1:
customer.Create()
elif menu == 2 :
customer.Add()
elif menu == 3 :
customer.Sub()
elif menu == 4 :
customer.Show()
elif menu == 0 :
break
|
class Solution:
def intToRoman(self, num):
"""
:type num: int
:rtype: str
"""
res = ""
while num:
if num >= 1000:
res += (num//1000) * 'M'
num = num%1000
elif num >= 900:
res += 'CM'
num -= 900
elif num >= 500:
res += 'D'
num -= 500
elif num >= 400:
res += 'CD'
num -= 400
elif num >= 100:
res += (num//100) * 'C'
num = num%100
elif num >= 90:
res += 'XC'
num -= 90
elif num >= 50:
res += 'L'
num -= 50
elif num >= 40:
res += 'XL'
num -= 40
elif num >= 10:
res += (num//10) * 'X'
num = num%10
elif num >= 9:
res += 'IX'
num -= 9
elif num >= 5:
res += 'V'
num -= 5
elif num >= 4:
res += 'IV'
num -= 4
elif num >= 1:
res += (num//1) * 'I'
num = 0
return res
|
pairs = []
with open("dane/pary.txt") as f:
for line in f:
parsed_line = line.strip().split()
num = int(parsed_line[0])
text = parsed_line[1]
pairs.append(tuple([num, text]))
def is_prime(num: int) -> bool:
for i in range(2, num):
if num % i == 0:
return False
return True
def num_to_primes(num: int) -> (int, int):
primes = []
for i in range(2, num):
if is_prime(i) and is_prime(num - i):
primes.append(tuple([i, num - i]))
# para z największą różnicą zawsze będzie pierwsza
return primes[0]
output_file = open("wyniki_4_1.txt", "w")
for pair in pairs:
num = pair[0]
if num % 2 != 0:
continue
primes = num_to_primes(num)
output_file.write(f"{num} {primes[0]} {primes[1]}\n")
output_file.close()
|
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
prod = 1
prods = [1]*len(nums)
for i in range(len(nums)):
prods[i] = prod
prod *= nums[i]
prod = 1
for i in range(len(nums)-1, -1, -1):
prods[i] *= prod
prod *= nums[i]
return prods
|
def all_index(array, num):
indx = []
for i in range(0,len(array)):
for j in range(0,array[i].count(num)):
if j == 0:
indx.append([i, array[i].index(num)])
else:
indx.append([i, array[i].index(num,indx[j-1][1]+1)])
return indx
tic = [[1,1,0],[0,2,1],[1,2,2]]
print(all_index(tic, 1))
|
"""This problem was asked by Uber.
You have N stones in a row, and would like to create from them a pyramid.
This pyramid should be constructed such that the height of each stone
increases by one until reaching the tallest stone, after which the heights
decrease by one. In addition, the start and end stones of the pyramid
should each be one stone high.
You can change the height of any stone by paying a cost of 1 unit to
lower its height by 1, as many times as necessary. Given this information,
determine the lowest cost method to produce this pyramid.
For example, given the stones [1, 1, 3, 3, 2, 1], the optimal solution
is to pay 2 to create [0, 1, 2, 3, 2, 1].
""" |
"""
给定整数数组 A,每次 move 操作将会选择任意 A[i],并将其递增 1。
返回使 A 中的每个值都是唯一的最少操作次数。
示例 1:
输入:[1,2,2]
输出:1
解释:经过一次 move 操作,数组将变为 [1, 2, 3]。
示例 2:
输入:[3,2,1,2,1,7]
输出:6
解释:经过 6 次 move 操作,数组将变为 [3, 4, 1, 2, 5, 7]。
可以看出 5 次或 5 次以下的 move 操作是不能让数组的每个值唯一的。
提示:
0 <= A.length <= 40000
0 <= A[i] < 40000
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
"""
# sort
# 线性探测+路径压缩 https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/solution/ji-shu-onxian-xing-tan-ce-fa-onpai-xu-onlogn-yi-ya/
class Solution:
def minIncrementForUnique(self, A):
'''
'''
A.sort()
print(A)
step = 0
for i in range(1,len(A)):
if A[i] <= A[i-1]:
step += (A[i-1]-A[i]+1)
A[i] = A[i-1] + 1
return step
if __name__ == "__main__":
s = Solution()
A = [1,3,4,2,3,1,2]
print(s.minIncrementForUnique(A)) |
"""Constants for the xbox integration."""
DOMAIN = "xbox"
OAUTH2_AUTHORIZE = "https://login.live.com/oauth20_authorize.srf"
OAUTH2_TOKEN = "https://login.live.com/oauth20_token.srf"
EVENT_NEW_FAVORITE = "xbox/new_favorite"
|
def encrypt(message, key):
encrypted_message = ''
for char in message:
if char.isalpha():
#ord() returns an integer representing the Unicode code point of the character
unicode_num = ord(char)
unicode_num += key
if char.isupper():
if unicode_num > ord('Z'):
unicode_num -= 26
elif unicode_num < ord('A'):
unicode_num += 26
elif char.islower():
if unicode_num > ord('z'):
unicode_num -= 26
elif unicode_num < ord('a'):
unicode_num += 26
#chr() returns a character from a string
encrypted_message += chr(unicode_num)
else:
encrypted_message += char
return encrypted_message
def decrypt(encoded, key):
return encrypt(encoded, -key)
def encrypt_input():
e_message = input('\nEnter message to encrypt: ')
e_key = int(input('\nEnter key number from 1 - 26: '))
while e_key > 26:
e_key = int(input('\nEnter key number from 1 - 26: '))
return f'\nYour encrypted message is =====> {encrypt(e_message, e_key)}'
def decrypt_input():
d_message = input('\nEnter message to decrypt: ')
d_key = int(input('\nEnter key number from 1 - 26: '))
while d_key > 26:
d_key = int(input('\nEnter key number from 1 - 26: '))
return f'\nYour decrypted message is =====> {decrypt(d_message, d_key)}'
def start():
question = input('\nEncrpyt (e) or Decrypt (d) a message? ')
if question == 'e':
return encrypt_input()
if question == 'd':
return decrypt_input()
# else:
# start()
if __name__ == "__main__":
while True:
print(start())
|
# In "and" operator if ONE is false the whole is false
# in "or" operator if ONE is true the whole is true
print("Welcome to the rollercoaster!")
height = int(input("What is your height in cms? "))
bill = 0
if height >= 120:
print("You can ride the rollercoaster")
age = int(input("What is your age? "))
if age < 12:
bill = 5
print("Child tickets are $5")
elif age <= 18:
bill = 7
print("Youth tickets are $7")
elif age >= 45 and age <= 55:
print("Everything is going to be ok. Have a free ride")
else:
bill = 14
print("Adult tickets are $14")
wants_photo = input("Do you want a photo taken? Y or N.")
if wants_photo == "Y":
bill += 3
print(f"Your final bill is $ {bill}")
else:
print("Sorry, your pp isn't grown up to ride the rollercoaster") |
lista = [4,14,24,34,44]
q4 = int(input("a soma dos dois dígitos é igual a?"))
numero_final = []
for x in range(len(lista)):
valor = str(lista[x])
dig_um = int(valor[0])
if lista[x]>9:
dig_dois = int(valor[1])
if lista[x]<10:
if dig_um== q4:
numero_final.append(lista[x])
elif dig_um + dig_dois == q4:
numero_final.append(lista[x])
print(numero_final) |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Problem 021
Divisible Sum Pairs
Source : https://www.hackerrank.com/challenges/divisible-sum-pairs/problem
"""
_, d = map(int, input().split())
numbers = list(map(int, input().split()))
nb = len(numbers)
count = 0
for i in range(nb-1):
for j in range(i+1, nb):
count += (numbers[i] + numbers[j]) % d == 0
print(count)
|
class User:
def __init__(self, username, name, email, bio, repositories):
self.username = username
self.name = name
self.email = email
self.bio = bio
self.repositories = repositories
def __str__(self):
final = "Name: {} ({}):".format(self.name, self.username)
if self.email:
final = "{} ({})".format(final, self.email)
if self.bio:
final = "{} - {}".format(final, self.bio)
if self.repositories:
for repo in self.repositories:
final = "{}\n{}".format(final, repo.__str__())
return final
def __eq__(self, other):
return self.__dict__ == other.__dict__
|
#-------------------------------------------------------------------------------
def checkUser( username, passwd ):
return False
#-------------------------------------------------------------------------------
def checkIfUserAvailable( username ):
return False
#-------------------------------------------------------------------------------
def getUserEmail( username ):
return None
#-------------------------------------------------------------------------------
def allowPasswordChange( username ):
return False
#-------------------------------------------------------------------------------
def changeUserPassword( username, oldpass, newpass ):
return False
#-------------------------------------------------------------------------------
|
# using modified merge function
def compute_union(arr1, arr2):
union = []
index1 = 0
index2 = 0
while (index1 < len(arr1)) and (index2 < len(arr2)):
if arr1[index1] < arr2[index2]:
union.append(arr1[index1])
index1 += 1
elif arr1[index1] > arr2[index2]:
union.append(arr2[index2])
index2 += 1
else:
union.append(arr2[index2])
index1 += 1
index2 += 1
while index1 < len(arr1):
union.append(arr1[index1])
index1 += 1
while index2 < len(arr2):
union.append(arr2[index2])
index2 += 1
return union
# using modified merge function
def compute_intersection(arr1, arr2):
intersection = []
index1 = 0
index2 = 0
while (index1 < len(arr1)) and (index2 < len(arr2)):
if arr1[index1] < arr2[index2]:
index1 += 1
elif arr1[index1] > arr2[index2]:
index2 += 1
else:
intersection.append(arr2[index2])
index1 += 1
index2 += 1
return intersection
if __name__ == "__main__":
arr1 = [1, 3, 4, 5, 7]
arr2 = [2, 3, 5, 6]
# arr1=[2, 5, 6]
# arr2=[4, 6, 8, 10]
union = compute_union(arr1, arr2)
print('union : ', union)
intersection = compute_intersection(arr1, arr2)
print('intersection : ', intersection)
|
levels = [
#{
# 'geometry': [ ' bbb ',
# ' bbb ',
# ' bbb ',
# ' bbb ',
# ' b ',
# ' b ',
# ' bbb ',
# ' bbbbb ',
# ' bbb ',
# ' b ',
# ' ',
# ' b e ',
# ' b b ',
# ' b b ',
# ' v b '],
# 'start': {'x': 4, 'y': 11},
# 'swatches': [ { 'fields': [ { 'action': 'split1',
# 'position': {'x': 6, 'y': 12}},
# { 'action': 'split2',
# 'position': {'x': 6, 'y': 14}}],
# 'position': {'x': 4, 'y': 14},
# 'type': 'v'}]},
{ 'geometry': [ ' ',
' ',
' bbb ',
' bbbb ',
' bbbb ',
' bbb ',
' bbb ',
' bbbb ',
' bbbb ',
' bebb ',
' bbbb ',
' bb ',
' ',
' ',
' '],
'start': {'x': 6, 'y': 3},
'swatches': []},
{ 'geometry': [ ' bbbbb ',
' bbbbb ',
' bbbsb ',
' bbbbb ',
' l ',
' r ',
' bbbbbb ',
' bbbbbb ',
' bbbbhb ',
' bbbbbb ',
' l ',
' r ',
' bbbbb ',
' bbbeb ',
' bbbbb '],
'start': {'x': 4, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 4, 'y': 10}},
{ 'action': 'onoff',
'position': {'x': 4, 'y': 11}}],
'position': {'x': 7, 'y': 8},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 4, 'y': 4}},
{ 'action': 'onoff',
'position': {'x': 4, 'y': 5}}],
'position': {'x': 6, 'y': 2},
'type': 's'}]},
{ 'geometry': [ ' bbbb ',
' bbbb ',
' bbbb ',
' bbbb ',
' b ',
' b ',
' bbb ',
' bbb ',
' bbb ',
' b ',
' b ',
' bbbbb ',
' bbbbbb ',
' bbeb ',
' bbbb '],
'start': {'x': 4, 'y': 1},
'swatches': []},
{ 'geometry': [ ' bbbbb ',
' bbbbb ',
' bbbbb ',
' bff ',
' ff ',
'bbbb ff ',
'bebb ff ',
'bbbb ff ',
' bb ff ',
' ff bff ',
'ffffbbb ',
'ffffbbb ',
'fbff ',
'ffff ',
' '],
'start': {'x': 3, 'y': 1},
'swatches': []},
{ 'geometry': [ 'bbb ',
'beb bbbb ',
'bbb bbbb ',
'bb bbsbb ',
' b bbbbb ',
' k b k ',
' q s q ',
' b b b ',
' b k s ',
' b q b ',
' bbbb b ',
' bbbb bb',
' bbbb bbb',
' bb bbb',
' bs bbb'],
'start': {'x': 8, 'y': 13},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 8, 'y': 6}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 5}}],
'position': {'x': 8, 'y': 8},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 1, 'y': 5}},
{ 'action': 'on',
'position': {'x': 1, 'y': 6}}],
'position': {'x': 6, 'y': 3},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 1, 'y': 5}},
{ 'action': 'off',
'position': {'x': 1, 'y': 6}}],
'position': {'x': 4, 'y': 6},
'type': 's'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 1, 'y': 5}},
{ 'action': 'onoff',
'position': {'x': 1, 'y': 6}}],
'position': {'x': 3, 'y': 14},
'type': 's'}]},
{ 'geometry': [ ' b ',
' b ',
' b ',
' b ',
' bbb ',
' bbbbbb',
' bbbbb b',
'bbb b',
'bbb bbb',
'bbbb bbb',
' bbb bbb',
' bbb ',
' bbbb ',
' beb ',
' bbb '],
'start': {'x': 6, 'y': 0},
'swatches': []},
{ 'geometry': [ ' bbbb ',
' bbbbb ',
' bbbbbb ',
' bl b ',
' b b ',
' b b ',
' b b ',
' bbbbb ',
' bbbbbb ',
' bh bb ',
' bb ',
' bbb ',
' bbbb ',
' bbeb ',
' bbbb '],
'start': {'x': 5, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 2, 'y': 3}}],
'position': {'x': 4, 'y': 9},
'type': 'h'}]},
{ 'geometry': [ ' bbb ',
' bbb ',
' bbb ',
' bbb ',
' bvb ',
' bbb ',
' ',
' ',
' ',
' bbbbbbbbb',
' bbbbbbbbb',
' bbbbbbbbb',
' bbb ',
' beb ',
' bbb '],
'start': {'x': 5, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'split1',
'position': {'x': 8, 'y': 10}},
{ 'action': 'split2',
'position': {'x': 2, 'y': 10}}],
'position': {'x': 5, 'y': 4},
'type': 'v'}]},
{ 'geometry': [ ' bbb ',
' bbb ',
' bbb ',
' bbb ',
' b ',
' b ',
' bbb ',
' bebbb ',
' bbb ',
' b ',
' b ',
' bbb ',
' bbb ',
' bvb ',
' bbb '],
'start': {'x': 5, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'split1',
'position': {'x': 5, 'y': 12}},
{ 'action': 'split2',
'position': {'x': 5, 'y': 2}}],
'position': {'x': 5, 'y': 13},
'type': 'v'}]},
{ 'geometry': [ ' ',
' bbb',
' beb',
' bbb',
' l ',
'bb r ',
'sb b ',
' b l ',
' b r ',
'bb bbb',
'b bbbb',
'b bbbb',
'hbb bbbbb',
'bbbbbbllvb',
' bb'],
'start': {'x': 8, 'y': 10},
'swatches': [ { 'fields': [ { 'action': 'split1',
'position': {'x': 8, 'y': 13}},
{ 'action': 'split2',
'position': {'x': 8, 'y': 10}}],
'position': {'x': 8, 'y': 13},
'type': 'v'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 8, 'y': 4}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 5}}],
'position': {'x': 0, 'y': 6},
'type': 's'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 8, 'y': 7}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 8}},
{ 'action': 'onoff',
'position': {'x': 7, 'y': 13}},
{ 'action': 'onoff',
'position': {'x': 6, 'y': 13}}],
'position': {'x': 0, 'y': 12},
'type': 'h'}]},
{ 'geometry': [ ' ',
' ',
' b ',
' bbbbbb',
' b beb',
' b bbb',
' b kk',
' bbbbbb ',
' bbsbbb ',
' bb b ',
'bbb b ',
'bb bbb ',
'bb bbb ',
' bbbb ',
' '],
'start': {'x': 4, 'y': 2},
'swatches': [ { 'fields': [ { 'action': 'off',
'position': {'x': 9, 'y': 6}},
{ 'action': 'off',
'position': {'x': 8, 'y': 6}}],
'position': {'x': 3, 'y': 8},
'type': 's'}]},
{ 'geometry': [ ' ',
' bb ',
' bbb ',
' bbb ',
' bbbbb ',
' beb ',
'bb bbbbb ',
'bbb lbhb ',
'bbb bbb ',
' b b ',
' bbb b ',
' bbbbbbb ',
' bbbbbb ',
' bb lbh',
' '],
'start': {'x': 3, 'y': 3},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 5, 'y': 7}}],
'position': {'x': 9, 'y': 13},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 7, 'y': 13}}],
'position': {'x': 7, 'y': 7},
'type': 'h'}]},
{ 'geometry': [ ' ',
' bbbbbb',
' bbbbbb',
' bbbbb b',
'bbb f f',
'bbb f b',
'bfffff b',
' fffbbb b',
' fbfbeb b',
'bfffbbb f',
'bfff b',
' ffb bb',
' bbbbbbb',
' bbbbb',
' bbb '],
'start': {'x': 6, 'y': 13},
'swatches': []},
{ 'geometry': [ ' bbbbbb ',
' bb ll ',
'bbb rr ',
'beb bbb ',
'bbb bbb ',
' bbb ',
' b ',
' b ',
'bbbb bbb',
'bbbb bbb',
'bbbb bbb',
'b b b ',
'b bbbhb ',
'h bbbbb ',
' '],
'start': {'x': 7, 'y': 4},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 7, 'y': 1}},
{ 'action': 'onoff',
'position': {'x': 7, 'y': 2}}],
'position': {'x': 6, 'y': 12},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 6, 'y': 1}},
{ 'action': 'onoff',
'position': {'x': 6, 'y': 2}}],
'position': {'x': 0, 'y': 13},
'type': 'h'}]},
{ 'geometry': [ 'bbb bbb ',
'bbbbbbbb ',
'bbb bl ',
' b br ',
' b bbb ',
' b k ',
'bbb q ',
'bbbbv bbb',
'bbb sbbb',
' k bbb',
' q l ',
'sbs r ',
'beb bhb',
'bbb bbb',
' bbb'],
'start': {'x': 1, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 7, 'y': 2}},
{ 'action': 'onoff',
'position': {'x': 7, 'y': 3}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 5}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 6}}],
'position': {'x': 8, 'y': 12},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 8, 'y': 5}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 6}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 10}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 11}}],
'position': {'x': 6, 'y': 8},
'type': 's'},
{ 'fields': [ { 'action': 'split1',
'position': {'x': 8, 'y': 13}},
{ 'action': 'split2',
'position': {'x': 1, 'y': 1}}],
'position': {'x': 4, 'y': 7},
'type': 'v'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 1, 'y': 9}},
{ 'action': 'off',
'position': {'x': 1, 'y': 10}}],
'position': {'x': 2, 'y': 11},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 1, 'y': 9}},
{ 'action': 'off',
'position': {'x': 1, 'y': 10}}],
'position': {'x': 0, 'y': 11},
'type': 's'}]},
{ 'geometry': [ ' v ',
' vbv ',
'bbb v ',
'bbb l ',
'bbb r ',
' b h ',
' b h ',
' b b ',
'bbb l ',
'bvb r ',
'bbb bbb ',
' beb ',
' bbb ',
' ',
' '],
'start': {'x': 1, 'y': 3},
'swatches': [ { 'fields': [ { 'action': 'split1',
'position': {'x': 6, 'y': 7}},
{ 'action': 'split2',
'position': {'x': 6, 'y': 5}}],
'position': {'x': 7, 'y': 1},
'type': 'v'},
{ 'fields': [ { 'action': 'split1',
'position': {'x': 6, 'y': 2}},
{ 'action': 'split2',
'position': {'x': 7, 'y': 1}}],
'position': {'x': 6, 'y': 0},
'type': 'v'},
{ 'fields': [ { 'action': 'split1',
'position': {'x': 6, 'y': 0}},
{ 'action': 'split2',
'position': {'x': 6, 'y': 2}}],
'position': {'x': 6, 'y': 2},
'type': 'v'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 3}},
{ 'action': 'on',
'position': {'x': 6, 'y': 4}}],
'position': {'x': 6, 'y': 5},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 8}},
{ 'action': 'on',
'position': {'x': 6, 'y': 9}}],
'position': {'x': 6, 'y': 6},
'type': 'h'},
{ 'fields': [ { 'action': 'split1',
'position': {'x': 5, 'y': 1}},
{ 'action': 'split2',
'position': {'x': 6, 'y': 0}}],
'position': {'x': 5, 'y': 1},
'type': 'v'},
{ 'fields': [ { 'action': 'split1',
'position': {'x': 7, 'y': 1}},
{ 'action': 'split2',
'position': {'x': 6, 'y': 0}}],
'position': {'x': 1, 'y': 9},
'type': 'v'}]},
{ 'geometry': [ 'bbbbbbbbbb',
'bsbbbbbbbb',
'bbbbbbbbbb',
' b b ',
' b b ',
' b b ',
' br b ',
' bb rb ',
' lb bb ',
' b bl ',
' b b ',
'bbbb b ',
'hbbh hbb ',
' heb ',
' bbb '],
'start': {'x': 8, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'off',
'position': {'x': 3, 'y': 6}}],
'position': {'x': 6, 'y': 12},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 3, 'y': 6}}],
'position': {'x': 6, 'y': 13},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 7, 'y': 7}}],
'position': {'x': 3, 'y': 12},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 2, 'y': 8}}],
'position': {'x': 1, 'y': 1},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 8, 'y': 9}},
{ 'action': 'off',
'position': {'x': 2, 'y': 8}}],
'position': {'x': 0, 'y': 12},
'type': 'h'}]},
{ 'geometry': [ 'bbbbbbbb ',
'l bbsbb ',
'r sbbbs ',
'h bbbbb ',
' bbb ',
' lb ',
' b ',
' bbbs ',
' sbbl ',
' r ',
'bb b ',
'bbb b ',
'bebbbl ',
'bbb r ',
' b '],
'start': {'x': 5, 'y': 2},
'swatches': [ { 'fields': [ { 'action': 'on',
'position': {'x': 5, 'y': 8}},
{ 'action': 'on',
'position': {'x': 5, 'y': 9}}],
'position': {'x': 8, 'y': 7},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 5, 'y': 12}},
{ 'action': 'off',
'position': {'x': 5, 'y': 13}},
{ 'action': 'off',
'position': {'x': 0, 'y': 1}},
{ 'action': 'off',
'position': {'x': 0, 'y': 2}}],
'position': {'x': 7, 'y': 2},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 5, 'y': 8}},
{ 'action': 'off',
'position': {'x': 5, 'y': 9}}],
'position': {'x': 5, 'y': 1},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 5, 'y': 12}},
{ 'action': 'off',
'position': {'x': 5, 'y': 13}},
{ 'action': 'off',
'position': {'x': 0, 'y': 1}},
{ 'action': 'off',
'position': {'x': 0, 'y': 2}}],
'position': {'x': 3, 'y': 2},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 5, 'y': 12}},
{ 'action': 'on',
'position': {'x': 5, 'y': 13}},
{ 'action': 'on',
'position': {'x': 0, 'y': 1}},
{ 'action': 'on',
'position': {'x': 0, 'y': 2}}],
'position': {'x': 2, 'y': 8},
'type': 's'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 4, 'y': 5}}],
'position': {'x': 0, 'y': 3},
'type': 'h'}]},
{ 'geometry': [ ' bbb ',
'bbbeb b',
'kbbbb b',
'q b',
'b b',
'bbbbb bbb',
'bbbbb bbb',
'b l b',
'b r b',
'b b b',
's s s',
'b b b',
'b b b',
'b bbbbbb',
' bbbbbb'],
'start': {'x': 9, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 4, 'y': 7}},
{ 'action': 'onoff',
'position': {'x': 4, 'y': 8}}],
'position': {'x': 9, 'y': 10},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 0, 'y': 2}},
{ 'action': 'off',
'position': {'x': 0, 'y': 3}}],
'position': {'x': 4, 'y': 10},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 0, 'y': 2}},
{ 'action': 'on',
'position': {'x': 0, 'y': 3}}],
'position': {'x': 0, 'y': 10},
'type': 's'}]},
{ 'geometry': [ ' bb ',
' sb ',
' bbbbbb ',
' bbsbbb ',
' bbbbb ',
' k ',
' q ',
' bbvbsb ',
' bbbbbb ',
' bbsbbb ',
' l l ',
' r r ',
'bbbs bbb',
'bebb bbb',
'bbbb bbb'],
'start': {'x': 7, 'y': 8},
'swatches': [ { 'fields': [ { 'action': 'off',
'position': {'x': 8, 'y': 5}},
{ 'action': 'off',
'position': {'x': 8, 'y': 6}}],
'position': {'x': 7, 'y': 7},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 8, 'y': 5}},
{ 'action': 'off',
'position': {'x': 8, 'y': 6}}],
'position': {'x': 5, 'y': 3},
'type': 's'},
{ 'fields': [ { 'action': 'split1',
'position': {'x': 8, 'y': 13}},
{ 'action': 'split2',
'position': {'x': 2, 'y': 13}}],
'position': {'x': 5, 'y': 7},
'type': 'v'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 8, 'y': 5}},
{ 'action': 'off',
'position': {'x': 8, 'y': 6}}],
'position': {'x': 5, 'y': 9},
'type': 's'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 3, 'y': 10}},
{ 'action': 'onoff',
'position': {'x': 3, 'y': 11}}],
'position': {'x': 3, 'y': 12},
'type': 's'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 8, 'y': 10}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 11}}],
'position': {'x': 2, 'y': 1},
'type': 's'}]},
{ 'geometry': [ ' bbb ',
' bbbb ',
' bbbbb ',
'rbb bb ',
'bbb bb ',
'bbl bb ',
'b b ',
'b bb ',
'bbbhhbbbbb',
'bbbbb bbb',
' b ',
' b ',
' bbb ',
' beb ',
' bbb '],
'start': {'x': 6, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 0, 'y': 3}}],
'position': {'x': 4, 'y': 8},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 2, 'y': 5}}],
'position': {'x': 3, 'y': 8},
'type': 'h'}]},
{ 'geometry': [ ' ',
' bbb ',
' bbbbbbb ',
'hbl bbb ',
' bbb ',
' sbb ',
' bbb',
' sbb',
' bbb ',
' bbb ',
'hbq bbb ',
' bbbbbbb ',
' bbbbb',
' lbeb',
' bbb'],
'start': {'x': 6, 'y': 2},
'swatches': [ { 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 6, 'y': 13}}],
'position': {'x': 7, 'y': 7},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 6, 'y': 13}}],
'position': {'x': 6, 'y': 5},
'type': 's'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 6, 'y': 13}}],
'position': {'x': 0, 'y': 3},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 2, 'y': 3}}],
'position': {'x': 0, 'y': 10},
'type': 'h'}]},
{ 'geometry': [ ' bsbr ',
' l bbbb',
' r bbhb',
'bbbb bbbb',
'bbbbbbl ',
'bbbb ',
'bfff ',
'bffffbbb ',
'lffffbeb ',
' ffffbbb ',
' fff k ',
' bbb q ',
' bvb bbbb',
' bbb bbsb',
' kbbsbbb'],
'start': {'x': 2, 'y': 4},
'swatches': [ { 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 4}}],
'position': {'x': 8, 'y': 2},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 0, 'y': 8}},
{ 'action': 'on',
'position': {'x': 3, 'y': 1}},
{ 'action': 'on',
'position': {'x': 3, 'y': 2}}],
'position': {'x': 8, 'y': 13},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 3, 'y': 14}},
{ 'action': 'off',
'position': {'x': 7, 'y': 10}},
{ 'action': 'off',
'position': {'x': 7, 'y': 11}}],
'position': {'x': 6, 'y': 14},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 0}},
{ 'action': 'off',
'position': {'x': 3, 'y': 1}},
{ 'action': 'off',
'position': {'x': 3, 'y': 2}}],
'position': {'x': 4, 'y': 0},
'type': 's'},
{ 'fields': [ { 'action': 'split1',
'position': {'x': 2, 'y': 12}},
{ 'action': 'split2',
'position': {'x': 7, 'y': 2}}],
'position': {'x': 2, 'y': 12},
'type': 'v'}]},
{ 'geometry': [ ' ',
' bbbh ',
' bbbbb ',
' bb l ',
' b rr ',
' bbbbb ',
' hb bhb ',
' bb bb ',
' lb b ',
' l b ',
' r b ',
' bbb bbb ',
' beb bhb ',
' bbbbbbbb ',
' bvb '],
'start': {'x': 6, 'y': 2},
'swatches': [ { 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 4}},
{ 'action': 'on',
'position': {'x': 6, 'y': 3}}],
'position': {'x': 7, 'y': 12},
'type': 'h'},
{ 'fields': [ { 'action': 'split1',
'position': {'x': 2, 'y': 6}},
{ 'action': 'split2',
'position': {'x': 2, 'y': 8}}],
'position': {'x': 7, 'y': 14},
'type': 'v'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 1, 'y': 8}}],
'position': {'x': 6, 'y': 6},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 7, 'y': 4}}],
'position': {'x': 5, 'y': 1},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 2, 'y': 9}},
{ 'action': 'on',
'position': {'x': 2, 'y': 10}}],
'position': {'x': 1, 'y': 6},
'type': 'h'}]},
{ 'geometry': [ ' bbb ',
' bbbb ',
' kkhb bbb',
' b bbbb',
' k bsb ',
' q b ',
' bbbbbb ',
' bbbbbl ',
' s l ',
' b r ',
' b bbb ',
'bbb beb ',
'bbb bbb ',
'bbb ll ',
' '],
'start': {'x': 2, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 7, 'y': 13}},
{ 'action': 'onoff',
'position': {'x': 6, 'y': 13}},
{ 'action': 'onoff',
'position': {'x': 5, 'y': 8}},
{ 'action': 'onoff',
'position': {'x': 5, 'y': 9}}],
'position': {'x': 7, 'y': 4},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 5, 'y': 8}},
{ 'action': 'on',
'position': {'x': 5, 'y': 9}}],
'position': {'x': 3, 'y': 2},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 7}},
{ 'action': 'off',
'position': {'x': 3, 'y': 4}},
{ 'action': 'off',
'position': {'x': 3, 'y': 5}}],
'position': {'x': 1, 'y': 8},
'type': 's'}]},
{ 'geometry': [ ' bbb ',
' hbbbb ',
' bbk ',
' lq ',
' bb ',
' bbbb',
' bbbbbbbbb',
' beb bbsb',
' bbb bbb',
' l bb ',
' bbbbb ',
' bb ',
' b ',
' bbbv',
' '],
'start': {'x': 4, 'y': 10},
'swatches': [ { 'fields': [ { 'action': 'split1',
'position': {'x': 6, 'y': 12}},
{ 'action': 'split2',
'position': {'x': 4, 'y': 10}}],
'position': {'x': 9, 'y': 13},
'type': 'v'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 6, 'y': 2}},
{ 'action': 'off',
'position': {'x': 6, 'y': 3}}],
'position': {'x': 8, 'y': 7},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 2, 'y': 9}},
{ 'action': 'on',
'position': {'x': 5, 'y': 3}}],
'position': {'x': 2, 'y': 1},
'type': 'h'}]},
{ 'geometry': [ ' bbb bbb',
' beb bbb',
' bbb bbb',
' ff b ',
' ff b ',
' ffff b ',
'qffff b ',
'bffff bbb',
'bffff bbb',
'kfffb bb',
' ff bb',
' ff b',
' bbbsbb b',
' bbbsbhbbb',
' bbb bbbb'],
'start': {'x': 8, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'off',
'position': {'x': 0, 'y': 6}},
{ 'action': 'off',
'position': {'x': 0, 'y': 9}}],
'position': {'x': 6, 'y': 13},
'type': 'h'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 0, 'y': 6}}],
'position': {'x': 4, 'y': 12},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 0, 'y': 9}}],
'position': {'x': 4, 'y': 13},
'type': 's'}]},
{ 'geometry': [ ' ffff ',
' bbbfffbb',
'bbbeb bbb',
' bbb k',
' b q',
'bbb bbb',
'bbb bbb',
'b bbb ',
'k bbb ',
'q bbb ',
'bbbbbb ',
'bbsbv ',
'bbbb ',
' bb ',
' bb '],
'start': {'x': 7, 'y': 2},
'swatches': [ { 'fields': [ { 'action': 'split1',
'position': {'x': 3, 'y': 14}},
{ 'action': 'split2',
'position': {'x': 0, 'y': 12}}],
'position': {'x': 4, 'y': 11},
'type': 'v'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 9, 'y': 4}},
{ 'action': 'off',
'position': {'x': 9, 'y': 3}},
{ 'action': 'off',
'position': {'x': 0, 'y': 8}},
{ 'action': 'off',
'position': {'x': 0, 'y': 9}}],
'position': {'x': 2, 'y': 11},
'type': 's'}]},
{ 'geometry': [ 'bbb h ',
'beb l ',
'bbb r s',
'll b k',
' r b q',
' bbrrbbbbb',
' bbbbbb ',
' bbb ',
' bbb ',
'bbbbbbbbbb',
'k k b l',
'q q b r',
's s l h',
' r ',
' h '],
'start': {'x': 6, 'y': 7},
'swatches': [ { 'fields': [ { 'action': 'on',
'position': {'x': 9, 'y': 10}},
{ 'action': 'on',
'position': {'x': 9, 'y': 11}},
{ 'action': 'off',
'position': {'x': 3, 'y': 10}},
{ 'action': 'off',
'position': {'x': 3, 'y': 11}}],
'position': {'x': 9, 'y': 2},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 4, 'y': 5}},
{ 'action': 'on',
'position': {'x': 3, 'y': 5}}],
'position': {'x': 9, 'y': 12},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 1, 'y': 3}},
{ 'action': 'on',
'position': {'x': 1, 'y': 4}},
{ 'action': 'off',
'position': {'x': 0, 'y': 10}},
{ 'action': 'off',
'position': {'x': 0, 'y': 11}}],
'position': {'x': 6, 'y': 0},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 0, 'y': 3}}],
'position': {'x': 6, 'y': 14},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 1}},
{ 'action': 'on',
'position': {'x': 6, 'y': 2}}],
'position': {'x': 3, 'y': 12},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 12}},
{ 'action': 'on',
'position': {'x': 6, 'y': 13}},
{ 'action': 'off',
'position': {'x': 3, 'y': 10}},
{ 'action': 'off',
'position': {'x': 3, 'y': 11}},
{ 'action': 'off',
'position': {'x': 9, 'y': 3}},
{ 'action': 'off',
'position': {'x': 9, 'y': 4}},
{ 'action': 'off',
'position': {'x': 9, 'y': 10}},
{ 'action': 'off',
'position': {'x': 9, 'y': 11}}],
'position': {'x': 0, 'y': 12},
'type': 's'}]},
{ 'geometry': [ ' bff ',
'ffffh ',
'bfffbb ',
'ffbff bbb',
'fff beb',
'ffb bbb',
' ff bb',
' ffbfff b',
'ffbbffb f',
'fffl b f',
'ff k b',
'ff q b',
'bbhr bffb',
' bb bbbb',
' lbbbbh '],
'start': {'x': 5, 'y': 2},
'swatches': [ { 'fields': [ { 'action': 'off',
'position': {'x': 6, 'y': 10}},
{ 'action': 'off',
'position': {'x': 6, 'y': 11}},
{ 'action': 'on',
'position': {'x': 3, 'y': 9}},
{ 'action': 'on',
'position': {'x': 3, 'y': 12}}],
'position': {'x': 7, 'y': 14},
'type': 'h'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 6, 'y': 10}},
{ 'action': 'on',
'position': {'x': 6, 'y': 11}}],
'position': {'x': 4, 'y': 1},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 2, 'y': 14}}],
'position': {'x': 2, 'y': 12},
'type': 'h'}]},
{ 'geometry': [ 'qqq ',
'bbb fbbb ',
'bhbbffbbb ',
'bbb fbbb ',
' l k ',
' r q ',
' hbbbsbb ',
' sbbbbb ',
' bbbbbbh ',
' k l ',
' q r ',
' bbbf bbb',
' bbbffbbeb',
' bbbf bbb',
' lll'],
'start': {'x': 2, 'y': 12},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 7, 'y': 9}},
{ 'action': 'onoff',
'position': {'x': 7, 'y': 10}}],
'position': {'x': 8, 'y': 8},
'type': 'h'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 7, 'y': 4}},
{ 'action': 'off',
'position': {'x': 7, 'y': 5}},
{ 'action': 'off',
'position': {'x': 7, 'y': 9}},
{ 'action': 'off',
'position': {'x': 7, 'y': 10}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}},
{ 'action': 'off',
'position': {'x': 2, 'y': 5}},
{ 'action': 'off',
'position': {'x': 2, 'y': 9}},
{ 'action': 'off',
'position': {'x': 2, 'y': 10}}],
'position': {'x': 5, 'y': 6},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 7, 'y': 4}},
{ 'action': 'off',
'position': {'x': 7, 'y': 5}},
{ 'action': 'off',
'position': {'x': 7, 'y': 9}},
{ 'action': 'off',
'position': {'x': 7, 'y': 10}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}},
{ 'action': 'off',
'position': {'x': 2, 'y': 5}},
{ 'action': 'off',
'position': {'x': 2, 'y': 9}},
{ 'action': 'off',
'position': {'x': 2, 'y': 10}}],
'position': {'x': 2, 'y': 7},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 7, 'y': 14}},
{ 'action': 'on',
'position': {'x': 8, 'y': 14}},
{ 'action': 'on',
'position': {'x': 9, 'y': 14}},
{ 'action': 'off',
'position': {'x': 7, 'y': 4}},
{ 'action': 'off',
'position': {'x': 7, 'y': 5}}],
'position': {'x': 1, 'y': 2},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 2, 'y': 4}},
{ 'action': 'onoff',
'position': {'x': 2, 'y': 5}}],
'position': {'x': 1, 'y': 6},
'type': 'h'}]},
{ 'geometry': [ ' ',
' bb ',
' bb bbb ',
' ll bebb ',
' rr bbbb ',
' bbb lk ',
' bhb rq ',
' bbb bb ',
' b bbb ',
' b bb ',
' bbbbbb ',
' bbbbbbb ',
' bhb ',
' bbb',
' bbh'],
'start': {'x': 3, 'y': 11},
'swatches': [ { 'fields': [ { 'action': 'onoff',
'position': {'x': 2, 'y': 3}},
{ 'action': 'onoff',
'position': {'x': 2, 'y': 4}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 5}},
{ 'action': 'onoff',
'position': {'x': 8, 'y': 6}}],
'position': {'x': 9, 'y': 14},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 1, 'y': 3}},
{ 'action': 'onoff',
'position': {'x': 1, 'y': 4}}],
'position': {'x': 7, 'y': 12},
'type': 'h'},
{ 'fields': [ { 'action': 'onoff',
'position': {'x': 7, 'y': 5}},
{ 'action': 'onoff',
'position': {'x': 7, 'y': 6}}],
'position': {'x': 2, 'y': 6},
'type': 'h'}]},
{ 'geometry': [ 'bbbb bb ',
'bbeb bb ',
'bbbb bb ',
' k k ',
' q q ',
' bbbbbbsbb',
' bsbbbbbbb',
' bbbbsbbbs',
' bbbbsbb',
' bbbsbbb',
' bbbssbbb',
' bbssbbbl ',
'bbbbbbbb ',
'bbsbbbsb ',
'bbhb '],
'start': {'x': 6, 'y': 1},
'swatches': [ { 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 9, 'y': 7},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 7, 'y': 5},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 7, 'y': 8},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 6, 'y': 9},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 6, 'y': 10},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 6, 'y': 13},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 5, 'y': 7},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 5, 'y': 10},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 4, 'y': 11},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 3, 'y': 11},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 2, 'y': 6},
'type': 's'},
{ 'fields': [ { 'action': 'off',
'position': {'x': 2, 'y': 3}},
{ 'action': 'off',
'position': {'x': 2, 'y': 4}}],
'position': {'x': 2, 'y': 13},
'type': 's'},
{ 'fields': [ { 'action': 'on',
'position': {'x': 8, 'y': 11}}],
'position': {'x': 2, 'y': 14},
'type': 'h'}]}]
|
while True:
a, b, c = sorted(map(int, input().split()))
if a == 0 and b == 0 and c == 0:
break
print("right" if a ** 2 + b ** 2 == c ** 2 else "wrong")
|
# EASY
# count each element in array and store in dict{}
# loop through the array check if exist nums[i]+1 in dict{}
class Solution:
def findLHS(self, nums: List[int]) -> int:
n = len(nums)
appear = {}
for i in range(n):
appear[nums[i]] = appear.get(nums[i],0) + 1
result = 0
for k,v in appear.items():
if k+1 in appear:
result = max(result,v+appear[k+1])
return result |
class Clock():
# Set initial Clock state
def __init__(self, hours, minutes):
timeDic = self.calculateMinutes(minutes)
self.minutes = timeDic['minutes']
self.hours = self.calculateHour(hours + timeDic['hours'])
self.time = self.generateTimeString()
# Add minutes to the clock (Can be positive or subtracting)
def add(self, numMinutes=0):
timeDic = self.calculateMinutes(self.minutes + numMinutes)
self.setMinutes(timeDic['minutes'])
hours = self.calculateHour(self.hours + timeDic['hours'])
self.setHours(hours)
self.time = self.generateTimeString()
return self.time
# Calculate Clock Hour in '24' from num of hours (Positive or Negative)
def calculateHour(self, numHours=0):
if numHours >= 0 and numHours < 24:
return numHours
hours = abs(numHours % 24)
return hours
# Caluclate Clock Minutes from num of minutes (Positive or Negative)
# returns a dict of hours and minutes
def calculateMinutes(self, numMinutes=0):
if numMinutes >= 0 and numMinutes < 60:
return { 'hours': 0, 'minutes': numMinutes }
hours = (numMinutes / 60)
minutes = (numMinutes % 60)
if minutes == 60:
minutes = 0
hours = hours + 1
return { 'hours': hours, 'minutes': minutes }
# Generates time string from hours and minutes
def generateTimeString(self):
hourDigit = str(self.hours)
if len(hourDigit) < 2:
hourDigit = '%d%s' % (0, hourDigit)
minuteDigit = str(self.minutes)
if len(minuteDigit) < 2:
minuteDigit = '%d%s' % (0, minuteDigit)
return '%s:%s' % (hourDigit, minuteDigit)
# ToString overide for instance
def __str__(self):
return self.time
# Equality overide for instance
def __eq__(self, other):
return self.time == other.time
# Setter for hours
def setHours(self, hours):
self.hours = hours
# Setter for minutes
def setMinutes(self, minutes):
self.minutes = minutes
|
class Order:
__slots__ = (
'id',
'order_number',
'customer_name',
'shipping_name',
'order_date',
'order_details_url',
'subtotal',
'shipping_fee',
'tax',
'status',
'retail_bonus',
'order_type',
'customer_url',
'customer_id',
'customer_contact',
'total',
'qv',
'hostess',
'party',
'ship_date',
'line_items',
'shipping_address',
)
class OrderLineItem:
__slots__ = (
'sku',
'name',
'price',
'quantity',
'total',
)
|
'''
Find the largest continuous sum
'''
def largest_cont_sum(arr):
if len(arr) == 0:
return 0
cur_sum = arr[0]
max_sum = arr[0]
for item in arr[1:]:
cur_sum = max(cur_sum+item, item)
if cur_sum >= max_sum:
max_sum = cur_sum
return max_sum
|
tupla = (
int(input('Digite um número: ')),
int(input('Digite outro número: ')),
int(input('Digite mais número: ')),
int(input('Digite o último número: '))
)
print('Você digitou os valores: {}'.format(tupla))
print('O número 9 apareceu {} vezes.'.format(tupla.count(9)))
if 3 in tupla:
print('O número 3 foi digitado pela primeira vez na pergunta {}.'.format(tupla.index(3)+1))
else:
print('O número 3 não foi digitado.')
print('Os números pares digitados foram: ', end='')
for numero in tupla:
if numero % 2 == 0:
print(numero, end=' ')
|
class Solution:
def matrixReshape(self, mat: List[List[int]], newRows: int, newCols: int) -> List[List[int]]:
rows = len(mat)
cols = len(mat[0])
if rows * cols != newRows * newCols:
return mat
newMat = [[0] * newCols for _ in range(newRows)]
for x in range(rows):
for y in range(cols):
num = x * cols + y
newMat[num // newCols][num % newCols] = mat[x][y]
return newMat |
input = """
c num blocks = 1
c num vars = 180
c minblockids[0] = 1
c maxblockids[0] = 180
p cnf 180 765
43 -70 -94 0
80 70 -20 0
34 -89 37 0
-99 -140 153 0
-30 131 14 0
136 20 17 0
-125 -172 -114 0
19 -13 -126 0
127 -138 -142 0
-127 -84 79 0
-63 -13 50 0
-15 -118 17 0
6 65 -116 0
-30 -167 157 0
-156 -143 -12 0
38 -60 154 0
-121 18 -76 0
142 -152 130 0
177 41 -62 0
-51 180 -105 0
-61 -76 26 0
-177 -180 -110 0
32 42 -144 0
155 119 73 0
95 -39 104 0
111 -56 -167 0
126 82 -111 0
-64 159 -36 0
-28 -79 40 0
157 -130 88 0
172 16 -88 0
100 21 -110 0
93 40 -22 0
-172 -179 28 0
178 36 -104 0
-45 1 -100 0
-55 -1 32 0
178 32 -16 0
-26 22 63 0
-13 -42 73 0
-131 107 -16 0
-61 -98 -91 0
154 -42 -67 0
-161 -87 9 0
-151 27 -77 0
129 121 -122 0
108 -97 -15 0
-6 12 86 0
-108 -171 -57 0
-30 -145 175 0
1 -78 3 0
141 54 -62 0
-69 -119 58 0
-177 142 -59 0
-144 -164 163 0
21 -116 -119 0
106 -69 -129 0
174 34 -2 0
-33 -119 -152 0
88 -45 -142 0
-56 -164 -22 0
-15 82 -132 0
-162 -45 179 0
67 46 -78 0
-11 -170 86 0
-145 111 -21 0
-23 20 -27 0
39 60 53 0
160 -116 -47 0
-160 45 102 0
-113 143 45 0
112 115 -140 0
29 174 -126 0
132 157 -25 0
123 69 -167 0
99 -36 -63 0
-164 29 -43 0
-152 149 -23 0
149 35 173 0
-81 75 -84 0
-161 -142 84 0
-124 -113 -172 0
7 -143 -18 0
90 55 -118 0
179 -103 23 0
-119 -35 161 0
-160 -153 -133 0
114 99 -4 0
-116 -85 122 0
141 72 -71 0
-163 52 -20 0
-112 144 161 0
-173 111 -120 0
-145 -33 -86 0
-31 144 -94 0
-74 94 158 0
-4 107 -119 0
15 -43 -76 0
117 179 -51 0
159 -104 158 0
-160 -117 21 0
-23 97 59 0
-97 143 91 0
8 61 69 0
41 164 160 0
60 -175 -160 0
-27 169 -67 0
-178 33 -69 0
-119 -107 83 0
53 93 -160 0
-45 -155 -153 0
9 167 15 0
-38 127 168 0
-28 -69 -108 0
135 21 -117 0
146 48 41 0
139 -2 104 0
44 -31 176 0
104 -23 -109 0
106 49 123 0
-14 -2 -63 0
-170 -5 -177 0
88 -180 -161 0
175 23 168 0
98 -135 -45 0
79 -161 136 0
-140 123 -129 0
-104 -79 178 0
-158 46 24 0
76 -165 -65 0
-31 82 -29 0
-16 -124 58 0
-11 83 -21 0
43 -33 -121 0
4 133 23 0
-9 -157 72 0
-27 -86 13 0
35 140 54 0
167 64 21 0
-118 -122 97 0
-23 149 126 0
65 128 96 0
-167 -175 -177 0
-53 -116 -92 0
52 139 37 0
-50 -1 -85 0
105 -132 53 0
-119 -8 20 0
-112 100 53 0
-74 45 -39 0
-59 -44 -23 0
-31 146 1 0
23 114 -20 0
39 -25 166 0
54 110 47 0
-43 -9 154 0
116 -123 -109 0
-26 138 -12 0
-169 128 37 0
-147 -119 -105 0
17 -49 -21 0
174 27 18 0
101 -121 -166 0
-99 161 -90 0
9 90 -142 0
158 161 169 0
-38 -9 171 0
-165 87 -48 0
-18 -15 148 0
-48 -130 -57 0
-32 -2 50 0
-171 65 -30 0
12 -30 29 0
-106 -136 -67 0
-98 -61 174 0
29 46 -132 0
177 -116 42 0
-140 176 10 0
-147 105 165 0
57 68 -95 0
56 44 -173 0
-68 9 119 0
-89 69 -172 0
-17 146 15 0
6 149 27 0
-141 -32 -136 0
-111 -67 84 0
-147 -133 -108 0
137 -126 -123 0
175 105 -101 0
-60 177 -98 0
52 -19 -31 0
-61 -123 -91 0
-155 101 62 0
44 119 -109 0
8 138 32 0
166 131 -56 0
-46 -54 -116 0
66 132 100 0
-158 -83 180 0
117 160 69 0
-159 -132 48 0
-21 -59 -123 0
-107 -42 27 0
-9 -50 35 0
-56 96 142 0
143 110 -147 0
75 17 -68 0
22 17 -144 0
-56 152 41 0
-141 163 -108 0
-66 -49 -155 0
-134 8 157 0
-18 49 31 0
-4 -106 146 0
-153 38 -39 0
-99 -61 119 0
-105 156 98 0
-42 -173 178 0
25 -102 -51 0
-180 -85 -6 0
-18 52 129 0
-93 130 -25 0
-149 77 106 0
-157 -180 43 0
-136 -129 -87 0
-121 151 -83 0
79 153 -15 0
-85 13 -116 0
-63 150 74 0
-8 95 -1 0
171 -152 -167 0
-165 176 -17 0
-35 -74 -122 0
160 155 -87 0
32 -73 -106 0
145 -180 -47 0
-39 178 -120 0
-120 35 174 0
112 167 58 0
-42 53 135 0
50 141 54 0
32 -101 154 0
-128 85 -143 0
-90 -53 -144 0
-50 -143 46 0
65 -175 9 0
-4 -3 16 0
-158 103 88 0
-110 142 -27 0
-146 -138 -133 0
151 -71 -129 0
116 24 119 0
-25 -116 138 0
-170 -77 -5 0
111 -154 87 0
47 39 89 0
148 163 -106 0
-156 -38 -168 0
-25 4 165 0
-1 -13 15 0
164 -15 -92 0
-65 -163 19 0
-10 -137 -131 0
46 86 149 0
-30 61 168 0
-75 93 43 0
-89 114 -25 0
-159 163 -9 0
53 73 -148 0
-124 32 -27 0
94 104 -164 0
134 -143 -11 0
-107 -85 61 0
21 55 82 0
5 170 54 0
83 117 34 0
-1 -31 -78 0
54 162 43 0
-171 48 4 0
-157 -45 -135 0
55 -131 127 0
13 76 -173 0
-109 -120 -25 0
19 82 -31 0
27 30 68 0
6 9 72 0
-63 -86 -62 0
97 160 -53 0
129 5 102 0
-178 -116 -19 0
-95 -157 -59 0
171 17 157 0
-178 -61 -98 0
42 -43 81 0
110 -139 -134 0
-158 -146 116 0
18 22 79 0
-161 130 -59 0
68 -133 -9 0
163 30 -177 0
-30 -34 114 0
89 -170 83 0
64 -55 -82 0
-3 121 -145 0
41 -74 87 0
-135 -19 11 0
32 81 31 0
130 -138 31 0
123 -63 39 0
-94 -38 149 0
-168 -125 -35 0
139 -95 -87 0
131 -56 -85 0
168 152 78 0
170 -145 39 0
121 -131 124 0
-124 83 177 0
50 -42 -37 0
-39 -37 158 0
156 107 115 0
171 35 -121 0
74 14 -51 0
-72 -21 -97 0
-44 102 85 0
-174 -46 2 0
-168 -6 -42 0
-75 42 47 0
-16 -112 -146 0
102 -82 79 0
-111 -33 -167 0
-167 -101 130 0
-74 -71 -17 0
110 -117 -88 0
171 92 -80 0
-39 126 -91 0
66 -165 83 0
87 -28 9 0
-128 -84 -15 0
-146 128 -90 0
31 -78 39 0
160 132 79 0
86 -111 -171 0
-138 -175 -128 0
101 46 85 0
-78 1 63 0
40 96 -53 0
68 -123 109 0
-74 79 132 0
-90 20 50 0
-180 97 -53 0
-60 112 143 0
157 -175 -40 0
79 -82 -160 0
-159 142 -9 0
129 -179 131 0
-107 72 34 0
-71 -163 16 0
-131 -64 10 0
-48 150 -30 0
52 -118 155 0
-72 42 -87 0
-135 118 16 0
178 3 -70 0
-28 -3 116 0
95 -60 160 0
73 -162 -39 0
129 -130 163 0
140 53 -130 0
-25 -108 -134 0
169 -4 -60 0
107 -113 55 0
171 -91 179 0
-111 -59 94 0
14 -56 -40 0
-125 -44 172 0
-34 42 -101 0
79 70 -139 0
-53 -106 55 0
17 158 128 0
102 -60 146 0
-134 -56 -176 0
71 153 89 0
-48 -97 -168 0
-15 23 160 0
107 119 93 0
-148 -142 12 0
26 -142 -16 0
10 179 -160 0
63 -179 112 0
-105 -17 -141 0
172 164 55 0
-107 -26 67 0
142 12 -125 0
-18 -148 -92 0
-87 -116 -84 0
-134 12 35 0
-150 142 82 0
-95 -171 -154 0
-72 18 81 0
24 -166 68 0
-146 45 -122 0
-89 -57 -77 0
57 68 -98 0
6 -169 73 0
94 138 -41 0
-41 46 -36 0
104 -161 -149 0
121 13 -92 0
-150 115 2 0
-93 18 136 0
-80 115 81 0
128 -15 39 0
-71 109 -111 0
-94 -147 53 0
-165 116 -54 0
179 -8 -148 0
48 -114 65 0
160 -127 -68 0
40 -88 -59 0
43 -63 15 0
-15 -6 -23 0
-112 140 49 0
78 -102 -93 0
120 -20 -42 0
51 15 -114 0
159 20 -75 0
-85 -3 10 0
-104 54 72 0
132 142 21 0
-151 122 153 0
-20 -81 -59 0
113 -132 -29 0
-113 -58 74 0
-130 88 144 0
91 -84 -2 0
5 -74 -145 0
-106 171 140 0
90 -134 115 0
145 50 -13 0
12 54 24 0
-129 101 -18 0
-60 -126 5 0
-179 -107 100 0
-103 -35 -7 0
34 66 7 0
-128 -23 -11 0
70 -92 23 0
19 166 140 0
-154 87 173 0
77 -103 -70 0
-26 177 86 0
152 72 -141 0
95 -64 -169 0
-147 57 -162 0
21 69 124 0
-157 -5 -68 0
128 11 -66 0
-154 61 92 0
18 -11 -175 0
-119 51 163 0
58 157 176 0
-124 63 -10 0
71 -160 -127 0
26 87 136 0
94 -148 134 0
49 -82 43 0
-164 -87 -167 0
162 -83 -167 0
-66 126 55 0
-88 -92 167 0
64 106 158 0
113 124 -118 0
-84 -91 146 0
160 114 131 0
-57 43 -7 0
160 -38 -65 0
-7 83 129 0
-131 82 -48 0
-79 122 -121 0
-157 54 -176 0
40 44 -56 0
-116 -98 36 0
26 142 -69 0
-20 90 -69 0
-117 -50 -111 0
-17 173 108 0
-96 31 -98 0
-164 30 -151 0
120 139 -50 0
-144 147 56 0
4 91 -39 0
-126 155 105 0
-174 106 -7 0
-169 86 136 0
121 -20 -55 0
-97 -93 104 0
-164 -104 102 0
-8 101 -39 0
-124 -31 -107 0
88 93 -63 0
-28 -84 -108 0
-91 135 155 0
-76 112 35 0
-50 99 56 0
-114 -77 56 0
-76 -99 13 0
-20 16 117 0
-11 1 179 0
-11 -68 133 0
81 155 -17 0
106 110 158 0
123 -137 -78 0
94 -11 -123 0
-137 -174 136 0
-138 154 36 0
19 -72 -78 0
165 14 -2 0
116 -26 119 0
107 79 -10 0
120 82 -158 0
24 55 -139 0
22 -25 102 0
-32 -94 -36 0
-64 150 5 0
-178 60 33 0
166 62 110 0
-77 -138 -11 0
12 -146 101 0
-73 -1 -123 0
15 -154 -150 0
109 -59 115 0
33 139 42 0
174 -177 -13 0
-124 146 125 0
136 1 -173 0
-172 -147 -51 0
142 45 163 0
-150 -177 137 0
52 170 -71 0
-54 -178 -83 0
-129 -51 127 0
-110 -141 -19 0
-155 129 87 0
-153 -116 84 0
101 139 54 0
119 -134 92 0
67 -49 110 0
-2 59 -53 0
75 105 100 0
51 -85 112 0
-41 -22 -120 0
-78 92 48 0
138 102 -108 0
-98 -26 90 0
-132 111 -113 0
-30 -160 170 0
-163 78 58 0
129 24 169 0
112 166 107 0
92 -12 104 0
169 -49 107 0
44 -86 -55 0
-83 -88 4 0
-103 -158 -71 0
37 18 -130 0
-62 -175 51 0
157 -137 -97 0
-72 -141 -96 0
-163 -40 -146 0
32 133 -10 0
-180 28 -102 0
-138 88 -157 0
-139 -179 -80 0
-80 -21 -169 0
15 -168 -10 0
-63 -41 -96 0
29 -95 -118 0
-83 -87 146 0
-119 -62 -135 0
60 -175 -128 0
81 145 73 0
93 -167 112 0
28 -79 -158 0
163 171 -162 0
-74 100 138 0
153 69 -176 0
-153 -174 -65 0
141 -29 165 0
126 158 112 0
-165 92 161 0
-82 125 15 0
15 -170 -71 0
68 89 -118 0
-172 56 45 0
-120 -52 177 0
-129 -127 168 0
-36 49 -147 0
135 -47 -10 0
16 -103 -28 0
52 -64 -87 0
-105 -71 140 0
-9 97 -136 0
95 -85 -93 0
-161 82 -107 0
-118 11 83 0
16 132 -21 0
166 103 -102 0
44 68 -19 0
149 -150 -170 0
8 -93 -6 0
-142 -29 66 0
-47 -85 -112 0
19 123 -2 0
-119 149 -152 0
-144 99 -150 0
-19 152 51 0
118 13 147 0
-73 -25 -15 0
173 -13 -11 0
-126 -98 -35 0
-160 91 60 0
27 -52 45 0
122 -33 -13 0
53 -22 87 0
-78 -44 -89 0
-11 -117 33 0
107 121 -143 0
-166 -66 147 0
140 124 29 0
115 -52 -112 0
-18 94 149 0
-141 142 -144 0
8 -152 56 0
107 40 -110 0
106 110 -144 0
-47 -167 -162 0
15 14 -91 0
27 93 -157 0
146 105 -138 0
154 38 127 0
170 39 -156 0
17 -19 84 0
-170 23 -46 0
36 -91 -81 0
-114 161 -113 0
167 -136 -16 0
-54 -134 -33 0
30 47 -127 0
-10 12 -14 0
-91 141 28 0
-32 -44 -38 0
-144 90 142 0
1 -118 -169 0
-178 -44 -79 0
-115 -70 -109 0
111 -102 93 0
21 -90 83 0
82 -50 154 0
158 -114 -82 0
-96 -174 137 0
-18 -161 -19 0
-24 -2 -136 0
-34 175 167 0
-155 13 -124 0
130 98 -76 0
-61 109 -143 0
-24 149 33 0
148 132 -44 0
-79 17 169 0
-127 158 150 0
162 139 -37 0
-100 66 -65 0
67 -50 78 0
107 -124 59 0
-72 114 -24 0
-172 -52 -118 0
-82 115 42 0
-90 -48 51 0
-80 -45 124 0
-106 -180 46 0
58 -172 129 0
87 105 -52 0
-99 -178 -176 0
-52 -4 113 0
-113 101 -76 0
-51 68 67 0
-10 -68 77 0
128 138 -126 0
10 147 20 0
-47 50 -126 0
-61 -73 -112 0
-77 -46 -138 0
37 -102 -12 0
62 -2 31 0
-165 32 -4 0
-169 -134 149 0
137 -32 33 0
127 49 67 0
-169 -84 -47 0
-43 6 117 0
20 104 54 0
122 141 103 0
-72 -142 -149 0
2 -62 -10 0
-136 -103 -9 0
-173 -44 -24 0
-8 57 169 0
9 -146 -47 0
76 -28 146 0
-149 -115 89 0
94 -157 81 0
176 -106 162 0
12 -2 -123 0
-82 -25 60 0
-123 74 -180 0
-62 -38 -36 0
-87 -99 44 0
-131 -82 122 0
-115 -85 -52 0
163 44 -117 0
63 42 -136 0
4 16 -71 0
-64 42 -142 0
-104 -15 106 0
4 139 -89 0
-70 -42 144 0
86 17 -91 0
7 -29 -21 0
-16 -127 -104 0
154 144 -157 0
-16 -121 -51 0
-124 164 142 0
-145 -39 -165 0
136 91 44 0
100 -33 -3 0
110 167 -47 0
2 -128 -105 0
-76 -142 73 0
55 95 -121 0
62 -12 20 0
20 -34 -14 0
-175 -99 19 0
166 74 175 0
61 -123 100 0
127 92 21 0
1 -38 -3 0
135 107 -38 0
174 12 19 0
176 97 136 0
152 -3 102 0
163 -108 -6 0
15 -47 -56 0
92 164 -105 0
-144 11 46 0
26 113 49 0
141 152 -7 0
-39 16 37 0
-129 -101 -50 0
-42 89 111 0
27 72 -84 0
167 -4 11 0
-154 -178 176 0
138 -149 -73 0
-89 9 -127 0
"""
output = "UNSAT"
|
def multiplication_table(size):
return [[ x * y for y in range(1, size + 1)] for x in range(1, size + 1)]
print(multiplication_table(3)) # [[1,2,3],[2,4,6],[3,6,9]] |
algo = input('Digite algo: ')
print('Tipo do valor:', type(algo))
print('è um número ?:', algo.isnumeric())
print('é alfabeto', algo.isalpha())
print('é um alfanumerico ', algo.isalnum())
|
a=5
b=50
if a>=b:
c=a-b
else:
c=a-b
print(c)
|
# -*- coding: utf-8 -*-
# Put here your production specific settings
ADMINS = [
('Francesca Alberti', 'francydark91@gmail.com'),
]
EMAIL_SUBJECT_PREFIX = '[ALBERTIFRA]' |
# autocord
# package for simple automation with discord client
#
# m: error
class ApiError(Exception):
pass |
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
copy("src", "out_encodings")
run("""
coverage run utf8.py
coverage annotate utf8.py
""", rundir="out_encodings")
compare("out_encodings", "gold_encodings", "*,cover")
clean("out_encodings")
|
"""
0604. Design Compressed String Iterator
Design and implement a data structure for a compressed string iterator. The given compressed string will be in the form of each letter followed by a positive integer representing the number of this letter existing in the original uncompressed string.
Implement the StringIterator class:
next() Returns the next character if the original string still has uncompressed characters, otherwise returns a white space.
hasNext() Returns true if there is any letter needs to be uncompressed in the original string, otherwise returns false.
Example 1:
Input
["StringIterator", "next", "next", "next", "next", "next", "next", "hasNext", "next", "hasNext"]
[["L1e2t1C1o1d1e1"], [], [], [], [], [], [], [], [], []]
Output
[null, "L", "e", "e", "t", "C", "o", true, "d", true]
Explanation
StringIterator stringIterator = new StringIterator("L1e2t1C1o1d1e1");
stringIterator.next(); // return "L"
stringIterator.next(); // return "e"
stringIterator.next(); // return "e"
stringIterator.next(); // return "t"
stringIterator.next(); // return "C"
stringIterator.next(); // return "o"
stringIterator.hasNext(); // return True
stringIterator.next(); // return "d"
stringIterator.hasNext(); // return True
Constraints:
1 <= compressedString.length <= 1000
compressedString consists of lower-case an upper-case English letters and digits.
The number of a single character repetitions in compressedString is in the range [1, 10^9]
At most 100 calls will be made to next and hasNext.
"""
class StringIterator:
def __init__(self, compressedString: str):
self.tokens = []
for token in re.findall('\D\d+', compressedString):
self.tokens.append((token[0], int(token[1:])))
self.tokens = self.tokens[::-1]
def next(self):
if not self.tokens: return ' '
t, n = self.tokens.pop()
if n > 1:
self.tokens.append((t, n - 1))
return t
def hasNext(self):
return bool(self.tokens)
# Your StringIterator object will be instantiated and called as such:
# obj = StringIterator(compressedString)
# param_1 = obj.next()
# param_2 = obj.hasNext() |
class HarmonyConfig(object):
def __init__(self, config):
self.json = config
def get_activities(self):
return self._build_kv_menu('activity')
def get_devices(self):
return self._build_kv_menu('device')
def _build_kv_menu(self, key):
menu = {}
for d in self.json[key]:
menu.update({int(d['id']): d['label']})
return menu |
# Copyright 2018 Databricks, Inc.
VERSION = "1.12.1.dev0"
|
#!/usr/bin/env python
#
# Copyright (c) 2018 10X Genomics, Inc. All rights reserved.
#
__MRO__ = """
stage CHOOSE_DIMENSION_REDUCTION(
in bool chemistry_batch_correction,
out bool disable_run_pca,
out bool disable_correct_chemistry_batch,
src py "stages/analyzer/choose_dimension_reduction",
)
"""
def main(args, outs):
if args.chemistry_batch_correction is None or args.chemistry_batch_correction is False:
outs.disable_run_pca = False
outs.disable_correct_chemistry_batch = True
else:
outs.disable_run_pca = True
outs.disable_correct_chemistry_batch = False
|
'''https://leetcode.com/problems/longest-common-subsequence/
1143. Longest Common Subsequence
Medium
4663
55
Add to List
Share
Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.
A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
For example, "ace" is a subsequence of "abcde".
A common subsequence of two strings is a subsequence that is common to both strings.
Example 1:
Input: text1 = "abcde", text2 = "ace"
Output: 3
Explanation: The longest common subsequence is "ace" and its length is 3.
Example 2:
Input: text1 = "abc", text2 = "abc"
Output: 3
Explanation: The longest common subsequence is "abc" and its length is 3.
Example 3:
Input: text1 = "abc", text2 = "def"
Output: 0
Explanation: There is no such common subsequence, so the result is 0.
Constraints:
1 <= text1.length, text2.length <= 1000
text1 and text2 consist of only lowercase English characters.'''
# Time: O(m * n)
# Space: O(min(m, n))
class Solution(object):
def longestCommonSubsequence(self, text1, text2):
"""
:type text1: str
:type text2: str
:rtype: int
"""
if len(text1) < len(text2):
return self.longestCommonSubsequence(text2, text1)
dp = [[0 for _ in range(len(text2)+1)] for _ in range(2)]
for i in range(1, len(text1)+1):
for j in range(1, len(text2)+1):
dp[i % 2][j] = dp[(i-1) % 2][j-1]+1 if text1[i-1] == text2[j-1] \
else max(dp[(i-1) % 2][j], dp[i % 2][j-1])
return dp[len(text1) % 2][len(text2)]
|
# Copyright 2021 BenchSci Analytics Inc.
# Copyright 2021 Nate Gay
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"rules_kustomize"
load("//:kustomization.bzl", _kustomization = "kustomization")
load("//:kustomize_image.bzl", _kustomize_image = "kustomize_image")
kustomization = _kustomization
kustomize_image = _kustomize_image
|
class Program:
language = 'Python'
def say_hello():
print(f'Hello from {Program.language}')
p = Program()
print(type(p))
print(p.__dict__)
print(Program.__dict__)
print(p.__class__)
# BEST PRACTICES
print(isinstance(p, Program))
|
def assert_status_with_message(status_code=200, response=None, message=None):
"""
Check to see if a message is contained within a response.
:param status_code: Status code that defaults to 200
:type status_code: int
:param response: Flask response
:type response: str
:param message: String to check for
:type message: str
:return: None
"""
assert response.status_code == status_code
assert message in str(response.data)
|
# -*- coding: utf-8 -*-
# @Author: 何睿
# @Create Date: 2019-01-15 16:40:08
# @Last Modified by: 何睿
# @Last Modified time: 2019-01-15 17:49:45
class MinStack(object):
# 栈中存储的是元组(当前位置的值,当前位置到栈底所有值的最小值)
def __init__(self):
"""
initialize your data structure here.
"""
self.stack = []
def push(self, x):
"""
:type x: int
:rtype: void
"""
# 获取最小值
curmin = self.getMin()
if curmin == None or curmin > x:
curmin = x
# 存入元组
self.stack.append((x, curmin))
def pop(self):
"""
:rtype: void
"""
self.stack.pop()
def top(self):
"""
:rtype: int
"""
if len(self.stack) == 0:
return None
else:
return self.stack[len(self.stack)-1][0]
def getMin(self):
"""
:rtype: int
"""
if len(self.stack) == 0:
return None
else:
return self.stack[len(self.stack)-1][1]
|
class TreeLeaf( object ):
"""Base class for Tree Leaf objects.
Supports a single parent.
Cannot have children.
"""
def __init__( self ):
"""Creates a tree leaf object.
"""
super( TreeLeaf, self ).__init__()
self._parent = None
@property
def parent( self ):
"""The current parent of the node or None
if there isn't one.
This is an @property decorated method which allows
retrieval and assignment of the scale value.
"""
if self._parent != None:
return self._parent()
return None
def predecessors( self ):
"""Returns successive parents of the node.
Generator function that allows iteration
up the tree.
"""
parent = self.parent
while parent != None:
yield parent
parent = parent.parent
|
def roman_to_int(s):
s = s.upper()
try:
rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
int_val = 0
for i in range(len(s)):
if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:
int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]
else:
int_val += rom_val[s[i]]
return int_val
except KeyError:
pass
return None |
#!/usr/bin/env python3
"""
This module containes general-purpose chemical data (aka tables).
Sources:
1. www.ccdc.cam.ac.uk/Lists/ResourceFileList/Elemental_Radii.xlsx, (access
date: 13 Oct 2015)
2. C. W. Yong, 'DL_FIELD - A force field and model development tool for
DL_POLY', R. Blake, Ed., CSE Frontier, STFC Computational Science and
Engineering, Daresbury Laboratory, UK, p38-40 (2010)
3. https://www.ccdc.cam.ac.uk/support-and-resources/ccdcresources/
Elemental_Radii.xlsx (access date: 26 Jul 2017)
Note:
Added atomic mass, atomic van der Waals radius and covalent radius, that equals
1, for a dummy atom `X`. This is for the shape descriptors calculations to use
with functions for molecular shape descriptors that require mass.
"""
# Atomic mass dictionary (in upper case!)
atomic_mass = {
'AL': 26.982,
'SB': 121.76,
'AR': 39.948,
'AS': 74.922,
'BA': 137.327,
'BE': 9.012,
'BI': 208.98,
'B': 10.811,
'BR': 79.904,
'CD': 112.411,
'CS': 132.905,
'CA': 40.078,
'C': 12.011,
'CE': 140.116,
'CL': 35.453,
'CR': 51.996,
'CO': 58.933,
'CU': 63.546,
'DY': 162.5,
'ER': 167.26,
'EU': 151.964,
'F': 18.998,
'GD': 157.25,
'GA': 69.723,
'GE': 72.61,
'AU': 196.967,
'HF': 178.49,
'HE': 4.003,
'HO': 164.93,
'H': 1.008,
'IN': 114.818,
'I': 126.904,
'IR': 192.217,
'FE': 55.845,
'KR': 83.8,
'LA': 138.906,
'PB': 207.2,
'LI': 6.941,
'LU': 174.967,
'MG': 24.305,
'MN': 54.938,
'HG': 200.59,
'MO': 95.94,
'ND': 144.24,
'NE': 20.18,
'NI': 58.693,
'NB': 92.906,
'N': 14.007,
'OS': 190.23,
'O': 15.999,
'PD': 106.42,
'P': 30.974,
'PT': 195.078,
'K': 39.098,
'PR': 140.908,
'PA': 231.036,
'RE': 186.207,
'RH': 102.906,
'RB': 85.468,
'RU': 101.07,
'SM': 150.36,
'SC': 44.956,
'SE': 78.96,
'SI': 28.086,
'AG': 107.868,
'NA': 22.991,
'SR': 87.62,
'S': 32.066,
'TA': 180.948,
'TE': 127.6,
'TB': 158.925,
'TL': 204.383,
'TH': 232.038,
'TM': 168.934,
'SN': 118.71,
'TI': 47.867,
'W': 183.84,
'U': 238.029,
'V': 50.942,
'XE': 131.29,
'YB': 173.04,
'Y': 88.906,
'ZN': 65.39,
'ZR': 91.224,
'X': 1,
}
# Atomic vdW radii dictionary (in upper case!)
atomic_vdw_radius = {
'AL': 2,
'SB': 2,
'AR': 1.88,
'AS': 1.85,
'BA': 2,
'BE': 2,
'BI': 2,
'B': 2,
'BR': 1.85,
'CD': 1.58,
'CS': 2,
'CA': 2,
'C': 1.7,
'CE': 2,
'CL': 1.75,
'CR': 2,
'CO': 2,
'CU': 1.4,
'DY': 2,
'ER': 2,
'EU': 2,
'F': 1.47,
'GD': 2,
'GA': 1.87,
'GE': 2,
'AU': 1.66,
'HF': 2,
'HE': 1.4,
'HO': 2,
'H': 1.09,
'IN': 1.93,
'I': 1.98,
'IR': 2,
'FE': 2,
'KR': 2.02,
'LA': 2,
'PB': 2.02,
'LI': 1.82,
'LU': 2,
'MG': 1.73,
'MN': 2,
'HG': 1.55,
'MO': 2,
'ND': 2,
'NE': 1.54,
'NI': 1.63,
'NB': 2,
'N': 1.55,
'OS': 2,
'O': 1.52,
'PD': 1.63,
'P': 1.8,
'PT': 1.72,
'K': 2.75,
'PR': 2,
'PA': 2,
'RE': 2,
'RH': 2,
'RB': 2,
'RU': 2,
'SM': 2,
'SC': 2,
'SE': 1.9,
'SI': 2.1,
'AG': 1.72,
'NA': 2.27,
'SR': 2,
'S': 1.8,
'TA': 2,
'TE': 2.06,
'TB': 2,
'TL': 1.96,
'TH': 2,
'TM': 2,
'SN': 2.17,
'TI': 2,
'W': 2,
'U': 1.86,
'V': 2,
'XE': 2.16,
'YB': 2,
'Y': 2,
'ZN': 1.29,
'ZR': 2,
'X': 1,
}
# Atomic covalent radii dictionary (in upper case!)
atomic_covalent_radius = {
'AL': 1.21,
'SB': 1.39,
'AR': 1.51,
'AS': 1.21,
'BA': 2.15,
'BE': 0.96,
'BI': 1.48,
'B': 0.83,
'BR': 1.21,
'CD': 1.54,
'CS': 2.44,
'CA': 1.76,
'C': 0.68,
'CE': 2.04,
'CL': 0.99,
'CR': 1.39,
'CO': 1.26,
'CU': 1.32,
'DY': 1.92,
'ER': 1.89,
'EU': 1.98,
'F': 0.64,
'GD': 1.96,
'GA': 1.22,
'GE': 1.17,
'AU': 1.36,
'HF': 1.75,
'HE': 1.5,
'HO': 1.92,
'H': 0.23,
'IN': 1.42,
'I': 1.4,
'IR': 1.41,
'FE': 1.52,
'KR': 1.5,
'LA': 2.07,
'PB': 1.46,
'LI': 1.28,
'LU': 1.87,
'MG': 1.41,
'MN': 1.61,
'HG': 1.32,
'MO': 1.54,
'ND': 2.01,
'NE': 1.5,
'NI': 1.24,
'NB': 1.64,
'N': 0.68,
'OS': 1.44,
'O': 0.68,
'PD': 1.39,
'P': 1.05,
'PT': 1.36,
'K': 2.03,
'PR': 2.03,
'PA': 2,
'RE': 1.51,
'RH': 1.42,
'RB': 2.2,
'RU': 1.46,
'SM': 1.98,
'SC': 1.7,
'SE': 1.22,
'SI': 1.2,
'AG': 1.45,
'NA': 1.66,
'SR': 1.95,
'S': 1.02,
'TA': 1.7,
'TE': 1.47,
'TB': 1.94,
'TL': 1.45,
'TH': 2.06,
'TM': 1.9,
'SN': 1.39,
'TI': 1.6,
'W': 1.62,
'U': 1.96,
'V': 1.53,
'XE': 1.5,
'YB': 1.87,
'Y': 1.9,
'ZN': 1.22,
'ZR': 1.75,
'X': 1,
}
# Atom symbols - atom keys pairs for deciphering OPLS force field
# from dl_field.atom_type file - DL_FIELD 3.5 by C. W. Yong
opls_atom_keys = {
# The list has to be case sensitive.
# The OPLS atom types can overlap in case of noble gasses.
# 'He' - helim, 'HE' or 'he' - hydrogen
# 'Ne'- neon, 'NE' or 'ne' - imine nitrogen
# 'Na' - sodium, 'NA' - nitrogen
# In case of these there still a warning sould be raised
# as 'ne' can be just lower case for 'Ne'.
'Ar': ['AR', 'Ar', 'ar'],
'B': ['B', 'b'],
'Br': ['BR', 'BR-', 'Br', 'br', 'br-'],
'C': [
'CTD', 'CZN', 'C', 'CBO', 'CZB', 'CDS', 'CALK', 'CG', 'CML', 'C5B',
'CTP', 'CTF', 'C5BC', 'CZA', 'CTS', 'CO', 'C5X', 'CQ', 'CP1', 'CDXR',
'CANI', 'CRA', 'C4T', 'CHZ', 'CAO', 'CTA', 'CDX', 'CA5', 'CTJ', 'CZ',
'CO4', 'CTI', 'C5BB', 'CG1', 'C5M', 'CTM', 'CT', 'C5A', 'CN', 'C3M',
'CB', 'CT1', 'C5N', 'CO3', 'CTQ', 'CTH', 'CTU', 'CTE', 'CTC', 'CTG',
'C3T', 'CD', 'CME', 'CT_F', 'CA', 'C56B', 'CT1G', 'C56A', 'CM', 'CTNC',
'CR3', 'ctd', 'czn', 'c', 'cbo', 'czb', 'cds', 'calk', 'cg', 'cml',
'c5b', 'ctp', 'ctf', 'c5bc', 'cza', 'cts', 'co', 'c5x', 'cq', 'cp1',
'cdxr', 'cani', 'cra', 'c4t', 'chz', 'cao', 'cta', 'cdx', 'ca5', 'ctj',
'cz', 'co4', 'cti', 'c5bb', 'cg1', 'c5m', 'ctm', 'ct', 'c5a', 'cn',
'c3m', 'cb', 'ct1', 'c5n', 'co3', 'ctq', 'cth', 'ctu', 'cte', 'ctc',
'ctg', 'c3t', 'cd', 'cme', 'ct_f', 'ca', 'c56b', 'ct1g', 'c56a', 'cm',
'ctnc', 'cr3'
],
'Cl': ['CL', 'CL-', 'Cl', 'cl', 'cl-'],
'F': [
'F', 'FX1', 'FX2', 'FX3', 'FX4', 'FG', 'F-', 'f', 'fx1', 'fx2', 'fx3',
'fx4', 'fg', 'f-'
],
'H': [
'HA', 'HAE', 'HS', 'HT3', 'HC', 'HWS', 'H', 'HNP', 'HAM', 'H_OH', 'HP',
'HT4', 'HG', 'HMET', 'HO', 'HANI', 'HY', 'HCG', 'HE', 'ha', 'hae',
'hs', 'ht3', 'hc', 'hws', 'h', 'hnp', 'ham', 'h_oh', 'hp', 'ht4', 'hg',
'hmet', 'ho', 'hani', 'hy', 'hcg'
],
'He': ['He'],
'I': ['I', 'I-', 'i', 'i-'],
'Kr': ['Kr', 'kr'],
'N': [
'NAP', 'NN', 'NB', 'N5BB', 'NS', 'NOM', 'NTC', 'NP', 'N', 'NTH2',
'NTH', 'NZC', 'NO', 'N5B', 'NO3', 'NZT', 'NZ', 'NI', 'NTH0', 'NA5B',
'NT', 'NO2', 'NBQ', 'NG', 'NE', 'NZA', 'NA', 'NZB', 'NHZ', 'NO2B',
'NEA', 'NA5', 'NE', 'nap', 'nn', 'nb', 'n5bb', 'ns', 'nom', 'ntc',
'np', 'n', 'nth2', 'nth', 'nzc', 'no', 'n5b', 'no3', 'nzt', 'nz', 'ni',
'nth0', 'na5b', 'nt', 'no2', 'nbq', 'ng', 'nza', 'nzb', 'nhz', 'no2b',
'nea', 'na5'
],
'Na': ['Na', 'Na+'],
'Ne': ['Ne'],
'O': [
'OM', 'OAB', 'ONI', 'O2ZP', 'O2Z', 'OHE', 'OES', 'OBS', 'OT4', 'OWS',
'O3T', 'OT3', 'O4T', 'OAL', 'O2', 'OAS', 'OS', 'ON', 'OVE', 'OZ', 'O',
'OHX', 'OY', 'ONA', 'OA', 'OHP', 'OSP', 'OH', 'om', 'oab', 'oni',
'o2zp', 'o2z', 'ohe', 'oes', 'obs', 'ot4', 'ows', 'o3t', 'ot3', 'o4t',
'oal', 'o2', 'oas', 'os', 'on', 'ove', 'oz', 'o', 'ohx', 'oy', 'ona',
'oa', 'ohp', 'osp', 'oh'
],
'P':
['P', 'P1', 'P2', 'P3', 'P4', 'PR', 'p', 'p1', 'p2', 'p3', 'p4', 'pr'],
'Rn': ['Rn', 'rn'],
'S': [
'S', 'SX6', 'SY', 'SH', 'SA', 'SZ', 'SD', 's', 'sx6', 'sy', 'sh', 'sa',
'sz', 'sd'
],
'Xe': ['Xe', 'xe']
}
|
class OuterClass(object):
def outer_method(self):
def nested_function():
class InnerClass(object):
class InnermostClass(object):
def innermost_method(self):
print()
InnerClass.InnermostClass().innermost_method()
nested_function()
OuterClass().outer_method()
|
# -*- coding: utf-8 -*-
#
# Copyright (c) 2015, ParaTools, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# (1) Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# (2) Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# (3) Neither the name of ParaTools, Inc. nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""TODO: FIXME: Docs
TAU Commander core software architecture.
TAU Commander follows the `Model-View-Controller (MVC)`_ architectural pattern.
Packages in :py:mod:`taucmdr.model` define models and controllers. The `model` module
declares the model attributes as a dictionary named `ATTRIBUTES` in the form::
<attribute>: {
property: value,
[[property: value], ...]
}
Attribute properties can be anything you wish, including these special properties:
* ``type`` (str): The attribute is of the specified type.
* ``required`` (bool): The attribute must be specified in the data record.
* ``model`` (str): The attribute associates this model with another data model.
* ``collection`` (str): The attribute associates this model with another data model.
* ``via`` (str): The attribute associates with another model "via" the specified attribute.
The `controller` module declares the controller as a subclass of :any:`Controller`. Controller
class objects are not bound to any particular data record and so can be used to create, update,
and delete records. Controller class instances **are** bound to a single data record.
Models may have **associations** and **references**. An association creates a relationship between
an attribute of this model and an attribute of another (a.k.a foreign) model. If the associated
attribute changes then the foreign model will update its associated attribute. A reference indicates
that this model is being referened by one or more attributes of a foreign model. If a record of the
referenced model changes then the referencing model, i.e. the foreign model, will update all referencing
attributes.
Associations, references, and attributes are constructed when :py:mod:`taucmdr.model` is imported.
Examples:
*One-sided relationship*
::
class Pet(Controller):
attributes = {'name': {'type': 'string'}, 'hungry': {'type': 'bool'}}
class Person(Controller):
attributes = {'name': {'type': 'string'}, 'pet': {'model': 'Pet'}}
We've related a Person to a Pet but not a Pet to a Person. That is, we can query a Person
to get information about their Pet, but we can't query a Pet to get information about their Person.
If a Pet record changes then the Person record that referenced the Pet record is notified of the
change. If a Person record changes then nothing happens to Pet. The Pet and Person classes codify
this relationship as:
* Pet.references = set( (Person, 'pet') )
* Pet.associations = {}
* Person.references = set()
* Person.associations = {}
Some example data for this model::
{
'Pet': {1: {'name': 'Fluffy', 'hungry': True}},
'Person': {0: {'name': 'Bob', 'pet': 1}}
}
*One-to-one relationship*
::
class Husband(Controller):
attributes = {'name': {'type': 'string'}, 'wife': {'model': 'Wife'}}
class Wife(Controller):
attributes = {'name': {'type': 'string'}, 'husband': {'model': 'Husband'}}
We've related a Husband to a Wife. The Husband may have only one Wife and the Wife may have
only one Husband. We can query a Husband to get information about their Wife and we can query a
Wife to get information about their Husband. If a Husband/Wife record changes then the Wife/Husband
record that referenced the Husband/Wife record is notified of the change. The Husband and Wife classes
codify this relationship as:
* Husband.references = set( (Wife, 'husband') )
* Husband.associations = {}
* Wife.references = set( (Husband, 'wife') )
* Wife.associations = {}
Example data::
{
'Husband': {2: {'name': 'Filbert', 'wife': 1}},
'Wife': {1: {'name': 'Matilda', 'husband': 2}}
}
*One-to-many relationship*
::
class Brewery(Controller):
attributes = {'address': {'type': 'string'},
'brews': {'collection': 'Beer',
'via': 'origin'}}
class Beer(Controller):
attributes = {'origin': {'model': 'Brewery'},
'color': {'type': 'string'},
'ibu': {'type': 'int'}}
We've related one Brewery to many Beers. A Beer has only one Brewery but a Brewery has zero or
more Beers. The `brews` attribute has a `via` property along with a `collection` property to specify
which attribute of Beer relates Beer to Brewery, i.e. you may want a model to have multiple
one-to-many relationship with another model. The Brewery and Beer classes codify this relationship as:
* Brewery.references = set()
* Brewery.associations = {'brews': (Beer, 'origin')}
* Beer.references = set()
* Beer.associations = {'origin': (Brewery, 'brews')}
Example data::
{
'Brewery': {100: {'address': '4615 Hollins Ferry Rd, Halethorpe, MD 21227',
'brews': [10, 12, 14]}},
'Beer': {10: {'origin': 100, 'color': 'gold', 'ibu': 45},
12: {'origin': 100, 'color': 'dark', 'ibu': 15},
14: {'origin': 100, 'color': 'pale', 'ibu': 30}}
}
*Many-to-many relationship*
::
class Actor(Controller):
attributes = {'home_town': {'type': 'string'},
'appears_in': {'collection': 'Movie',
'via': 'cast'}}
class Movie(Controller):
attributes = {'title': {'type': 'string'},
'cast': {'collection': 'Actor',
'via': 'appears_in'}}
An Actor may appear in many Movies and a Movie may have many Actors. Changing the `cast` of a Movie
notifies Actor and changing the movies an Actor `apppears_in` notifies Movie. This relationship is
codified as:
* Actor.references = set()
* Actor.associations = {'appears_in': (Movies, 'cast')}
* Movie.references = set()
* Movie.associations = {'cast': (Actor, 'appears_in')}
.. _Model-View-Controller (MVC): https://en.wikipedia.org/wiki/Model-view-controller
"""
|
# S-box Table
# We have 8 different 4x16 matrices for each S box
#It converts 48 bits to 32 bits
# Each S box will get 6 bits and output will be 4 bits
s_box = [
[[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
[0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
[4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
[15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13]],
[[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
[3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
[0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
[13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9]],
[[10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
[13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
[13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
[1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12]],
[[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
[13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
[10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
[3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14]],
[[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
[14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
[4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
[11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3]],
[[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
[10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
[9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
[4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13]],
[[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
[13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
[1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
[6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]],
[[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
[1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
[7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
[2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]]
]
# Round count: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Bits shifted:1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1
# Number of bit shifts
shift_table=[1, 1, 2, 2,
2, 2, 2, 2,
1, 2, 2, 2,
2, 2, 2, 1 ]
# Initial Permutation Table: (input of 64bit block size is pasesed: 64bit -> 64bit)
initial_perm = [58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7]
# Permuted choice 1: (key is passed: 64bit -> 56bit)
# That is bit position 8, 16, 24, 32, 40, 48, 56 and 64 are discarded from the key.
perm_cho_1= [57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4]
# Permuted choice 2: (key is passed into it after applying
# left shift to both halves: 56bit -> 56bit)
perm_cho_2= [14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32]
# Expansion permutation table
expan_perm=[32, 1, 2, 3, 4, 5,
4, 5, 6, 7, 8, 9,
8, 9, 10, 11, 12, 13,
12, 13, 14, 15, 16, 17,
16, 17, 18, 19, 20, 21,
20, 21, 22, 23, 24, 25,
24, 25, 26, 27, 28, 29,
28, 29, 30, 31, 32, 1]
# Permutation table
perm_table=[16, 7, 20, 21, 29, 12, 28, 17,
1, 15, 23, 26, 5, 18, 31, 10,
2, 8, 24, 14, 32, 27, 3, 9,
19, 13, 30, 6, 22, 11, 4, 25]
# Final Permutaion Table
final_perm = [40, 8, 48, 16, 56, 24, 64, 32,
39, 7, 47, 15, 55, 23, 63, 31,
38, 6, 46, 14, 54, 22, 62, 30,
37, 5, 45, 13, 53, 21, 61, 29,
36, 4, 44, 12, 52, 20, 60, 28,
35, 3, 43, 11, 51, 19, 59, 27,
34, 2, 42, 10, 50, 18, 58, 26,
33, 1, 41, 9, 49, 17, 57, 25 ]
# XOR function
def xor(a,b):
# a and b should be in binary
ans=""
for i in range(len(a)):
if(a[i]==b[i]):
ans=ans+"0"
else:
ans=ans+"1"
return ans
# Hexadecimal to binary conversion
def hexa_to_bin(msg):
mp = {'0' : "0000",
'1' : "0001",
'2' : "0010",
'3' : "0011",
'4' : "0100",
'5' : "0101",
'6' : "0110",
'7' : "0111",
'8' : "1000",
'9' : "1001",
'A' : "1010",
'B' : "1011",
'C' : "1100",
'D' : "1101",
'E' : "1110",
'F' : "1111" }
bin = ""
for i in range(len(msg)):
bin = bin + mp[msg[i]]
return bin
# Binary to hexadecimal conversion
def bin_to_hexa(msg):
mp = {"0000" : '0',
"0001" : '1',
"0010" : '2',
"0011" : '3',
"0100" : '4',
"0101" : '5',
"0110" : '6',
"0111" : '7',
"1000" : '8',
"1001" : '9',
"1010" : 'A',
"1011" : 'B',
"1100" : 'C',
"1101" : 'D',
"1110" : 'E',
"1111" : 'F' }
hex=""
for i in range(0,len(msg),4):
ch=""
ch=ch+msg[i]
ch=ch+msg[i+1]
ch=ch+msg[i+2]
ch=ch+msg[i+3]
hex=hex+mp[ch]
return hex
# Binary to decimal conversion
def bin_to_dec(msg):
decimal,i=0,0
while(msg!=0):
dec=msg%10
decimal=decimal+dec*pow(2, i)
msg=msg//10
i+=1
return decimal
# Decimal to binary conversion
def dec_to_bin(num):
res=bin(num).replace("0b", "")
if(len(res)%4 != 0):
div=len(res) / 4
div=int(div)
counter=(4*(div+1))-len(res)
for i in range(0, counter):
res='0'+res
return res
# shifting the bits towards left by nth shifts
def shift_left(key,nth_shifts):
s=""
for i in range(nth_shifts):
for j in range(1,len(key)):
s=s+key[j]
s=s+key[0]
key=s
s=""
return key
# Step1: It is just rearranging the positions of all bits of plain text
# according to the initial_perm matrix(8x8)
def initial_permutation(plain_text,initial_perm, no_bits):
permutation=""
for i in range(0,no_bits):
permutation=permutation+plain_text[initial_perm[i]-1]
return permutation
# Encryption function is implemented here
def encrypt(msg,key):
print("Encryption")
msg=hexa_to_bin(msg)
msg = initial_permutation(msg, initial_perm, 64)
print("Message after initial permutation: ",bin_to_hexa(msg))
# converting from hexa to binary
key = hexa_to_bin(key)
key = initial_permutation(key, perm_cho_1, 56)
print("The converted 56bit key is: ",key)
# Halving the key
l=key[0:28]
r=key[28:56]
# Halving the message
left = msg[0:32]
right =msg[32:64]
# Key transformation
key_from_pc2_bin=[]
key_from_pc2_hex=[]
for k in range(16):
l=shift_left(l,shift_table[k])
r=shift_left(r,shift_table[k])
combine_key=l+r
# permuted choice 2
round_key=initial_permutation(combine_key,perm_cho_2,48)
key_from_pc2_bin.append(round_key)
key_from_pc2_hex.append(bin_to_hexa(round_key))
# For decryption, just uncomment below two lines
# key_from_pc2_bin=key_from_pc2_bin[::-1]
# key_from_pc2_hex=key_from_pc2_hex[::-1]
# Message transformation
# Encryption
print()
print("Round: Left key part: Right key part: SubKey used:")
for j in range(16):
# Expansion Permutation
right_expand=initial_permutation(right,expan_perm,48)
xor_x=xor(right_expand,key_from_pc2_bin[j])
# calculating row and column from s box
s_box_str=""
for i in range(0,8):
row=bin_to_dec(int(xor_x[i*6]+xor_x[i*6+5]))
col=bin_to_dec(int(xor_x[i*6+1]+xor_x[i*6+2]+xor_x[i*6+3]+xor_x[i*6+4]))
val=s_box[i][row][col]
s_box_str=s_box_str+dec_to_bin(val)
# towards permutation box
s_box_str=initial_permutation(s_box_str,perm_table,32)
# Now again XOR with left part and above
result=xor(left,s_box_str)
left=result
# Swapping
if(j!=15):
left, right=right, left
print(str(j+1).zfill(2)," ",bin_to_hexa(left)," ",bin_to_hexa(right)," ",key_from_pc2_hex[j])
# concatinating both left and right
combine=left+right
cipher_text=initial_permutation(combine,final_perm,64)
return cipher_text
# Padding function
def pad(msg):
if(len(msg)%16!=0):
print("Padding required")
for i in range(abs(16-(len(msg)%16))):
msg=msg+'0'
else:
print("No padding required")
return(msg)
# Main function
print("Enter the message to be encrypted: ")
plain_text=input()
plain_text=pad(plain_text)
print("Message after padding: ", plain_text)
print("Enter the 64bit key for encryption: ")
key=input()
key=pad(key)
print("Key after padding: ",key)
cipher_text=bin_to_hexa(encrypt(plain_text,key))
print("Cipher text is: ",cipher_text)
'''
----------OUTPUT----------
Enter the message to be encrypted:
536ABCD8910FF9
Padding required
Message after padding: 536ABCD8910FF900
Enter the 64bit key for encryption:
74631BBDCA8
Padding required
Key after padding: 74631BBDCA800000
Encryption
Message after initial permutation: 4B5D24715C466E23
The converted 56bit key is: 00111000000100110000101100000001011000001001000111001101
Round: Left key part: Right key part: SubKey used:
01 5C466E23 6E81D6DE A289056D34C0
02 6E81D6DE 8F2C919D 8A34034AB231
03 8F2C919D 7C74DB60 69064C734D28
04 7C74DB60 69DDF400 40D08808191A
05 69DDF400 44AE2868 108972C57034
06 44AE2868 B2467F7F A46803610AE8
07 B2467F7F 458145D1 23270490981F
08 458145D1 488D0D53 4814910716B4
09 488D0D53 62E16561 494060887282
10 62E16561 0A6342EC 80C9B8746225
11 0A6342EC EA0DAA35 942303B208CA
12 EA0DAA35 7669590A 231E0184B313
13 7669590A 5706FABD 4930C4372660
14 5706FABD 29B656BD 10C4D8788942
15 29B656BD 31FA5C5F 54412204E41E
16 6A1A9764 31FA5C5F 16AB20801DC9
Cipher text is: 86760F7ABEE16B24
>>>
'''
'''
For decryption, we have to add just two lines, which server the purpose of
reversing the array, which stores the sub keys for different rounds
For decryption, just we have to reverse the array which stores the sub keys:
key_from_pc2_bin=key_from_pc2_bin[::-1]
key_from_pc2_hex=key_from_pc2_hex[::-1]
'''
'''
----------OUTPUT----------
Enter the message to be decrypted:
86760F7ABEE16B24
No padding required
Message after padding: 86760F7ABEE16B24
Enter the 64bit key for decryption:
74631BBDCA8
Padding required
Key after padding: 74631BBDCA800000
Encryption
Message after initial permutation: 6A1A976431FA5C5F
The converted 56bit key is: 00111000000100110000101100000001011000001001000111001101
Round: Left key part: Right key part: SubKey used:
01 31FA5C5F 29B656BD 16AB20801DC9
02 29B656BD 5706FABD 54412204E41E
03 5706FABD 7669590A 10C4D8788942
04 7669590A EA0DAA35 4930C4372660
05 EA0DAA35 0A6342EC 231E0184B313
06 0A6342EC 62E16561 942303B208CA
07 62E16561 488D0D53 80C9B8746225
08 488D0D53 458145D1 494060887282
09 458145D1 B2467F7F 4814910716B4
10 B2467F7F 44AE2868 23270490981F
11 44AE2868 69DDF400 A46803610AE8
12 69DDF400 7C74DB60 108972C57034
13 7C74DB60 8F2C919D 40D08808191A
14 8F2C919D 6E81D6DE 69064C734D28
15 6E81D6DE 5C466E23 8A34034AB231
16 4B5D2471 5C466E23 A289056D34C0
Plain text is: 536ABCD8910FF900
>>>
'''
'''
Took help from: https://www.geeksforgeeks.org/data-encryption-standard-des-set-1
Thanks for the help !
'''
|
# Python INTRO for TD Users
# Kike Ramírez
# May, 2018
# Understanding Dictioinaries
# Declaring a dictionary
Dict = {'Tim': 18,'Charlie':12,'Tiffany':22,'Robert':25}
# Print a chosen value
print((Dict['Tiffany']))
# Copy a dictionary
DictCopy = Dict.copy()
print(DictCopy)
# Update a dictionary
Dict.update({"Sarah":9})
print(Dict)
# Delete a key
del Dict ['Charlie']
print(Dict)
# Items to retrive data
print("Students Name: %s" % list(Dict.items()))
# Checking if a key exist
Boys = {'Tim': 18,'Charlie':12,'Robert':25}
for key in list(Boys.keys()):
if key in list(Dict.keys()):
print(True)
else:
print(False) |
# Split target image into an MxN grid
def splitImage(image, size):
W, H = image.size[0], image.size[1]
m, n = size
w, h = int(W/n), int(H/m)
imgs = []
for j in range(m):
for i in range(n):
# append cropped image
imgs.append(image.crop((i*w, j*h, (i+1)*w, (j+1)*h)))
return imgs |
def is_vowel(s: str) -> bool:
if len(s) == 0 or len(s) > 1:
return False
vowel = ["a", "e", "i", "o", "u"]
for item in s:
if item.lower() in vowel:
return True
return False |
# content of test_sample.py
def func(x):
return x + 2
def test_answer():
assert func(3) == 5
def test_2():
assert func(10) == 12 |
'''
Created on Aug 7, 2017
@author: duncan
'''
class Subscriber(object):
def __init__(self, subscriber_id, subscriber_email):
self.subscriber_id = subscriber_id
self.subscriber_email = subscriber_email
class Site(object):
def __init__(self, site_id, site_name):
self.site_id = site_id
self.site_name = site_name
class Keyword(object):
def __init__(self, keyword_id, keyword_name):
self.keyword_id = keyword_id
self.keyword_name = keyword_name
class Subscription():
def __init__(self, site, keyword, subscription_group_id=None, subscriber=None, page_limit=1, minimum_alert=1):
'''
Constructor
'''
self.subscriber = subscriber
self.site = site
self.keyword = keyword
self.page_limit = page_limit
self.minimum_alert = minimum_alert
self.subscription_group_id = subscription_group_id
|
'''
Se um objeto anda como um pato e faz quack como um pato então ele é um pato
Se o objeto responde a uma caracteristica ele pode ser considerado do mesmo tipo.
Programa para interfaces e não para uma implementação
'''
class Livro():
def __init__(self, titulo, lancamento, autor):
self.titulo = titulo
self.lancamento = lancamento
self.autor = autor
class Filme():
def __init__(self, titulo, lancamento, diretor):
self.titulo = titulo
self.lancamento = lancamento
self.diretor = diretor
def imprimir(midia):
print(midia.titulo, midia.lancamento)
class Pato:
def quack(self):
print('quack, quack!')
class Pessoa:
def quack(self):
print('QUACK!')
def na_floresta(obj):
obj.quack()
na_floresta(Pato())
na_floresta(Pessoa())
|
# 2. Use the function to compute the square of all numbers of a given list
def squares(a):
squared = a*a
return squared
li = [1, 2, 3, 4, 5]
lisq=[]
for el in li:
sq = squares(el)
lisq.append(sq)
print(lisq) |
# coding: utf-8
__author__ = 'Keita Tomochika'
__version__ = '0.0.1'
__license__ = 'MIT'
|
name = "openjpeg"
version = "2.3.1"
authors = [
"Image and Signal Processing Group, UCL"
]
description = \
"""
OpenJPEG is an open-source JPEG 2000 codec written in C language. It has been developed in order to promote the
use of JPEG 2000, a still-image compression standard from the Joint Photographic Experts Group.
"""
requires = [
"cmake-3+",
"gcc-6+",
"png-1.6+",
"tiff-4+",
"zlib-1.2+"
]
variants = [
["platform-linux"]
]
tools = [
"opj_compress",
"opj_decompress",
"opj_dump"
]
build_system = "cmake"
with scope("config") as config:
config.build_thread_count = "logical_cores"
uuid = "openjpeg-{version}".format(version=str(version))
def commands():
env.PATH.prepend("{root}/bin")
env.LD_LIBRARY_PATH.prepend("{root}/lib")
env.PKG_CONFIG_PATH.prepend("{root}/lib/pkgconfig")
# We know that the version numbers are separated by a ".", so we should safely be able to get the
# number we want through a split.
env.CMAKE_MODULE_PATH.prepend("{root}/lib/openjpeg-" + str(version).split(".")[0] + "." + str(version).split(".")[1])
# Helper environment variables.
env.OPENJPEG_BINARY_PATH.set("{root}/bin")
env.OPENJPEG_INCLUDE_PATH.set("{root}/include")
env.OPENJPEG_LIBRARY_PATH.set("{root}/lib")
|
# Subject - the one to be observed
# Observers - the one monitoring or observing the subject for changes
class Subject:
def __init__(self):
self.__observers = []
def register(self, observer):
self.__observers.append(observer)
def notifyAll(self, *args, **kwargs):
for observer in self.__observers:
observer.notify(self, *args, **kwargs)
class Observer1:
def __init__(self, subject):
subject.register(self)
def notify(self, subject, *args):
pass
class Observer2:
def __init__(self, subject):
subject.register(self)
def notify(self, subject, *args):
pass
subject = Subject()
observer1 = Observer1(subject)
Observer2 = Observer2(subject)
subject.notifyAll("notification")
|
# Seeing the greatest number
def high():
print('-'*50)
print('The numbers informed are: ', end='')
for n in numbers:
print(n, end= ' ')
print('')
print('-'*50)
print(f'At all, were informed {len(numbers)} values.')
print(f'The highest number informed was {max(numbers)}')
print('-'*50)
# Function to continue the program
def cont():
c = str(input('Do you want to continue?[y/n]: ')).strip().lower()[0]
while c not in 'yn':
c = str(input('Do you want to continue?[y/n]: ')).strip().lower()[0]
if c == 'y':
numbers.clear()
return c
# Main program
numbers = []
while True:
print('-'*50)
quantity_num = int(input('How many numbers do you want to insert?: '))
if quantity_num > 0:
for q in range(quantity_num):
num = int(input(f'Insert the {q+1}º number: '))
numbers.append(num)
high()
else:
print('-'*50)
print('There\'s no number informed.')
print('-'*50)
if cont() == 'n':
break
print('-'*25 + '-'*25)
print(' '*20 + ' FINISHED ' + ' '*20)
print('-'*25 + '-'*25)
|
def galoisMult(a, b):
'''
The parameter b will be either 1, 2 or 3. Multiplication by 3 is defined as multiplication by 2 then adding the
original value. For example 3x6 is equivalent to 2x6+6. The multiplication by 2 is done with a left shift
(a <<= 1) and dropping the MSB. If that bit had been a 1 then remainder after dividing by the irreducible
polynomial 00011011 (1b). This polynomial is described in the literature as a 9 bit value 100011011, or in its
Galois form x8 + x4 + x3 + x1 + 1
:param a: the original value to be multiplied.
:param b: the value to be multiplied by
:return: the result
'''
result = 0
for i in range(b): # This needs to run once for x1, twice for x2 and thrice for x3
if b & 1 == 1: # If the LSB is 1. This will happen with x1 and x3
result ^= a # Add the original value to result. This is the + part of x3 = x2 +1
hiBitSet = a & 0x80 # Before doing x2 check to see if a is > 128
a <<= 1 # Do x2
a &= 0xff # reduce 9 bit numbers to 8 bit
if hiBitSet == 0x80: # If the original value of a was > 128 then the result is > 256 so reduce.
a ^= 0x1b # XOR with the irreducible polynomial
b >>= 1 # Rotate b
return result
if __name__ == '__main__':
#print(hex(galoisMult(0xa0, 1))) # a0
#print(hex(galoisMult(0xd4, 2))) # b3
#print(hex(galoisMult(0xbf, 3))) # da
print(hex(galoisMult(0x7f, 0)))
print(hex(galoisMult(0x7f, 1)))
print(hex(galoisMult(0x7f, 2)))
print(hex(galoisMult(0x7f, 3)))
|
diff_counter = 0
A = input()
B = input()
for i in range(len(A)):
if A[i] != B[i]:
diff_counter += 1
if diff_counter > 1:
print("LARRY IS DEAD!")
elif diff_counter == 1:
print("LARRY IS SAVED!")
else:
print("LARRY IS DEAD!")
|
"""
dir([object])
Without arguments, return the list of names in the current local scope. With an argument,
attempt to return a list of valid attributes for that object.
"""
class A:
name = "Derick"
age = 30
class Shape:
def __dir__(self):
return ['area', 'location', 'shape',]
def b():
c = 1
if __name__ == "__main__":
print("-------Calling dir with no arguments-------")
print(dir())
print("-------Calling dir on a class that does not implement the __dir__ method-------")
print(dir(A))
print("-------Calling dir on a class that implements the __dir__ method-------")
s = Shape()
print(dir(s))
print("-------Calling dir on a function-------")
print(dir(b))
|
class Method:
CHAR = 'char'
WORD = 'word'
SPECTROGRAM = 'spectrogram'
AUDIO = 'audio'
FLOW = 'flow'
@staticmethod
def getall():
return [Method.CHAR, Method.WORD, Method.AUDIO, Method.SPECTROGRAM, Method.FLOW]
|
#!/usr/bin/env/python
inp = open('top-1m.csv', 'r')
out = open('top-1m__.csv', 'a+')
out.write('"domain_id,"domain_name"')
id = ''
domain = ''
while True:
line = inp.readline()
if len(line) > 0:
cPos = line.find(',')
id = line[:cPos]
domain = line[cPos+1:]
domain = '"'+domain.rstrip()+'"'
final = id+','+domain+'\n'
out.write(final)
else:
break
inp.close()
out.close() |
TINY_TEST = False
if TINY_TEST:
MIN_BOUND = -2
MAX_BOUND = 2
else:
MIN_BOUND = -200
MAX_BOUND = 200
WIDTH = (MAX_BOUND - MIN_BOUND) + 3
M = [["."] * WIDTH for i in range(WIDTH)]
def setMap(p, v):
x, y = p
M[y - MIN_BOUND + 1][x - MIN_BOUND + 1] = v
def getMap(p):
x, y = p
return M[y - MIN_BOUND + 1][x - MIN_BOUND + 1]
START = (0, 0)
if TINY_TEST:
GOAL = (2, 2)
setMap(START, "S")
setMap(GOAL, "G")
obstacles = [(1, 1)]
for p in obstacles:
setMap(p, "#")
else:
N, X, Y = [int(x) for x in input().split()]
setMap((X, Y), "G")
for i in range(N):
p = [int(x) for x in input().split()]
setMap(p, "#")
def pp(map):
for line in map:
print("".join(line))
def main():
def visit(x, y):
if getMap((x, y)) == "G":
return True
if getMap((x, y)) != ".":
return
if x < MIN_BOUND-1 or MAX_BOUND+1 < x:
return
if y < MIN_BOUND-1 or MAX_BOUND+1 < y:
return
newFront.append((x, y))
setMap((x, y), "v")
newFront = [START]
for numSteps in range(1, 1000):
front = set(newFront)
# print("len front,", len(front), numSteps)
# print(front)
newFront = []
for x, y in front:
isFinished = (
visit(x + 1, y + 1)
or visit(x, y + 1)
or visit(x - 1, y + 1)
or visit(x + 1, y)
or visit(x - 1, y)
or visit(x, y - 1))
if isFinished:
print(numSteps)
return
if not newFront:
print(-1)
return
main()
|
def even_numbers(func):
def wrapper(nums):
numbers = func(nums)
return [num for num in numbers if num % 2 == 0]
return wrapper
@even_numbers
def get_numbers(numbers):
return numbers
print(get_numbers([1, 2, 3, 4, 5]))
|
SEASONS = {
1: {
"TITLE" : "Destiny 2",
"EXPANSION" : "Destiny 2",
"ACTIVE" : False,
"YEAR" : "1",
"START" : '2017-09-06 17:00:00',
"END" : '2017-12-05 17:00:00',
},
2: {
"TITLE" : "Curse of Osiris",
"EXPANSION" : "Destiny 2",
"ACTIVE" : False,
"YEAR" : "1",
"START" : '2017-12-05 17:00:01',
"END" : '2018-05-08 17:00:00',
},
3: {
"TITLE" : "Warmind",
"EXPANSION" : "Destiny 2",
"ACTIVE" : False,
"YEAR" : "1",
"START" : '2018-05-08 17:00:01',
"END" : '2018-09-04 17:00:00',
},
4: {
"TITLE" : "Season of the Outlaw",
"EXPANSION" : "Forsaken",
"ACTIVE" : False,
"YEAR" : "2",
"START" : '2018-09-04 17:00:01',
"END" : '2018-12-04 17:00:00',
},
5: {
"TITLE" : "Season of the Forge",
"EXPANSION" : "Forsaken",
"ACTIVE" : False,
"YEAR" : "2",
"START" : '2018-12-04 17:00:01',
"END" : '2019-03-05 17:00:00',
},
6: {
"TITLE" : "Season of the Drifter",
"EXPANSION" : "Forsaken",
"ACTIVE" : False,
"YEAR" : "2",
"START" : '2019-03-05 17:00:01',
"END" : '2019-06-04 17:00:00',
},
7: {
"TITLE" : "Season of Opulence",
"EXPANSION" : "Forsaken",
"ACTIVE" : False,
"YEAR" : "2",
"START" : '2019-06-04 17:00:01',
"END" : '2019-09-30 17:00:00',
},
8: {
"TITLE" : "Season of the Undying",
"EXPANSION" : "Shadowkeep",
"ACTIVE" : False,
"YEAR" : "3",
"START" : '2019-09-30 17:00:01',
"END" : '2019-12-10 17:00:00',
},
9: {
"TITLE" : "Season of Dawn",
"EXPANSION" : "Shadowkeep",
"ACTIVE" : False,
"YEAR" : "3",
"START" : '2019-12-10 17:00:01',
"END" : '2020-03-09 17:00:00',
},
10: {
"TITLE" : "Season of the Worthy",
"ACTIVE" : False,
"EXPANSION" : "Shadowkeep",
"YEAR" : "3",
"START" : '2020-03-09 17:00:01',
"END" : '2020-06-09 17:00:00',
},
11: {
"TITLE" : "Season of Arrivals",
"ACTIVE" : False,
"EXPANSION" : "Shadowkeep",
"YEAR" : "3",
"START" : '2020-06-09 17:00:01',
"END" : '2020-10-10 17:00:00',
},
12: {
"TITLE" : "Season of the Hunt",
"ACTIVE" : False,
"EXPANSION" : "Beyond Light",
"YEAR" : "4",
"START" : '2020-10-10 17:00:01',
"END" : '2021-02-09 17:00:00',
},
13: {
"TITLE" : "Season of the Chosen",
"ACTIVE" : False,
"EXPANSION" : "Beyond Light",
"YEAR" : "4",
"START" : '2021-02-09 17:00:01',
"END" : '2021-05-11 17:00:00',
},
14: {
"TITLE" : 'Season of the Splicer',
"ACTIVE" : False,
"EXPANSION" : 'Beyond Light',
"YEAR" : '4',
"START" : '2021-05-11 17:00:01',
"END" : '2021-08-24 17:00:00',
},
15: {
"TITLE": 'Season of the Lost',
"ACTIVE": True,
"EXPANSION": 'Beyond Light',
"YEAR": '4',
"START": '2021-08-24 17:00:01',
"END": '2022-02-22 17:00:00',
},
}
CURRENT_SEASON = 15
# CURRENT_SEASON = list(SEASONS)[-1]
LAST_SEASON = CURRENT_SEASON - 1
|
# Given a sorted integer array without duplicates, return the summary of its ranges.
# Example 1:
# Input: [0,1,2,4,5,7]
# Output: ["0->2","4->5","7"]
# Explanation: 0,1,2 form a continuous range; 4,5 form a continuous range.
# Example 2:
# Input: [0,2,3,4,6,8,9]
# Output: ["0","2->4","6","8->9"]
# Explanation: 2,3,4 form a continuous range; 8,9 form a continuous range.
class Solution(object):
def summaryRanges(self, nums):
"""
:type nums: List[int]
:rtype: List[str]
"""
# 模拟 线性扫描 O(n)
# 从前往后扫描整个数组,扫描时维护当前区间的起点 st 和终点 ed,
# 如果当前数可以接在区间结尾,则更新 ed;
# 否则打印 [st,ed],
# 然后将 st 和 ed 更新成当前数。
# 时间复杂度分析:每个数仅被遍历一次,所以时间复杂度是 O(n)。
if not nums:
return []
res = []
st = ed = nums[0]
for num in nums[1:]:
if num == ed + 1:
ed += 1
else:
res.append(str(st) if st == ed else str(st) + '->' + str(ed))
st = ed = num
# for the last case
res.append(str(st) if st == ed else str(st) + '->' + str(ed))
return res |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2019-04-10 16:23
# @Author : fgyong 简书:_兜兜转转_ https://www.jianshu.com/u/6d1254c1d145
# @Site : http://fgyong.cn 兜兜转转的技术博客
# @File : Int_sort.py
# @Software: PyCharm
#得出root为最大值 左右儿子为左右堆的最大值
def big_endian(arr:list,start:int,end:int):
root = start
while True:
child = root*2 +1#左孩子
if child>end:
break#取出最大孩子
if child +1 <= end and arr[child] < arr[child + 1]:
child +=1
if arr[root] < arr[child]:#最大孩子和root交换
arr[root],arr[child] = arr[child],arr[root]
root = child ####调整子树为大堆子树#####
else:
break
#堆排序主函数时间复杂度 0(n*log2 N) 辅助内存0(1)
def head_sort(arr:list) ->[]:
firt = len(arr)//2-1#从倒数第2层扫描 调整到 root>child
for start in range(firt,-1,-1):#然后扫描倒数第三行 直到扫描root节点
big_endian(arr,start,len(arr)-1)#调整为root 为最大值 左右儿子为次大小
for end in range(len(arr)-1,0,-1):
arr[0],arr[end] = arr[end],arr[0]
big_endian(arr,0,end-1)#顶部和尾部交换,调整大小堆
return arr
#选择排序 时间复杂度0(n^2) 辅助内存0(1)
#每次挑选最大或者最小值放到最前边
def selection_sort(list2):
for i in range(0, len (list2)-1):
min_ = i
for j in range(i + 1, len(list2)):
if list2[j] < list2[min_]:
min_ = j
list2[i], list2[min_] = list2[min_], list2[i] # swap
return list2
#插入排序 时间复杂度 0(n^2) 辅助内存0(1) 最好:0(n) 最坏0(n^2)
def insert_sort(lis:list):
for i in range(1,len(lis)): #默认第一个元素已经在有序序列中,从后面元素开始插入
for j in range(i,0,-1): #逆向遍历比较,交换位置实现插入
if lis[j] < lis[j-1]:
lis[j],lis[j-1] = lis[j-1],lis[j]
return lis
#冒泡排序 时间复杂度 0(n^2) 辅助内存0(1) 最好:0(n) 最坏0(n^2)
def bubble_sort(nums):
for i in range(len(nums) - 1): # 这个循环负责设置冒泡排序进行的次数
for j in range(len(nums) - i - 1): # j为列表下标
if nums[j] > nums[j + 1]:
nums[j], nums[j + 1] = nums[j + 1], nums[j]
return nums
#快速排序 时间复杂度0(nlog2 N) 最好0(nlog2 N) 最坏0(n^2) 辅助内存 0(nlog2 N)
def quick_sort(li:list,low:int,hi:int) ->None:
if low>=hi:return
i = low
h = hi
tmp = li[i]#双指针 左右比较 最后空下来的位子是之前的存储的tmp
while i < h:
while i<h and li[h] > tmp:
h -=1
li[i] = li[h]
while i < h and li[i] < tmp:
i +=1
li[h]= li[i]
li[i] = tmp
quick_sort(li,low,i-1)
quick_sort(li,i+1,hi)
#希尔排序 step 由大变小 最后变成有序时间复杂度0(n^1.3-2)最坏0(n^2)
def shell_sort(li:list)->None:
step = len(li)
while step > 1:
step = step // 3 + 1
for i in range(step, len(li)):
if li[i - step] > li[i]:
li[i], li[i - step] = li[i - step], li[i]
### 归并排序
def merge_sort(li:list):
if len(li)<=1:return li
mi = len(li)//2
l = merge_sort(li[:mi])
r = merge_sort(li[mi:])
return merge(l,r)
### 合并数组
def merge(left:list,right:list)->list:
i,j=0,0
res = []
while i<len(left) and j<len(right):
if left[i]<right[j]:
res.append(left[i])
i +=1
else:
res.append(right[j])
j+=1
res +=left[i:]
res += right[j:]
return res
def main():
l = [1,3,2,0,12,10,8]
print(merge_sort(l)) # 原地排序
# print(l)
if __name__ == "__main__":
main()
|
#Day 6 : Lets Review
for i in range(int(input())):
char = input()
print("".join(char[::2]),"".join(char[1::2])) |
# Copyright 2017 Therp BV, ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Client side message boxes",
"version": "13.0.1.0.0",
"author": "Therp BV, " "ACSONE SA/NV, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Hidden/Dependency",
"summary": "Show a message box to users",
"depends": ["web"],
"data": ["views/templates.xml"],
"qweb": ["static/src/xml/web_ir_actions_act_window_message.xml"],
}
|
def linked_sort(a,b,kf=''):
mapped = sorted([(i,j) for i,j in zip(a,b)], key=kf or standard)
bsr=[j for i,j in mapped]
a.sort(key=(kf or standard))
b.sort(key=lambda x: bsr.index(x))
return a
standard = lambda x: str(x)
|
def findDecision(obj): #obj[0]: Coupon, obj[1]: Education
# {"feature": "Education", "instances": 34, "metric_value": 0.9597, "depth": 1}
if obj[1]>1:
# {"feature": "Coupon", "instances": 19, "metric_value": 0.998, "depth": 2}
if obj[0]<=3:
return 'True'
elif obj[0]>3:
return 'False'
else: return 'False'
elif obj[1]<=1:
# {"feature": "Coupon", "instances": 15, "metric_value": 0.8366, "depth": 2}
if obj[0]>2:
return 'True'
elif obj[0]<=2:
return 'False'
else: return 'False'
else: return 'True'
|
one = ['1']
two = ['3']
three = ['9']
a = '1'
b = '3'
c = '9'
v = [0,0,0]
for i in range(1000):
v[0] = int(a)
v[1] = int(b)
v[2] = int(c)
for i in range(len(a)) :
v[0] += int(a[i])
for i in range(len(b)) :
v[1] += int(b[i])
for i in range(len(a)) :
v[2] += int(c[i])
one.append(str(v[0]))
two.append(str(v[1]))
three.append(str(v[2]))
a = str(v[0])
b = str(v[1])
c = str(v[2])
n = input("N: ")
s = n
while True :
num = int(s)
for i in range(len(s)) :
num += int(s[i])
if str(num) in one :
print(f"1 {num}")
break
'''elif str(num) in two :
print(f"3 {num}")
break
elif str(num) in three :
print(f"9 {num}")
break'''
s = str(num)
|
class MovieTrackingCamera:
distortion_model = None
division_k1 = None
division_k2 = None
focal_length = None
focal_length_pixels = None
k1 = None
k2 = None
k3 = None
pixel_aspect = None
principal = None
sensor_width = None
units = None
|
print("digite um numero para consultar seu intervalo")
x = int(input())
if 0 <= x <= 25:
print('Intervalo [0,25]')
if 25 < x <= 50:
print('Intervalo (25,50]')
if 50 < x <= 75:
print('Intervalo (50,75]')
if 75 < x <= 100:
print('Intervalo (75,100]')
else:
print('Fora de intervalo')
|
"""
Implement pow(x, n), which calculates x raised to the power n (i.e., xn).
source - https://leetcode.com/problems/powx-n
"""
"""
Time Complexity - O(Logn)
Space Complexity - 1
"""
# Faster
class Solution:
def myPow(self, x: float, n: int) -> float:
return pow(x, n)
"""
Time Complexity - O(Logn)
Space Complexity - 1
"""
class Solution:
def myPow(self, x: float, n: int) -> float:
if n < 0:
x = 1/x
n = -n
res = 1
while n:
if n & 1:
res *= x
n >>= 1
x *= x
return res
|
"""
Shape Vertices.
How to iterate over the vertices of a shape.
When loading an obj or SVG, getVertexCount()
will typically return 0 since all the vertices
are in the child shapes.
You should iterate through the children and then
iterate through their vertices.
"""
def setup():
size(640, 360)
# Load the shape
global uk
uk = loadShape("uk.svg")
def draw():
background(51)
# Center where we will draw all the vertices
translate(width / 2 - uk.width / 2, height / 2 - uk.height / 2)
# Iterate over the children
children = uk.getChildCount()
for i in xrange(children):
child = uk.getChild(i)
total = child.getVertexCount()
# Now we can actually get the vertices from each child
for j in xrange(total):
v = child.getVertex(j)
# Cycling brightness for each vertex
stroke((frameCount + (i + 1) * j) % 255)
# Just a dot for each one
point(v.x, v.y)
|
class HttpRequest():
def __init__(self, scope, body, receive, metadata=None, application=None):
self._application = application
self._scope = scope
self._body = body
self._cookies = None
self._receive = receive
self._subdomain, self._headers = metadata
self._params = None
def _parse_qs(self):
qs = self._scope.get('query_string')
qsd = {}
if not qs: return qsd
else: qs = qs.decode() if isinstance(qs, bytes) else qs
query_kv_pairs = qs.split('&')
for kv_pair in query_kv_pairs:
key, value = kv_pair.split('=')
current_value = qsd.get(key)
if not current_value:
qsd[key] = value
else:
if isinstance(current_value, list): current_value.append(value)
else: qsd[key] = [current_value, value]
return qsd
@property
def app(self):
return self._application
@property
def body(self):
return self._body.get('body')
@property
def cookies(self):
if not self._cookies:
csd = {}
cookiestring = self.headers.get('cookie')
if not cookiestring: self._cookies = csd; return self._cookies
cookies = cookiestring.split('; ')
for cookie in cookies:
k, v = cookie.split('=')
csd[k] = v
self._cookies = csd
return self._cookies
@property
def headers(self):
if not self._headers:
self._headers = {}
for header in self._scope.get('headers'):
self._headers[header[0]] = header[1]
return self._headers
@property
def method(self):
return self._scope.get('method')
@property
def params(self):
if not self._params:
self._params = self._parse_qs()
return self._params
@params.setter
def params(self, pair):
if not self._params:
self._params = {}
self._params[pair[0]] = pair[1]
@property
def querystring(self):
return self._scope.get('query_string', '')
@property
def subdomain(self):
return self._subdomain
@property
def url(self):
return self._scope.get('path')
async def stream(self):
"""TODO: Revisit and implement with appropriate testing"""
return await self._receive()
|
"""
Given an array of integers nums and an integer target, return indices
of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution,
and you may not use the same element twice.
You can return the answer in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Output: Because nums[0] + nums[1] == 9, we return [0, 1].
Example 2:
Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:
Input: nums = [3,3], target = 6
Output: [0,1]
Constraints:
2 <= nums.length <= 104
-109 <= nums[i] <= 109
-109 <= target <= 109
Only one valid answer exists.
"""
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
hashmap = {}
for idx in range(len(nums)):
diff = target-nums[idx]
if diff in hashmap:
return [idx, hashmap[diff]]
hashmap[nums[idx]] = idx
|
# This dict is built through the metaclass applied to ExternalProvider.
# It is intentionally empty here, and should remain empty.
PROVIDER_LOOKUP = dict()
def get_service(name):
"""Given a service name, return the provider class"""
return PROVIDER_LOOKUP[name]()
|
dbodydict = dict() # dtitle, dbody
fdbody = open("sample_alldoc_fake_body.dict")
while 1:
line = fdbody.readline()
if not line:
break
tks = line.strip().split(' ')
dbodydict[tks[0]]=tks[1]
fclean = open("sample_valid_cqexp.cleaned")
fexp = open("sample_valid_cqbody.cleaned",'w')
while 1:
line = fclean.readline()
if not line:
break
tks = line.strip().split(' ')
q = tks[0]
dp = tks[1]
dn = tks[2]
dpcq = tks[3]
dncq = tks[4]
dpbody = '0'
dnbody = '0'
if dp in dbodydict:
dpbody = dbodydict[dp]
if dn in dbodydict:
dnbody = dbodydict[dn]
out = str(q)+' '+str(dp)+' '+str(dn)+' '+str(dpcq)+' '+str(dncq)+' '+str(dpbody)+' '+str(dnbody)+'\n'
fexp.write(out)
|
""" Complex Boolean Expressions
if 18.5 <= weight / height**2 < 25:
print("BMI is considered 'normal'")
if is_raining and is_sunny:
print("Is there a rainbow?")
if (not unsubscribed) and (location == "USA" or location == "CAN"):
print("send email")
Good and Bad Examples
1. Don't use True or False as conditions
# Bad example
if True:
print("This indented code will always get run.")
# Another bad example
if is_cold or not is_cold:
print("This indented code will always get run.")
2. Be careful writing expressions that use logical operators
# Bad example
if weather == "snow" or "rain":
print("Wear boots!")
3. Don't compare a boolean variable with == True or == False
# Bad example
if is_cold == True:
print("The weather is cold!")
# Good example
if is_cold:
print("The weather is cold!")
""" |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def viterbi(obs, states, start_p, trans_p, emit_p):
V = [{}] # list of dictionaries
for st in states:
V[0][st] = {"prob": start_p[st] * emit_p[st][obs[0]], "prev": None}
# Run Viterbi when t > 0
for t in range(1, len(obs)):
V.append({})
for st in states:
max_tr_prob = max(V[t-1][prev_st]["prob"]*trans_p[prev_st][st] for prev_st in states)
for prev_st in states:
if V[t-1][prev_st]["prob"] * trans_p[prev_st][st] == max_tr_prob:
max_prob = max_tr_prob * emit_p[st][obs[t]]
V[t][st] = {"prob": max_prob, "prev": prev_st}
break
for line in dptable(V):
print(line)
opt = []
# The highest probability
max_prob = max(value["prob"] for value in V[-1].values())
previous = None
# Get most probable state and its backtrack
for st, data in V[-1].items():
if data["prob"] == max_prob:
opt.append(st)
previous = st
break
# Follow the backtrack till the first observation
for t in range(len(V) - 2, -1, -1):
opt.insert(0, V[t + 1][previous]["prev"])
previous = V[t + 1][previous]["prev"]
print('The steps of states are ' + ' '.join(opt) + ' with highest probability of %s' % max_prob)
def dptable(V):
# Print a table of steps from dictionary
yield " ".join(("%12d" % i) for i in range(len(V)))
for state in V[0]:
yield "%.7s: " % state + " ".join("%.7s" % ("%f" % v[state]["prob"]) for v in V)
# tupel of observations
obs = ('normal', 'cold', 'dizzy')
# tupel of states
states = ('Healthy', 'Fever')
# dictionary of initial probabilities
start_p = {'Healthy': 0.6, 'Fever': 0.4}
# state transition probabilities
trans_p = {
'Healthy' : {'Healthy': 0.7, 'Fever': 0.3},
'Fever' : {'Healthy': 0.4, 'Fever': 0.6}
}
# transition probabilities from states to observations
emit_p = {
'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1},
'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6}
}
if __name__ == "__main__":
viterbi(obs, states, start_p, trans_p, emit_p)
|
# username and password
# import sys
# import msvcrt
# passwor = ''
# while True:
# x = msvcrt.getch()
# if x == '\r':
# break
# sys.stdout.write('*')
# passwor +=x
# print '\n'+pass
username= input ("enter your username: \n")
password = input ("enter your password: \n")
print (" you completed your rwgestration \n welcome to the access world")
user = input ("what is your user name? : \n")
passw = input ("what is your passsword? :\n")
if (username == user and password == passw):
print ("welcome to next level")
else:
print ("Incorrect Information") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.