Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Fixed a typo in the title
Link
unwind
  • 401.8k
  • 64
  • 492
  • 620

Maping Mapping two integers to one integer, in a unique and deterministic way

edited title
Link
Daniel Daranas
  • 22.7k
  • 10
  • 66
  • 122

Maaping Maping two integers to one integer in a unique anand deterministic way

Source Link
harm
  • 10.5k
  • 11
  • 40
  • 43

Maaping two integers to one integer in a unique an deterministic way

Imagine two positive integers A and B. I want to combine these two into a single integer C.

There can be no other integers D and E which combine to C. So combining them with the addition operator doesn't work. Eg 30 + 10 = 40 = 40 + 0 = 39 + 1 Neither does concatination work. Eg "31" + "2" = 312 = "3" + "12"

This combination operation should also be deterministic (always yield the same result with the same inputs) and should always yield an integer on either the positive or the negative side of integers.