 [SOLVED] Security problem... | Sololearn: Learn to code for FREE!

+4

# [SOLVED] Security problem...

You are in charge of security at a casino, and there is a thief who is trying to steal the casino's money! Look over the security diagrams to make sure that you always have a guard between the thief and the money! There is one money location, one thief, and any number of guards on each floor of the casino. Task: Evaluate a given floor of the casino to determine if there is a guard between the money and the thief, if there is not, you will sound an alarm. My Solution: n = input() c = "" for i in n: if i != 'x': c = c + i a = c.index("G") b = c.index("\$") c = c.index("T") if b >= a and c >= b: print("quiet") elif a < b: print("ALARM") elif b < a and b < c: print("quiet") else: print("ALARM") #Unable to pass only one test case :(

+5

#I think, this works.. #Observe the condition for guard just.. n = input() c = "" for i in n: if i != 'x': c = c + i a=0 for i in c: if i == 'G': a = a + 1 #a = c.index("G") b = c.index("\$") c = c.index("T") if (b>a>c) or (b<a<c): #a between b and c(, guard between \$ and T print("quiet") else: print("ALARM") #may this can be simplified in many ways in python.. but to understand problem, these steps clear that I hope. **never give up in trying to solve anything.. hope it helps....

+6

ANOTHER IDEA REMOVE UNNECESSARY X AND CHECK IF THIEF IS BESIDE MONEY OR NOT a=input().replace('x','') if a.index('T') in [a.index('\$')+1,a.index('\$')-1]: print('ALARM') else: print('quiet')

+4

I think this code works try it If it does not work let me know https://code.sololearn.com/c8l9l340NC6x Keep learning & happy coding :D

+3

I mean, For input G\$T, it should output Alarm but your code , it's quiet.

+3

x = ''.join(input().split('x')) y = ''.join(x.split('T\$')) z = ''.join(y.split('\$T')) print('ALARM'if '\$' not in z else 'quiet') Noob style: passes all tests. #x removes space. #y&z remove only the thieves with money #If money is gone an alarm #else - it's all quiet

+2

\$GT is failing case there...

+2

Now only one case is failing...

+2

Now it's failing the case G\$T Note: There may be more than one guard also..

+2

That case is thr already :( case 3 is failing for me

+2

If possible cn u send the code pls I tried all the ways...

+1

Yo try this setup = input() setup = setup.replace('x', '') S=setup.find('\$') T=setup.find('T') if ((T - S) == 1) or ((T - S) ==-1): print('ALARM') else: print('quiet')

+1

cam= input().replace('x','') x=cam.find('T') y= cam.find('\$') if abs((x-y))==1: print ('ALARM') else : print('quiet')

0

i = list(input()) x = [] for r in range(len(i)): if i[r] != "x": x.append(i[r]) z = "".join(x) if "\$T" in z or "T\$" in z: print("ALARM") else: print("quiet") or: i = input().replace("x", "") if "\$T" in i or "T\$" in i: print("ALARM") else: print("quiet")

-1

a=input().replace("x","") thief=a.index("T") money=a.index("\$") range1=a[thief:money] range2= a[money:thief] if "G" in (range1 or range2): print ("quiet") else : print ("ALARM")