We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

filter and lambda together look too confusing. Generator expressions would be much better here. Also, you don't need absolute value. Mod operation should work on negative numbers. Like this:

Good solution! You're right about negative mod. Wasn't thinking about that. And I'm not super familiar with generator expressions. Your solution has inspired me to look into them more.

importFoundation// Complete the beautifulDays function below.funcbeautifulDays(i:Int,j:Int,k:Int)->Int{varcount=0forvalueini...j{varr=valuevarq=0whiler>0{q=q*10+r%10r/=10}abs(value-q)%k==0?count+=1:()}returncount}

I think your code was wrong. I think you lost variable i's value, because in while loop it changes its value to 0.

I think this has to work fine.

int count = 0;
for (; i <= j; i++) {
int num = i;
int revNum = 0;
while (num > 0) {
revNum = 10 * revNum + num % 10;
num /= 10;
}
if (Math.abs(i - revNum) % k == 0)
count++;
}
return count;

## Beautiful Days at the Movies

You are viewing a single comment's thread. Return to all comments →

using functional operations :)

or two line, unintelligible version :p

Which course/book are you following on python?

Learned Python as part of Discrete Math course and mostly self taught since :)

filter and lambda together look too confusing. Generator expressions would be much better here. Also, you don't need absolute value. Mod operation should work on negative numbers. Like this:

Good solution! You're right about negative mod. Wasn't thinking about that. And I'm not super familiar with generator expressions. Your solution has inspired me to look into them more.

This was my solution in Swift

i did the same ,but iam getting runtime error

swift is slow

swift not for server side, and fast work

I think your code was wrong. I think you lost variable i's value, because in while loop it changes its value to 0.

I think this has to work fine.

Nearly identical to my rust solution except I had the loop to reverse the number as a separate function.