Follow

Here should be a simple one. It was fun to do in Java and with chained calls it turns out to be somewhat of a one-liner. This is not a code-golf thing, but feel free to try it that way if that is your interest.

"Square Odd"
Let's process an integer. The idea is that if the number contains odd digits they need to be converted to their squared value. Even digits are passed through unchanged.

For example, given the number 232, you would output 292. Or in the case of 99, you would output 8181. But if it were 22 then the output would be 22.

If this is too simple and you would like a bit more of a challenge see if you can try a couple bonus situations.

1*. determine if a number is already in this state. For example 232 wouldn't be because 3 is not squared. However, 212 could be, as could 2814 since that could have come from 294.

and
2*. given a number possibly in this state already, decode it back to the original number.

Since 1 squared is 1 and some squares have even digits like 81 such a number could have started out as '9' or actually '81'. So in 1 and 2 you may want to come up with multiple initial beginnings. So given such '81' the answer would be both of those '81' and '9'.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.