You have found a machine which, when fed with two numbers s and e, produces a strange code consisting of the letters a and b. The machine seems to be using the following algorithm.
- Check if s is less than e - 1. If so, continue to step 2. If not, exit.
- Increment s by 1
- Decrement e by 1
- If this is the first letter you're producing, produce a. Otherwise produce a letter different from the one you last produced (only a and b may be produced)
- go to step 1.
check below for what i tried
def strangeCode(s, e):
output = ""
if s < e-1:
s = s+1
e = e-1
if len(output) % 2:
output = output+"b"
else:
output = output+"a"
return strangeCode(s,e)
return output
From my understanding, when i return strangecode(s,e), my output becomes an empty string again, and this is where i am stuck.
Example inputs and outputs are
input: s: 4 e: 8
output: "ab"