This file contains 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
# To run the file: python3 file_name method_flag (either 1:brute force or 2:frequency analysis) | |
import sys | |
cipher=open("cipher.txt","r") | |
lines=[] | |
for line in cipher: | |
lines.append(line) | |
if(int(sys.argv[1])==1): | |
#Try shifting and printing | |
while(True): |
This file contains 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
def checkSubst(integVal): | |
integVal2=integVal | |
flag=1 | |
while(integVal>1): | |
if(integVal%4!=0): | |
flag=0 | |
break | |
integVal/=4 | |
if(flag): return True | |
while(integVal2>1): |
This file contains 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
def getVal(rom): | |
if (rom=="I"): | |
return 1 | |
elif (rom=="V"): | |
return 5 | |
elif (rom=="X"): | |
return 10 | |
elif (rom=="L"): | |
return 50 | |
elif (rom=="C"): |
This file contains 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
a=input().split() | |
k=int(input()) | |
for i in range(len(a)): | |
a[i]=int(a[i]) | |
#a=[-5,-30,20,17,14,-7,-4,-9,11,20,23,42,-38,39,32,-8,-22,-50,-37] | |
ans=[] | |
a.sort() | |
tmin=[10000,-1,-1,-1] | |
for t in range(len(a)): | |
i=0 |
This file contains 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
def mergeArray(a,b): | |
m=len(b) | |
n = len(a)-m | |
for i in range(n//2): | |
a[i], a[n-1-i] = a[n-1-i], a[i] | |
k=len(a)-1 | |
i=n-1 | |
j=0 | |
while(i>=0 and j<m): | |
if(a[i]<b[j]): |
This file contains 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
def solution(l,k): | |
t_sum=0 | |
max_subArrInd=0 | |
for i in range(k): | |
t_sum+=l[i] | |
max_sum=t_sum | |
for i in range(1,len(l)-k+1): | |
t_sum=t_sum-l[i-1]+l[i+k-1] | |
if(t_sum>max_sum): | |
max_sum=t_sum |