Encryption Hackerrank Solution
This is the solution for the Encryption problem in the implementation section of the Algorithm domain. In this An English text needs to be encrypted using the following encryption scheme.
First, the spaces are removed from the text. Let L be the length of this text.
Then, characters are written into a grid, whose rows and columns have the following constraints:
The Code:
Found Bugs ?
Feel Free To Report us ! ;)
First, the spaces are removed from the text. Let L be the length of this text.
Then, characters are written into a grid, whose rows and columns have the following constraints:
- ⌊L−−√⌋≤rows≤column≤⌈L−−√⌉, where ⌊x⌋ is floor function and ⌈x⌉ is ceil function
Screenshots[Demo]
The Code:
import math
def perform(x,row,col):
row=int(row)
col=int(col)
mat=[['' for i in range(0,col)]for j in range(0,row)]
str=''
k=0
for i in range(0,row):
for j in range(0,col):
#print mat
if(k<len(x)):
mat[i][j]=x[k]
k+=1
k=0
for i in range(0,col):
for j in range(0,row):
str=str+mat[j][k]
k+=1
str=str+' '
print str
def calc(x):
row=math.floor(math.sqrt(len(x)));
col=math.ceil(math.sqrt(len(x)));
while(1==1):
if((row*col)>=len(x)):
break
elif(row<col):
row=row+1;
else:
col=col+1
perform(x,row,col)
x=map(str,raw_input());
calc(x)
Feel Free To Report us ! ;)

Comments
Post a Comment