def findByСoordinate(user_information): flights_near = [] airlines = getAirlines() for airline in airlines: flights = file.readLines(config.flights_dir + airline) for flight_information in flights: if isFlightNear(user_information, flight_information): flights_near.append(flight_information) return flights_near
def main(): fr24 = flightradar24.Api() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # sock.bind( ("192.168.1.111", 777) ) sock.bind(("", 777)) sock.listen(5) while 1: conn, addr = sock.accept() data = conn.recv(16384) udata = data.decode("utf-8") user_info = parse.user_tcp(udata) answer = [] if (user_info.ERROR != True): if (user_info.command == user_info.commands["FlightsByCoordinates"] ): answer = flights.findByСoordinate( str(user_info.coordinate1) + " " + str(user_info.coordinate2)) if (user_info.command == user_info.commands["FlightsByAirlines"]): for airline in user_info.airlines: flights.getGlobalFlight(fr24, airline) answer += file.readLines(config.flights_dir + airline) else: answer = ["error"] answer_string = "" for answer_one in answer: answer_string += answer_one + "\n" conn.send(bytes(answer_string, 'utf-8')) conn.close()
import math import file raw = file.readLines('inputs/day10.txt') def find_asteroids(): for y, line in enumerate(raw): for x, a in enumerate(line): if a == '#': yield (x, y) def get_angle(start, end): angle = math.atan2(end[0] - start[0], start[1] - end[1]) * 180 / math.pi if angle < 0: return 360 + angle return angle def partOne(asteroids): location = None max_count = 0 for start in asteroids: count = len({get_angle(start, end) for end in asteroids if start != end}) if count > max_count: max_count = count location = start return location, max_count def partTwo(asteroids, station_loc): asteroids.remove(station_loc) asteroid_angles = sorted(
import file orbits = file.readLines('inputs/day06.txt') # Prep planet/orbit list for num in range(len(orbits)): orbits[num] = orbits[num].split(')') orbit_list = [] for x in range(len(orbits)): for y in range(len(orbits[x])): orbit_list.append(orbits[x][y]) planets = list(set(orbit_list)) for num in range(len(planets)-1): if (planets[num] == "COM"): del(planets[num]) # Part One def getOrbits_P1(orbitList, planet, count): result = 0 for orbit in orbitList: orbitCount = count end = orbit[0] planetCheck = orbit[1]
import math import file moduleMasses = file.readLines('inputs/day01.txt') def calcFuel(mass): return math.floor(float(mass) / 3) - 2 def partOne(): totalFuel = 0 for moduleMass in moduleMasses: totalFuel += calcFuel(moduleMass) return totalFuel def partTwo(): totalFuel = 0 for moduleMass in moduleMasses: fuel = moduleMass while True: fuel = calcFuel(fuel) if fuel > 0: totalFuel += fuel else: break return totalFuel print("Part 1: %d" % partOne())