Skip to main content
Tweeted twitter.com/StackCodeReview/status/1388780318593851399
deleted 26 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

For example, if the input is 3, then only five layouts (YYY, YYX, YXY, XYY, XYX) of the eight possible combinations (YYY, YYX, YXX, YXY, XYY, XYX, XXY, XXX) are valid. For both sides of the street, it's 5*5=25.

Please critique this solution for King Kohima's problem?.

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

For example, if the input is 3, then only five layouts (YYY, YYX, YXY, XYY, XYX) of the eight possible combinations (YYY, YYX, YXX, YXY, XYY, XYX, XXY, XXX) are valid. For both sides of the street, it's 5*5=25.

Please critique this solution for King Kohima's problem?

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

For example, if the input is 3, then only five layouts (YYY, YYX, YXY, XYY, XYX) of the eight possible combinations (YYY, YYX, YXX, YXY, XYY, XYX, XXY, XXX) are valid. For both sides of the street, it's 5*5=25.

Please critique this solution.

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane
Post Reopened by Pimgd, SuperBiasedMan, 200_success
deleted 12 characters in body; edited tags; edited title; edited tags
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

Solution to king kohimaKing Kohima problem in pythonPython

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

SoFor example, if the input is 3, the total combination possible is 8 likethen only five layouts (YYY,YYX YYX,YXX YXY,YXY XYY,XYY XYX) of the eight possible combinations (YYY,XYX YYX,XXY YXX,XXX)
But valid are only-YYY YXY,YYX XYY,YXY XYX,XYY XXY,XYX

And XXX) are valid. For both sides of the street so its, it's 5*5=25.

I have tried this code in Python can one tell me isPlease critique this is a good solution for King Kohima's problem?

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane

Solution to king kohima problem in python

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

So if input is 3, the total combination possible is 8 like(YYY,YYX,YXX,YXY,XYY,XYX,XXY,XXX)
But valid are only-YYY,YYX,YXY,XYY,XYX

And both sides of the street so its 5*5=25

I have tried this code in Python can one tell me is this is a good solution for King Kohima's problem?

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane

Solution to King Kohima problem in Python

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

For example, if the input is 3, then only five layouts (YYY, YYX, YXY, XYY, XYX) of the eight possible combinations (YYY, YYX, YXX, YXY, XYY, XYX, XXY, XXX) are valid. For both sides of the street, it's 5*5=25.

Please critique this solution for King Kohima's problem?

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane
edited body
Source Link
SuperBiasedMan
  • 13.1k
  • 5
  • 36
  • 62

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

So if input is 3, the total combination possible is 8 like(YYY,YYX,YXX,YXY,XYY,XYX,XXY,XXX)
But valid are only-YYY,YYX,YXY,XYY,XYX

And both sides of the street so its 5*5=25

I have tried this code in Python can one tell me is this the rightis a good solution for King Kohima's problem?

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

So if input is 3, the total combination possible is 8 like(YYY,YYX,YXX,YXY,XYY,XYX,XXY,XXX)
But valid are only-YYY,YYX,YXY,XYY,XYX

And both sides of the street so its 5*5=25

I have tried this code in Python can one tell me is this the right solution for King Kohima's problem?

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane

King Kohima problem:

King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to decide on which plots along the street are new building allowed to be built. In order to this, you first want to calculate the number of possible ways of assigning free plots to buildings while keeping in mind this restriction – No two consecutive plots can have buildings on them. This is done to ensure a sense of free space in the arena. The street is divided in M sections. Each section corresponds to 2 plots, one on each side of the street. Find the number of possible assignments.

Input

In the first line you’re given M ( M ≤ 1000 ). Output In the first and only line output the result/ Example Input: 3 Output: 25 Example explanation: If we just look at the one street side and mark X as a plot where building is allowed and Y as a free plot, we have: XYX, YXY, YYX, XYY, YYY. Since the same number exists on the other side, we have 5*5 = 25 combinations.

So if input is 3, the total combination possible is 8 like(YYY,YYX,YXX,YXY,XYY,XYX,XXY,XXX)
But valid are only-YYY,YYX,YXY,XYY,XYX

And both sides of the street so its 5*5=25

I have tried this code in Python can one tell me is this is a good solution for King Kohima's problem?

def binary(i):
    r=str(0)
    while(i):
        x=str(i%2)
        if(x=='1' and r[-1]=='1'): #two consecutive X are not possible 
            return None
        else:
            r=r+str(x)
        i=i/2
    return r    
m=3 #input
l=[]
for i in range(0,2**m):
    l.append(binary(i)) #converted the number to binary
print(l)
c=0 #count possible plot available
for i in l:
    if i:
        c=c+1
print(c*c) #both side of the lane
added 50 characters in body
Source Link
Ravinder Baid
  • 207
  • 1
  • 2
  • 7
Loading
added 38 characters in body
Source Link
Ravinder Baid
  • 207
  • 1
  • 2
  • 7
Loading
Post Closed as "Not suitable for this site" by SuperBiasedMan, Pimgd, ferada, Quill, janos
added 11 characters in body; edited tags
Source Link
Mast
  • 13.5k
  • 12
  • 54
  • 119
Loading
added 1220 characters in body
Source Link
Ravinder Baid
  • 207
  • 1
  • 2
  • 7
Loading
Source Link
Ravinder Baid
  • 207
  • 1
  • 2
  • 7
Loading