From 3217473354f61400c13ef61b5748a396265a6fff Mon Sep 17 00:00:00 2001 From: Kukuh Aji Sulistyo Date: Thu, 23 Feb 2017 22:45:43 +0700 Subject: [PATCH 1/7] add bigrandom answer --- bigrandom/answer.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bigrandom/answer.py b/bigrandom/answer.py index cb5fee4..23add76 100644 --- a/bigrandom/answer.py +++ b/bigrandom/answer.py @@ -1,16 +1,24 @@ class BigRandom: def __init__(self): - self.data = "data.txt" + self.data = open("data.txt", "r") # add attributes if you need more def answer(self): + mydata = open("data.txt", "rw+") noh = 0 # variable to store number of hashtag - # ommiting line number's hashtag suc = 0 # variable to store sum of character's code in ascii, - # ommiting line number and its hashtag + nomor = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000 + for line in self.data.readlines(): + noh = noh + len([x for x in line if x == '#']) # count seluruh '#' + suc = suc + sum([ord(x) for x in line]) # sum dari ascii seluruh karakter - # your algorithm + # @return + # noh = count suluruh '#' - 10000, karena '#' disetiap penomoran baris tidak dihitung - return (noh,suc) + # ord('#') * 10000 = sum ascii dari '#' untuk setiap penomoran baris + # sum([ord(x) for x in nomor]) = sum ascii dari seluruh nomor 1234567891011121314...999910000 + return (noh - 10000, suc - (ord('#') * 10000 + sum([ord(x) for x in nomor]))) - # add methods if you need more \ No newline at end of file +big = BigRandom() +a, b = big.answer() +print(a, b) \ No newline at end of file From c7dc0f79797032df962437e13d9f6c8f9e93939b Mon Sep 17 00:00:00 2001 From: Kukuh Aji Sulistyo Date: Thu, 23 Feb 2017 22:51:38 +0700 Subject: [PATCH 2/7] minor change on bigrandom answer --- bigrandom/answer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bigrandom/answer.py b/bigrandom/answer.py index 23add76..6e09c99 100644 --- a/bigrandom/answer.py +++ b/bigrandom/answer.py @@ -4,9 +4,7 @@ def __init__(self): # add attributes if you need more def answer(self): - mydata = open("data.txt", "rw+") - noh = 0 # variable to store number of hashtag - suc = 0 # variable to store sum of character's code in ascii, + noh, suc = 0 nomor = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000 for line in self.data.readlines(): noh = noh + len([x for x in line if x == '#']) # count seluruh '#' From bac4f7435c24ba517b22b080143e4caee80e07e8 Mon Sep 17 00:00:00 2001 From: Kukuh Aji Sulistyo Date: Thu, 23 Feb 2017 22:52:43 +0700 Subject: [PATCH 3/7] minor change --- bigrandom/answer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigrandom/answer.py b/bigrandom/answer.py index 6e09c99..be156b4 100644 --- a/bigrandom/answer.py +++ b/bigrandom/answer.py @@ -4,7 +4,7 @@ def __init__(self): # add attributes if you need more def answer(self): - noh, suc = 0 + noh, suc = 0, 0 nomor = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000 for line in self.data.readlines(): noh = noh + len([x for x in line if x == '#']) # count seluruh '#' From 2fdcd01add9e8bb6c8fbdaeefaf33c7cedaf20d2 Mon Sep 17 00:00:00 2001 From: Kukuh Aji Sulistyo Date: Sun, 26 Feb 2017 21:07:16 +0700 Subject: [PATCH 4/7] updating bigrandom/answer.py --- bigrandom/answer.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/bigrandom/answer.py b/bigrandom/answer.py index be156b4..7169cb8 100644 --- a/bigrandom/answer.py +++ b/bigrandom/answer.py @@ -5,16 +5,10 @@ def __init__(self): def answer(self): noh, suc = 0, 0 - nomor = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000 for line in self.data.readlines(): noh = noh + len([x for x in line if x == '#']) # count seluruh '#' suc = suc + sum([ord(x) for x in line]) # sum dari ascii seluruh karakter - - # @return - # noh = count suluruh '#' - 10000, karena '#' disetiap penomoran baris tidak dihitung - - # ord('#') * 10000 = sum ascii dari '#' untuk setiap penomoran baris - # sum([ord(x) for x in nomor]) = sum ascii dari seluruh nomor 1234567891011121314...999910000 + nomor = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000 return (noh - 10000, suc - (ord('#') * 10000 + sum([ord(x) for x in nomor]))) big = BigRandom() From e18835144a42e395c3b144d0d23b4e3f6ca22344 Mon Sep 17 00:00:00 2001 From: Kukuh Aji Sulistyo Date: Sun, 26 Feb 2017 22:21:23 +0700 Subject: [PATCH 5/7] add casear/answer.py + minor change in bigrandom/answer.py --- bigrandom/answer.py | 20 ++++++++++++++------ caesar/answer.py | 15 +++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/bigrandom/answer.py b/bigrandom/answer.py index 7169cb8..e07cfa2 100644 --- a/bigrandom/answer.py +++ b/bigrandom/answer.py @@ -1,16 +1,24 @@ class BigRandom: def __init__(self): - self.data = open("data.txt", "r") - # add attributes if you need more + self.data = "data.txt" def answer(self): + self.data = open("data.txt", "r") noh, suc = 0, 0 for line in self.data.readlines(): - noh = noh + len([x for x in line if x == '#']) # count seluruh '#' - suc = suc + sum([ord(x) for x in line]) # sum dari ascii seluruh karakter - nomor = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000 - return (noh - 10000, suc - (ord('#') * 10000 + sum([ord(x) for x in nomor]))) + noh = noh + len([x for x in line if x == '#']) #______ count of '#' + suc = suc + sum([ord(x) for x in line]) #_____________ sum of asciis of all chars + + + numbs = ''.join([str(x) for x in range(10000)]) # 1234567891011121314...999910000 + + self.data.close() # close data stream + + # ord('#') * 10000 _________________ sum of asciis of first '#' in each row + # sum([ord(x) for x in nomor]) _____ sum of asciis of numbs + return (noh - 10000, suc - (ord('#') * 10000 + sum([ord(x) for x in numbs]))) +# instantiation big = BigRandom() a, b = big.answer() print(a, b) \ No newline at end of file diff --git a/caesar/answer.py b/caesar/answer.py index 0d85db4..98b0442 100644 --- a/caesar/answer.py +++ b/caesar/answer.py @@ -4,10 +4,13 @@ def __init__(self): # add attributes if you need more def answer(self): - key = 0 # variable to store the key + self.ciphertext = open("ciphertext.txt", "r+") + key = int(raw_input(":> ")) # _____________________________________________________ get key from user + msg = ''.join([chr(ord(x) - key) for x in str(self.ciphertext.readlines())]) # ____ decripting @return decripted string + print("Hasil decrypt dengan key %d adalah \n %s" % (key, msg)) # _________________________ printing out + self.ciphertext.close() # _________________________________________________________ close data stream + return (msg) - # your algorithm - - return (key) - - # add methods if you need more \ No newline at end of file +# instantiation +csr = Caesar() +print(csr.answer()); \ No newline at end of file From a24131887d7509571a70b3dd20f2e1ca93c98393 Mon Sep 17 00:00:00 2001 From: Kukuh Aji Sulistyo Date: Sun, 26 Feb 2017 22:24:54 +0700 Subject: [PATCH 6/7] minor change --- caesar/answer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caesar/answer.py b/caesar/answer.py index 98b0442..4e03e9c 100644 --- a/caesar/answer.py +++ b/caesar/answer.py @@ -7,7 +7,7 @@ def answer(self): self.ciphertext = open("ciphertext.txt", "r+") key = int(raw_input(":> ")) # _____________________________________________________ get key from user msg = ''.join([chr(ord(x) - key) for x in str(self.ciphertext.readlines())]) # ____ decripting @return decripted string - print("Hasil decrypt dengan key %d adalah \n %s" % (key, msg)) # _________________________ printing out + print("Hasil decrypt dengan key %d adalah \n %s" % (key, msg)) # __________________ printing out self.ciphertext.close() # _________________________________________________________ close data stream return (msg) From 3aa81483073fe61471d123afa26ae6566c33144a Mon Sep 17 00:00:00 2001 From: Kukuh Aji Sulistyo Date: Tue, 28 Feb 2017 17:24:28 +0700 Subject: [PATCH 7/7] minor change --- bigrandom/answer.py | 8 ++++++++ caesar/answer.py | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bigrandom/answer.py b/bigrandom/answer.py index e07cfa2..af887c6 100644 --- a/bigrandom/answer.py +++ b/bigrandom/answer.py @@ -3,6 +3,14 @@ def __init__(self): self.data = "data.txt" def answer(self): + + noh = 0 # variable to store number of hashtag + # ommiting line number's hashtag + suc = 0 # variable to store sum of character's code in ascii, + # ommiting line number and its hashtag + + # your algorithm + self.data = open("data.txt", "r") noh, suc = 0, 0 for line in self.data.readlines(): diff --git a/caesar/answer.py b/caesar/answer.py index 4e03e9c..5b239af 100644 --- a/caesar/answer.py +++ b/caesar/answer.py @@ -4,12 +4,14 @@ def __init__(self): # add attributes if you need more def answer(self): + key = 0 + + # your algorithm self.ciphertext = open("ciphertext.txt", "r+") - key = int(raw_input(":> ")) # _____________________________________________________ get key from user msg = ''.join([chr(ord(x) - key) for x in str(self.ciphertext.readlines())]) # ____ decripting @return decripted string print("Hasil decrypt dengan key %d adalah \n %s" % (key, msg)) # __________________ printing out self.ciphertext.close() # _________________________________________________________ close data stream - return (msg) + return (key) # instantiation csr = Caesar()