1808
A_Lucky_Numbers
Explanation
Hateehc is a Martian blogger who wants to buy a starship with the luckiest number. The luckiness of a number is the difference between its largest and smallest digits.
For example, the luckiness of the number 142857
is 8 - 1 = 7
, and the luckiness of the number 111
is 0
because all its digits are the same.
In a store, there are starships with numbers from 𝑙
to 𝑟
. You need to help Hateehc find the starship with the luckiest number.
Logic to solve the problem:
- Iterate through the range of starship numbers
[𝑙, 𝑟]
. - For each number in the range, find the luckiness (the difference between the largest and smallest digits).
- Keep track of the maximum luckiness found so far and the corresponding starship number.
- Stop the iteration if the maximum luckiness is equal to 9, as this is the highest possible luckiness.
- Return the starship number with the highest luckiness.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
B_Playing_in_a_Casino
Explanation
The winnings for each game are calculated as the sum of the absolute differences between the corresponding numbers on the two players' cards.
- For each column in the grid, sort the values.
- Iterate through the sorted values and calculate the accumulated differences between each value and the previous one.
- Sum the accumulated differences for each column.
- Divide the total sum by 2 to get the total winnings.
Calculate the total winnings for all games played in pairs. Sort the numbers in each column of the grid and calculates the accumulated differences between consecutive sorted numbers.
The total winnings are obtained by summing up the accumulated differences and dividing the result by 2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|