SpinalHDL
1 / 1
Description
Even Digits
Design a hardware module for the Even Digits problem.
Given a non-negative integer n, find the minimum amount you must add or subtract so that the resulting number contains only even decimal digits.
Digits 0, 2, 4, 6, and 8 are even. Digits 1, 3, 5, 7, and 9 are odd.
Your task is to output the minimum distance from n to any number whose decimal representation uses only even digits.
Hardware I/O Encoding
nis a scalar unsigned 32-bit integer input- the output is a single unsigned 32-bit integer
- the output value is the minimum absolute difference between
nand any all-even-digit number
Examples
Example 1
- input
n = 42 - output:
0
The decimal digits of 42 are already all even.
Example 2
- input
n = 11 - output:
3
The closest all-even-digit numbers are 8 and 20, with distances 3 and 9. The minimum is 3.
Example 3
- input
n = 2018 - output:
2
The closest all-even-digit number is 2020.
Input
n
32-bit Unsigned IntegerInput number.
Output
32-bit Unsigned Integer
Minimum distance to a number whose decimal digits are all even.