Skip to content

Instantly share code, notes, and snippets.

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
"""
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
# -*- 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
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
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 + \
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.
class Prefixer():
def __init__(self):
self.__data = {}
def __repr__(self):
return 'Prefixer(%s)' % (self.__data,)
def __eq__(self, other):
return self.__data == other.__data
# -*- 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
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
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