heres the solution in python for both part1 and 2 :
data=""withopen("input9.txt","r")asinfile:data=infile.read().strip()numbers=list(map(int,data.split("\n")))numbers=sorted(numbers)diff3=0diff1=0numbers.append(numbers[-1]+3)numbers=[0]+numbersmemory=[1]defno_of_paths(n):s=0forxinrange(n-1,-1,-1):if(numbers[n]-numbers[x]<=3):s+=memory[x]else:breakreturnsforxinrange(1,len(numbers)):memory.append(no_of_paths(x))diff=numbers[x]-numbers[x-1]if(diff==1):diff1+=1elif(diff==3):diff3+=1print("1. ans = ",diff3*diff1)print("2. ans =",memory[-1])
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
heres the solution in python for both part1 and 2 :