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
class Nearby(object): | |
""" | |
Nearby solver | |
@type _tn: int | |
@param _tn: the number of topics created | |
@type _topics: dict | |
@param _topics: the dictionary of topics created | |
""" |
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
class Square(object): | |
""" | |
Square is data structure that represents a part of the plane. | |
A square is divided to 4 parts. | |
@type _origine_x: float | |
@param _origine_x: the x coordinate of the origine of this square | |
@type _origine_y: float | |
@param _origine_y: the y coordinate of the origine of this square |
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
# -*- coding: utf-8 -*- | |
''' | |
Created on Jan 09, 2013 | |
@author: Mourad Mourafiq | |
About: This is an attempt to solve the Quora challenge Nearby. | |
''' | |
import math | |
import heapq |
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
class NearbySquare(Nearby): | |
""" | |
Nearby solver using the square data structure | |
@type _tn: int | |
@param _tn: the number of topics created | |
@type _topics: dict | |
@param _topics: the dictionary of topics created | |
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
COMMANDS = "(ADD)|(DEL)|(W?QUERY)" | |
ANY_STRING = "(\\S*.*)" | |
SEPARATORS = "(?: |\\t)" | |
IDS = "\\w+" | |
TYPES = "user|topic|question|board" | |
FLOATS = "[0-9]+(?:.[0-9]*)?" | |
INTS = "[0-9]+" | |
BOOSTS = "((?:" + TYPES + "|(?:" + IDS + ")):" + FLOATS + SEPARATORS + ")*" | |
ANY_COMMAND = "(?P<command>" + COMMANDS + ")" + SEPARATORS + "(?P<parameters>" + ANY_STRING + ")" | |
ADD_COMMAND = "(?P<type>" + TYPES + ")" + SEPARATORS + \ |
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
class Item(object): | |
""" | |
either a topic, a user, a board or a question | |
@type type: str | |
@param type: The item's type. | |
@type id: str | |
@param id: The item's id. | |
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
class Prefixer(): | |
def __init__(self): | |
self.__data = {} | |
def __repr__(self): | |
return 'Prefixer(%s)' % (self.__data,) | |
def __eq__(self, other): | |
return self.__data == other.__data |
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
# -*- coding: utf-8 -*- | |
''' | |
Created on Jan 04, 2013 | |
@author: Mourad Mourafiq | |
About: This is an attempt to solve the Quora challenge Typehead. | |
''' | |
import re | |
import copy |
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
class Item(object): | |
""" | |
Describe an item | |
@type id: string | |
@param id: the id of the elemet | |
@type value: string | |
@param value: the value of the item | |
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
class Node(object): | |
""" | |
A node object in a decision tree | |
@type column: int | |
@param column: the column index of the criteria to be tested | |
@type value: string | |
@param value: the value that the column must match to get a true result |