This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
import random | |
from common import print_tour, read_input | |
def distance(city1, city2): | |
return math.sqrt((city1[0] - city2[0]) ** 2 + (city1[1] - city2[1]) ** 2) | |
def construct_dist_matrix(cities): | |
N = len(cities) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
import random | |
from common import print_tour, read_input | |
def distance(city1, city2): | |
return math.sqrt((city1[0] - city2[0]) ** 2 + (city1[1] - city2[1]) ** 2) | |
def construct_dist_matrix(cities): | |
N = len(cities) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from collections import deque | |
class Wikipedia: | |
# Initialize the graph of pages. | |
def __init__(self, pages_file, links_file): | |
# A mapping from a page ID (integer) to the page title. | |
# For example, self.titles[1234] returns the title of the page whose |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def readNumber(line, index): | |
number = 0 | |
while index < len(line) and line[index].isdigit(): | |
number = number * 10 + int(line[index]) | |
index += 1 | |
decimal = 0 | |
if index < len(line) and line[index] == ".": | |
index += 1 | |
decimal_digit = 1/10 | |
while index < len(line) and line[index].isdigit(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, sys, time | |
########################################################################### | |
# # | |
# Implement a hash table from scratch! (⑅•ᴗ•⑅) # | |
# # | |
# Please do not use Python's dictionary or Python's collections library. # | |
# The goal is to implement the data structure yourself. # | |
# # | |
########################################################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bisect | |
def createDictionary(filename="words.txt"): | |
with open(filename, 'r') as f: | |
return set(word.strip().lower() for word in f if word.strip().isalpha()) | |
def solution(random_word, dictionary): | |
sorted_random_word = sorted(random_word) | |
new_dictionary = [(sorted(word), word) for word in dictionary] | |
new_dictionary.sort() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dictionary(filename="words.txt"): | |