Skip to content

Instantly share code, notes, and snippets.

@austa
Created March 18, 2014 19:38
Show Gist options
  • Save austa/9627765 to your computer and use it in GitHub Desktop.
Save austa/9627765 to your computer and use it in GitHub Desktop.
"""
Ayni dizinde bulunan algoritmalar_2014_ogrenci_listesi.csv
dosyasini en alt satirda ki;
differentValues(hashing(dosya_adi.csv)) seklinde arguman olarak verin
Cakismayan sayisi = 106, cakisan sayisi = 41 seklincde cikacaktir.
Alaattin USTA([email protected])
"""
import csv
import time
import hashlib
def hashing(csv_file):
start_time = time.time()
reverse_alphabet = "ZYXWVUTSRQPONMLKJIHGFEDCBA"
hash_table = dict()
adjusted_data = ""
index = 0
open_file = open(csv_file)
for row in csv.reader(open_file):
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
hash_table[index] = hashingResultValue % 147
index += 1
elapsed_time = time.time()- start_time
print "Gecen sure:", elapsed_time
return hash_table
def differentValues(hash_table):
hashLenght = len(hash_table)
for i in range(hashLenght):
for j in range(hashLenght):
if not (i == j):
if (hash_table[i] == hash_table[j]):
hash_table[j] = "overlap"
differentValues = 0
overlapValues = 0
for i in range(hashLenght):
if(hash_table[i] == "overlap"):
overlapValues += 1
else:
differentValues += 1
print "Cakismayanlar sayisi:", differentValues
print "Cakisan sayisi:", overlapValues
differentValues(hashing("algoritmalar_2014_ogrenci_listesi.csv"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment