Last active
March 30, 2018 02:44
-
-
Save khrlimam/49af22b0c3c11fcca7d1f4d3c84fdb95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
antRoutes = [ | |
[1,2,9,10,25,26], | |
[4,3,8,11,24,27], | |
[5,6,7,12,23,28], | |
[16,15,14,13,22,29], | |
[17,18,19,20,21,30], | |
[36,35,34,33,32,31] | |
]; | |
detik = input('Semut di detik berapa? ') | |
if detik >= 1+(antRoutes[0].__len__() * antRoutes.__len__()): | |
print 'The cute ant telah sampai Malaysia!' | |
else: | |
if detik == 0: | |
print "END!" | |
else: | |
enumaretedRoutes = enumerate(map(lambda x: enumerate(x, 1), antRoutes), 1) | |
c = [[b, [d for d in b[1]] ] for b in [a for a in enumaretedRoutes]] | |
row_data = filter(lambda x: filter(lambda y: y[1] == detik , x[1]), c) | |
row_num = row_data[0][0][0] | |
col_data = filter(lambda z: z[1] == detik, row_data[0][1]) | |
col_num = col_data[0][0] | |
print "The cute ant is in (%s, %s) now!" % (col_num, row_num) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def point(detik): | |
baris = round(math.sqrt(detik)) | |
squared_baris = baris*baris | |
if (baris % 2) == 0: | |
if squared_baris == detik: | |
kolom = 1 | |
if (squared_baris < detik): | |
baris += 1 | |
kolom = detik-squared_baris | |
if ((squared_baris - detik) > 0): | |
kolom = (squared_baris - detik) + 1 | |
else: | |
if squared_baris == detik: | |
kolom = baris | |
baris = 1 | |
if (squared_baris < detik): | |
kolom = baris+1 | |
baris = detik-squared_baris | |
if ((squared_baris - detik) > 0): | |
kolom = baris | |
baris = (squared_baris - detik) + 1 | |
return (baris, kolom) | |
if __name__ == '__main__': | |
detik = input('Masukkan detik: ') | |
if detik == 0: | |
print("END!") | |
else: | |
print("The cute ant is now in %s" % str(point(detik))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment