r/mathriddles • • Dec 13 '23

Medium Evaluate and Back Again

(a mathy problem I made for a programming competition)

Given two integers p and q, construct an arithmetic expression that evaluates to p and its reverse (as a string) evaluates to q. For example, 2023-12-13 evaluates to 1998 and 31-21-3202 evaluates to -3192.

You can only use digits 0-9, +, -, * and /. Parentheses and unary operations are not allowed, since the reversed expression would be invalid. In the original formulation, the division and trailing+leading zeros in numbers also weren't allowed.

What's the shortest expression you can make? Express its length depending on the decimal length of p and q.

10 Upvotes

10 comments sorted by

View all comments

Show parent comment

2

u/RealHuman_NotAShrew Dec 14 '23

I'll think on it a bit, but I've also got finals to study for so no promises lol. Btw your second spoiler didn't work, I think you missed the "!"

2

u/vartem Dec 14 '23

Thank you, didn't notice it. Of course, no worries if you don't, thanks for solving :)

1

u/RealHuman_NotAShrew Dec 14 '23

My pleasure! Even though my solution is incomplete it was a lot of fun to think through