Skip to content

Instantly share code, notes, and snippets.

@vinu76jsr
Created August 26, 2012 02:21
Show Gist options
  • Save vinu76jsr/3473215 to your computer and use it in GitHub Desktop.
Save vinu76jsr/3473215 to your computer and use it in GitHub Desktop.
A model for restaurent
"""
"""
prime = [2,3,5,7,11,13,17,19,23,29,31,37,41,43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
def _hash(s):
sum = 0
for c in s:
sum+=prime[ord(c)-ord('a')]
return sum
def merge_sort(list):
if len(list)<=1:
return list
mid = len(list)/2
return merge(merge_sort(list[:mid]),merge_sort(list[mid:]))
def merge(l1, l2):
index1 = 0
index2 = 0
l = []
while index1<len(l1) and index2<len(l2):
if l1[index1][0]<l2[index2][0] and len(l1[index1][1])<len(l2[index2][1]):
l.append(l1[index1])
index1 = index1 + 1
else:
l.append(l2[index2])
index2 = index2+1
if index1<len(l1):
l = l+l1[index1:]
if index2<len(l2):
l = l+l2[index2:]
return l
def giveAnagrams(l):
ll = []
for i in l:
print i, _hash(i)
ll.append((_hash(i),i))
#ll = merge_sort(ll)
ll.sort()
prevh = 0
prevs = ""
result = []
templ = []
print ll
for h, s in ll:
if h==prevh and len(s)==len(prevs):
templ.append(s)
else:
if len(templ)>1:
result.append(templ)
templ = []
templ.append(s)
prevh = h
prevs = s
return result
if __name__=="__main__":
l = ['abroad', 'aces', 'about', 'aboard', 'case', '']
ll = giveAnagrams(l)
print "*"*25,"\n*** Printing anagrams ***\n", "*"*25
for i in ll:
print i
from django import models
class Restaurant(models.Model):
name=models.CharField(max_length=255)
location=models.CharField(max_length=255)
lat=models.DecimalField(max_digits=3, decimal_places=5)
long=models.DecimalField(max_digits=3, decimal_places=5)
address=models.CharField(max_length=400)
class Table(models.Model):
seats = models.IntegerField()
available = models.BooleanField(default=True)
restaurant = models.ForeignKey(Restaurant)
class Customer(models.Model):
name = models.CharField(max_length=255)
class Reservation(models.Model):
startTime = models.DateTimeField()
endTime = models.DateTimeField()
table= models.ForeignKey(Table)
restaurant = models.ForeignKey(restaurant)
customer = models.ForeignKey(Customer)
approved = models.ForeignKey(default=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment