Skip to content

Instantly share code, notes, and snippets.

@austa
Created March 27, 2014 15:57
Show Gist options
  • Save austa/9810859 to your computer and use it in GitHub Desktop.
Save austa/9810859 to your computer and use it in GitHub Desktop.
# Mukemmel cirpi odevi betigi.
# Oncelikle betigin calismasi icin,
# Betikle ayni dizinde "algoritmalar_2014_ogrenci_listesi.csv"
# Dosyasi bulunmalidir.
# Kodun calismasi icin ogrenci listesi dosyasini acarken cikan pencerede
# Ayirici seceneklerden "sabit genislik secilmelidir.
# Karakter kumeside UTF-8 olarak ayarlanmalidir(default)
# findStudentNumber("ALAATTIN USTA") gibi parametre verilmedir.
# Cakisma durumu ortadan kaldirilmistir, ve ogrenci numaralari
# Sorunsuz bicimde ekrana gelmektedir.
# Alaattin USTA([email protected])
import csv
import time
import hashlib
def hashing():
csv_file = "algoritmalar_2014_ogrenci_listesi.csv"
reverse_alphabet = "ZYXWVUTSRQPONMLKJIHGFEDCBA"
hash_list = ["null"]*147
adjusted_data = ""
index = 0
open_file = open(csv_file)
studentsNumber = 1
lastIndex = len(hash_list) - 1
for row in csv.reader(open_file):
subDict = dict()
changer = 0
hashingResultValue = 0
for col in row:
for character in col:
hashingResultValue +=abs(hash(character)) % (10**8) + \
(ord(character) * 119) + reverse_alphabet.find(character) * (146**3)
changer += 1
hashingResultIndex = hashingResultValue % 147
subDict = {col: studentsNumber}
if hash_list[hashingResultIndex] == "null" :
hash_list[hashingResultIndex] = subDict
studentsNumber += 1
elif hash_list[hashingResultIndex] != "null":
while hash_list[lastIndex] != "null":
lastIndex -= 1
hash_list[lastIndex] = subDict
studentsNumber +=1
return hash_list
def findStudentNumber(name):
myHashList = hashing()
splitName = name.split(" ")
myTrimName = ""
if len(splitName) == 2:
myTrimName = ';'.join(splitName)
elif len(splitName) == 3:
for index in range(len(splitName)):
if index == 2:
myTrimName = myTrimName + ";" + splitName[2]
break
elif index == 0:
myTrimName = myTrimName + splitName[index] + " "
else:
myTrimName += splitName[1]
for myDict in myHashList:
if myDict.keys()[0] == myTrimName:
print name + " isimli ogrencinin numarasi:"
return myDict[myTrimName]
print findStudentNumber("ALAATTIN USTA")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment