prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
<|fim_middle|>
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | return (next_specific(landing_square, "R"),
chance_card, chest_card) |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
<|fim_middle|>
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | return (landing_square, chance_card, chest_card) |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
<|fim_middle|>
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | raise Exception("Case should not occur") |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
<|fim_middle|>
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | doubles += 1 |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
<|fim_middle|>
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | doubles = 0 |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
<|fim_middle|>
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | doubles = 0
current = "JAIL" |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
<|fim_middle|>
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card) |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
<|fim_middle|>
<|fim▁end|> | print euler_timer(84)(main)(verbose=True) |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def <|fim_middle|>(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | roll_die |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def <|fim_middle|>(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | back |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def <|fim_middle|>(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | next_specific |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def <|fim_middle|>(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def main(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | next_square |
<|file_name|>no084.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
from random import choice
from python.decorators import euler_timer
SQUARES = ["GO",
"A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",
"JAIL",
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",
"FP",
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",
"G2J",
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"]
def roll_die(size):
first_die = choice(range(1, size + 1))
second_die = choice(range(1, size + 1))
return (first_die + second_die, (first_die == second_die))
def back(square, step):
index = SQUARES.index(square)
new_index = (index - step) % len(SQUARES)
return SQUARES[new_index]
def next_specific(square, next_type):
if next_type not in ["R", "U"]:
raise Exception("next_specific only intended for R and U")
# R1=5, R2=15, R3=25, R4=35
index = SQUARES.index(square)
if next_type == "R":
if 0 <= index < 5 or 35 < index:
return "R1"
elif 5 < index < 15:
return "R2"
elif 15 < index < 25:
return "R3"
elif 25 < index < 35:
return "R4"
else:
raise Exception("Case should not occur")
# U1=12, U2=28
elif next_type == "U":
if 0 <= index < 12 or index > 28:
return "U1"
elif 12 < index < 28:
return "U2"
else:
return Exception("Case should not occur")
else:
raise Exception("Case should not occur")
def next_square(landing_square, chance_card, chest_card):
if landing_square not in ["CC1", "CC2", "CC3", "CH1", "CH2", "CH3", "G2J"]:
return (landing_square, chance_card, chest_card)
if landing_square == "G2J":
return ("JAIL", chance_card, chest_card)
elif landing_square in ["CC1", "CC2", "CC3"]:
# 1/16 Go, Jail
# 14/16 Stay
chest_card = (chest_card + 1) % 16
if chest_card == 0:
return ("GO", chance_card, chest_card)
elif chest_card == 1:
return ("JAIL", chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
elif landing_square in ["CH1", "CH2", "CH3"]:
# 1/16 Go, Jail, C1, E3, H2, R1, next U, back 3
# 1/8 Next R
chance_card = (chance_card + 1) % 16
if chance_card == 0:
return ("GO", chance_card, chest_card)
elif chance_card == 1:
return ("JAIL", chance_card, chest_card)
elif chance_card == 2:
return ("C1", chance_card, chest_card)
elif chance_card == 3:
return ("E3", chance_card, chest_card)
elif chance_card == 4:
return ("H2", chance_card, chest_card)
elif chance_card == 5:
return ("R1", chance_card, chest_card)
elif chance_card == 6:
return (next_specific(landing_square, "U"),
chance_card, chest_card)
elif chance_card == 7:
return next_square(back(landing_square, 3),
chance_card, chest_card)
elif chance_card in [8, 9]:
return (next_specific(landing_square, "R"),
chance_card, chest_card)
else:
return (landing_square, chance_card, chest_card)
else:
raise Exception("Case should not occur")
def <|fim_middle|>(verbose=False):
GAME_PLAY = 10 ** 6
dice_size = 4
visited = {"GO": 1}
current = "GO"
chance_card = 0
chest_card = 0
doubles = 0
for place in xrange(GAME_PLAY):
total, double = roll_die(dice_size)
if double:
doubles += 1
else:
doubles = 0
if doubles == 3:
doubles = 0
current = "JAIL"
else:
index = SQUARES.index(current)
landing_square = SQUARES[(index + total) % len(SQUARES)]
(current, chance_card,
chest_card) = next_square(landing_square, chance_card, chest_card)
# if current is not in visited, sets to 1
# (default 0 returned by get)
visited[current] = visited.get(current, 0) + 1
top_visited = sorted(visited.items(),
key=lambda pair: pair[1],
reverse=True)
top_visited = [SQUARES.index(square[0]) for square in top_visited[:3]]
return ''.join(str(index).zfill(2) for index in top_visited)
if __name__ == '__main__':
print euler_timer(84)(main)(verbose=True)
<|fim▁end|> | main |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
<|fim▁hole|> @html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking<|fim▁end|> | |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
<|fim_middle|>
<|fim▁end|> | def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
<|fim_middle|>
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
<|fim_middle|>
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | return self._enable |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
<|fim_middle|>
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self._enable = value |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
<|fim_middle|>
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | return self._text |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
<|fim_middle|>
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self._text = value |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
<|fim_middle|>
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | return self._html |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
<|fim_middle|>
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self._html = value |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
<|fim_middle|>
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | return self._substitution_tag |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
<|fim_middle|>
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self._substitution_tag = value |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
<|fim_middle|>
<|fim▁end|> | subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
<|fim_middle|>
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self.enable = enable |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
<|fim_middle|>
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self.text = text |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
<|fim_middle|>
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self.html = html |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
<|fim_middle|>
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | self.substitution_tag = substitution_tag |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
<|fim_middle|>
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | subscription_tracking["enable"] = self.enable |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
<|fim_middle|>
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | subscription_tracking["text"] = self.text |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
<|fim_middle|>
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | subscription_tracking["html"] = self.html |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
<|fim_middle|>
return subscription_tracking
<|fim▁end|> | subscription_tracking["substitution_tag"] = self.substitution_tag |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def <|fim_middle|>(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | __init__ |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def <|fim_middle|>(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | enable |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def <|fim_middle|>(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | enable |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def <|fim_middle|>(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | text |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def <|fim_middle|>(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | text |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def <|fim_middle|>(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | html |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def <|fim_middle|>(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | html |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def <|fim_middle|>(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | substitution_tag |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def <|fim_middle|>(self, value):
self._substitution_tag = value
def get(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | substitution_tag |
<|file_name|>subscription_tracking.py<|end_file_name|><|fim▁begin|>class SubscriptionTracking(object):
def __init__(self, enable=None, text=None, html=None, substitution_tag=None):
self._enable = None
self._text = None
self._html = None
self._substitution_tag = None
if enable is not None:
self.enable = enable
if text is not None:
self.text = text
if html is not None:
self.html = html
if substitution_tag is not None:
self.substitution_tag = substitution_tag
@property
def enable(self):
return self._enable
@enable.setter
def enable(self, value):
self._enable = value
@property
def text(self):
return self._text
@text.setter
def text(self, value):
self._text = value
@property
def html(self):
return self._html
@html.setter
def html(self, value):
self._html = value
@property
def substitution_tag(self):
return self._substitution_tag
@substitution_tag.setter
def substitution_tag(self, value):
self._substitution_tag = value
def <|fim_middle|>(self):
subscription_tracking = {}
if self.enable is not None:
subscription_tracking["enable"] = self.enable
if self.text is not None:
subscription_tracking["text"] = self.text
if self.html is not None:
subscription_tracking["html"] = self.html
if self.substitution_tag is not None:
subscription_tracking["substitution_tag"] = self.substitution_tag
return subscription_tracking
<|fim▁end|> | get |
<|file_name|>array_simp_2.py<|end_file_name|><|fim▁begin|>t = int(raw_input())
MOD = 10**9 + 7
def modexp(a,b):
res = 1
while b:
if b&1:
res *= a
res %= MOD
a = (a*a)%MOD
b /= 2
return res
fn = [1 for _ in xrange(100001)]
ifn = [1 for _ in xrange(100001)]
for i in range(1,100000):
fn[i] = fn[i-1] * i<|fim▁hole|>def nCr(n,k):
return fn[n] * ifn[k] * ifn[n-k]
for ti in range(t):
n = int(raw_input())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
if i%2==0:
ans += nCr(n-1,i)%MOD * a[i]%MOD
else:
ans -= nCr(n-1,i)%MOD * a[i]%MOD
ans %= MOD
print ans<|fim▁end|> | fn[i] %= MOD
ifn[i] = modexp(fn[i],MOD-2) |
<|file_name|>array_simp_2.py<|end_file_name|><|fim▁begin|>t = int(raw_input())
MOD = 10**9 + 7
def modexp(a,b):
<|fim_middle|>
fn = [1 for _ in xrange(100001)]
ifn = [1 for _ in xrange(100001)]
for i in range(1,100000):
fn[i] = fn[i-1] * i
fn[i] %= MOD
ifn[i] = modexp(fn[i],MOD-2)
def nCr(n,k):
return fn[n] * ifn[k] * ifn[n-k]
for ti in range(t):
n = int(raw_input())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
if i%2==0:
ans += nCr(n-1,i)%MOD * a[i]%MOD
else:
ans -= nCr(n-1,i)%MOD * a[i]%MOD
ans %= MOD
print ans<|fim▁end|> | res = 1
while b:
if b&1:
res *= a
res %= MOD
a = (a*a)%MOD
b /= 2
return res |
<|file_name|>array_simp_2.py<|end_file_name|><|fim▁begin|>t = int(raw_input())
MOD = 10**9 + 7
def modexp(a,b):
res = 1
while b:
if b&1:
res *= a
res %= MOD
a = (a*a)%MOD
b /= 2
return res
fn = [1 for _ in xrange(100001)]
ifn = [1 for _ in xrange(100001)]
for i in range(1,100000):
fn[i] = fn[i-1] * i
fn[i] %= MOD
ifn[i] = modexp(fn[i],MOD-2)
def nCr(n,k):
<|fim_middle|>
for ti in range(t):
n = int(raw_input())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
if i%2==0:
ans += nCr(n-1,i)%MOD * a[i]%MOD
else:
ans -= nCr(n-1,i)%MOD * a[i]%MOD
ans %= MOD
print ans<|fim▁end|> | return fn[n] * ifn[k] * ifn[n-k] |
<|file_name|>array_simp_2.py<|end_file_name|><|fim▁begin|>t = int(raw_input())
MOD = 10**9 + 7
def modexp(a,b):
res = 1
while b:
if b&1:
<|fim_middle|>
a = (a*a)%MOD
b /= 2
return res
fn = [1 for _ in xrange(100001)]
ifn = [1 for _ in xrange(100001)]
for i in range(1,100000):
fn[i] = fn[i-1] * i
fn[i] %= MOD
ifn[i] = modexp(fn[i],MOD-2)
def nCr(n,k):
return fn[n] * ifn[k] * ifn[n-k]
for ti in range(t):
n = int(raw_input())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
if i%2==0:
ans += nCr(n-1,i)%MOD * a[i]%MOD
else:
ans -= nCr(n-1,i)%MOD * a[i]%MOD
ans %= MOD
print ans<|fim▁end|> | res *= a
res %= MOD |
<|file_name|>array_simp_2.py<|end_file_name|><|fim▁begin|>t = int(raw_input())
MOD = 10**9 + 7
def modexp(a,b):
res = 1
while b:
if b&1:
res *= a
res %= MOD
a = (a*a)%MOD
b /= 2
return res
fn = [1 for _ in xrange(100001)]
ifn = [1 for _ in xrange(100001)]
for i in range(1,100000):
fn[i] = fn[i-1] * i
fn[i] %= MOD
ifn[i] = modexp(fn[i],MOD-2)
def nCr(n,k):
return fn[n] * ifn[k] * ifn[n-k]
for ti in range(t):
n = int(raw_input())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
if i%2==0:
<|fim_middle|>
else:
ans -= nCr(n-1,i)%MOD * a[i]%MOD
ans %= MOD
print ans<|fim▁end|> | ans += nCr(n-1,i)%MOD * a[i]%MOD |
<|file_name|>array_simp_2.py<|end_file_name|><|fim▁begin|>t = int(raw_input())
MOD = 10**9 + 7
def modexp(a,b):
res = 1
while b:
if b&1:
res *= a
res %= MOD
a = (a*a)%MOD
b /= 2
return res
fn = [1 for _ in xrange(100001)]
ifn = [1 for _ in xrange(100001)]
for i in range(1,100000):
fn[i] = fn[i-1] * i
fn[i] %= MOD
ifn[i] = modexp(fn[i],MOD-2)
def nCr(n,k):
return fn[n] * ifn[k] * ifn[n-k]
for ti in range(t):
n = int(raw_input())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
if i%2==0:
ans += nCr(n-1,i)%MOD * a[i]%MOD
else:
<|fim_middle|>
ans %= MOD
print ans<|fim▁end|> | ans -= nCr(n-1,i)%MOD * a[i]%MOD |
<|file_name|>array_simp_2.py<|end_file_name|><|fim▁begin|>t = int(raw_input())
MOD = 10**9 + 7
def <|fim_middle|>(a,b):
res = 1
while b:
if b&1:
res *= a
res %= MOD
a = (a*a)%MOD
b /= 2
return res
fn = [1 for _ in xrange(100001)]
ifn = [1 for _ in xrange(100001)]
for i in range(1,100000):
fn[i] = fn[i-1] * i
fn[i] %= MOD
ifn[i] = modexp(fn[i],MOD-2)
def nCr(n,k):
return fn[n] * ifn[k] * ifn[n-k]
for ti in range(t):
n = int(raw_input())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
if i%2==0:
ans += nCr(n-1,i)%MOD * a[i]%MOD
else:
ans -= nCr(n-1,i)%MOD * a[i]%MOD
ans %= MOD
print ans<|fim▁end|> | modexp |
<|file_name|>array_simp_2.py<|end_file_name|><|fim▁begin|>t = int(raw_input())
MOD = 10**9 + 7
def modexp(a,b):
res = 1
while b:
if b&1:
res *= a
res %= MOD
a = (a*a)%MOD
b /= 2
return res
fn = [1 for _ in xrange(100001)]
ifn = [1 for _ in xrange(100001)]
for i in range(1,100000):
fn[i] = fn[i-1] * i
fn[i] %= MOD
ifn[i] = modexp(fn[i],MOD-2)
def <|fim_middle|>(n,k):
return fn[n] * ifn[k] * ifn[n-k]
for ti in range(t):
n = int(raw_input())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
if i%2==0:
ans += nCr(n-1,i)%MOD * a[i]%MOD
else:
ans -= nCr(n-1,i)%MOD * a[i]%MOD
ans %= MOD
print ans<|fim▁end|> | nCr |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()<|fim▁hole|> self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False<|fim▁end|> |
def _run(self):
self.is_running = False
self.start() |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
<|fim_middle|>
<|fim▁end|> | def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
<|fim_middle|>
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
<|fim▁end|> | self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start() |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
<|fim_middle|>
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
<|fim▁end|> | self.is_running = False
self.start()
self.function(*self.args, **self.kwargs) |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
<|fim_middle|>
def stop(self):
self._timer.cancel()
self.is_running = False
<|fim▁end|> | if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
<|fim_middle|>
<|fim▁end|> | self._timer.cancel()
self.is_running = False |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
<|fim_middle|>
def stop(self):
self._timer.cancel()
self.is_running = False
<|fim▁end|> | self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def <|fim_middle|>(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
<|fim▁end|> | __init__ |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def <|fim_middle|>(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
<|fim▁end|> | _run |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def <|fim_middle|>(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
<|fim▁end|> | start |
<|file_name|>repeated_timer.py<|end_file_name|><|fim▁begin|>from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def <|fim_middle|>(self):
self._timer.cancel()
self.is_running = False
<|fim▁end|> | stop |
<|file_name|>test.py<|end_file_name|><|fim▁begin|>" Settings for tests. "
from settings.project import *
# Databases
DATABASES = {
'default': {<|fim▁hole|> 'PASSWORD': '',
'TEST_CHARSET': 'utf8',
}}
# Caches
CACHES['default']['BACKEND'] = 'django.core.cache.backends.locmem.LocMemCache'
CACHES['default']['KEY_PREFIX'] = '_'.join((PROJECT_NAME, 'TST'))
# pymode:lint_ignore=W404<|fim▁end|> | 'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
'USER': '', |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)<|fim▁hole|>root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)<|fim▁end|> | root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7) |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
<|fim_middle|>
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | def __init__(self, x):
self.val = x
self.left = None
self.right = None |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
<|fim_middle|>
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | self.val = x
self.left = None
self.right = None |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
<|fim_middle|>
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key) |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
<|fim_middle|>
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
<|fim_middle|>
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent) |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
<|fim_middle|>
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
<|fim_middle|>
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key) |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
<|fim_middle|>
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | return None |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
<|fim_middle|>
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | self.deleteNodeHelper(self.node, self.parent) |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
<|fim_middle|>
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
<|fim_middle|>
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | if parent.left == node:
parent.left = None
else:
parent.right = None |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
<|fim_middle|>
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | parent.left = None |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
<|fim_middle|>
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | parent.right = None |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
<|fim_middle|>
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
<|fim_middle|>
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | return |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
<|fim_middle|>
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | self.node = root
return |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
<|fim_middle|>
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | self.findNodeAndParent(root.left, key) |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
<|fim_middle|>
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | self.findNodeAndParent(root.right, key) |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def <|fim_middle|>(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | __init__ |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def <|fim_middle|>(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | deleteNode |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def <|fim_middle|>(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | deleteNodeHelper |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def <|fim_middle|>(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def findNodeAndParent(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | getNodeSuccessor |
<|file_name|>DeleteNodeBST.py<|end_file_name|><|fim▁begin|>class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
class Solution:
node = parent = None
def deleteNode(self, root: TreeNode, key: int) -> TreeNode:
# search for the node and its parent
self.findNodeAndParent(root, key)
if self.node == root and not root.left and not root.right:
return None
if self.node:
self.deleteNodeHelper(self.node, self.parent)
return root
def deleteNodeHelper(self, node, parent):
# if node is a leaf
if not node.left and not node.right:
if parent:
if parent.left == node:
parent.left = None
else:
parent.right = None
return
# if node has only one child
if not node.left or not node.right:
child = node.left if not node.right else node.right
node.val = child.val
node.left = child.left
node.right = child.right
return
# node has two children
successor, succesorParent = self.getNodeSuccessor(node)
node.val = successor.val
self.deleteNodeHelper(successor, succesorParent)
def getNodeSuccessor(self, node):
succesorParent = node
successor = node.right
while successor.left:
succesorParent = successor
successor = successor.left
return successor, succesorParent
def <|fim_middle|>(self, root, key):
if not root:
return
if root.val == key:
self.node = root
return
self.parent = root
if key < root.val:
self.findNodeAndParent(root.left, key)
else:
self.findNodeAndParent(root.right, key)
root = TreeNode(10)
root.left = TreeNode(3)
root.left.left = TreeNode(2)
root.left.right = TreeNode(8)
root.left.right.left = TreeNode(7)
root.left.right.right = TreeNode(9)
root.right = TreeNode(15)
root.right.left = TreeNode(13)
root.right.right = TreeNode(17)
root.right.right.right = TreeNode(19)
ob = Solution()
root = TreeNode(50)
root = ob.deleteNode(root, 50)
print(root)
<|fim▁end|> | findNodeAndParent |
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|># __init__.py
# Copyright (C) 2006, 2007, 2008, 2009, 2010 Michael Bayer [email protected]
#
# This module is part of Mako and is released under
<|fim▁hole|>__version__ = '0.3.4'<|fim▁end|> | # the MIT License: http://www.opensource.org/licenses/mit-license.php
|
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
Authors: Tim Hessels
UNESCO-IHE 2016
Contact: [email protected]
Repository: https://github.com/wateraccounting/wa
Module: Collect/MOD17
Description:
This module downloads MOD17 GPP data from
http://e4ftl01.cr.usgs.gov/. Use the MOD17.GPP_8daily function to
download and create 8 daily GPP images in Gtiff format.<|fim▁hole|>from wa.Collect import MOD17
MOD17.GPP_8daily(Dir='C:/Temp3/', Startdate='2003-12-01', Enddate='2003-12-20',
latlim=[41, 45], lonlim=[-8, -5])
MOD17.NPP_yearly(Dir='C:/Temp3/', Startdate='2003-12-01', Enddate='2003-12-20',
latlim=[41, 45], lonlim=[-8, -5])
"""
from .GPP_8daily import main as GPP_8daily
from .NPP_yearly import main as NPP_yearly
__all__ = ['GPP_8daily', 'NPP_yearly']
__version__ = '0.1'<|fim▁end|> | The data is available between 2000-02-18 till present.
Examples: |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError<|fim▁hole|>
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value<|fim▁end|> | |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
<|fim_middle|>
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | pass |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
<|fim_middle|>
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | @abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
<|fim_middle|>
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
<|fim_middle|>
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
<|fim_middle|>
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
<|fim_middle|>
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
<|fim_middle|>
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | """
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
<|fim_middle|>
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | self.name = name
self.values = ValueBuffer(name, 128) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
<|fim_middle|>
class OutputDevice(metaclass=ABCMeta):
"""
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | raise NotImplementedError |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>import logging
from abc import ABCMeta, abstractmethod
from collections import deque
from typing import List, Union, Iterable, Sequence
log = logging.getLogger(__name__)
class NoSensorsFoundException(RuntimeError):
pass
class Controller(metaclass=ABCMeta):
@abstractmethod
def run(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError
@abstractmethod
def valid(self) -> bool:
raise NotImplementedError
class InputDevice(metaclass=ABCMeta):
"""
Abstract class for input devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
@abstractmethod
def get_value(self) -> float:
raise NotImplementedError
class OutputDevice(metaclass=ABCMeta):
<|fim_middle|>
class PassthroughController(Controller):
def __init__(self, inputs=Sequence[InputDevice], outputs=Sequence[OutputDevice], speeds=None):
self.inputs = list(inputs)
self.outputs = list(outputs)
def run(self):
for idx, input_reader in enumerate(self.inputs):
output = self.outputs[idx]
output.name = input_reader.name
output.values.name = input_reader.name
output.set_value(input_reader.get_value())
output.apply()
log.debug('ran loop')
def apply_candidates(self):
return self.outputs
def enable(self):
for output_dev in self.outputs:
output_dev.enable()
def disable(self):
for output_dev in self.outputs:
output_dev.disable()
def valid(self) -> bool:
return bool(self.inputs and self.outputs) and len(self.inputs) == len(self.outputs)
class DummyInput(InputDevice):
def __init__(self):
super().__init__('dummy')
self.temp = 0
def get_value(self):
return self.temp
def set_value(self, value):
self.temp = value
class DummyOutput(OutputDevice):
def __init__(self):
super().__init__('dummy')
self.speed = None
self.enabled = False
def apply(self):
if self.enabled:
self.speed = round(self.values.mean())
def enable(self):
self.enabled = True
def disable(self):
self.enabled = False
def mean(seq: Iterable) -> float:
if not isinstance(seq, Iterable):
raise ValueError('provided sequence MUST be iterable')
if not isinstance(seq, Sequence):
seq = list(seq)
if len(seq) == 1:
return float(seq[0])
if len(seq) == 0:
raise ValueError('sequence must have at least one value.')
return sum(seq) / len(seq)
def lerp(value: Union[float, int], input_min: Union[float, int], input_max: Union[float, int], output_min: Union[float, int], output_max: Union[float, int]) -> float:
if value <= input_min:
return float(output_min)
if value >= input_max:
return float(output_max)
return (output_min * (input_max - value) + output_max * (value - input_min)) / (input_max - input_min)
def lerp_range(seq: Iterable[Union[float, int]], input_min, input_max, output_min, output_max) -> List[float]:
return [lerp(val, input_min, input_max, output_min, output_max) for val in seq]
class ValueBuffer:
def __init__(self, name, default_value=0.0):
self.name = name
self.buffer = deque(maxlen=32)
self._default_value = default_value
def update(self, value: float):
self.buffer.append(value)
def mean(self) -> float:
try:
return mean(self.buffer)
except (ValueError, ZeroDivisionError):
return self._default_value
<|fim▁end|> | """
Abstract class for output devices.
"""
def __init__(self, name):
self.name = name
self.values = ValueBuffer(name, 128)
def set_value(self, value: Union[int, float]):
self.values.update(value)
@abstractmethod
def apply(self):
raise NotImplementedError
@abstractmethod
def enable(self):
raise NotImplementedError
@abstractmethod
def disable(self):
raise NotImplementedError |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.