Find Out the Number of Grains of Sand!
Description:
Problem Description
,▄▀▀▀▀▀▀▀▄
▄P▀ ⁿ ' ▀▄ ,,,
,Æ▀ ▌]▄▀▀ ╙▀▄
,▀' ' ▄▀▌ ▌ ═,▐▀N▄,
▄▀" ² ' ▌¬ ▄╘ `▀▄
▄Æ▀└¬ ▐ ² ▀▄
▄▀ * ⌐ ╒ ┌ ," ² ┌ ▀▄
▄▀ ┐ ` ',▄▄▄▄,". / ,ⁿ, ,▄▄mm▄, ▀N▄
,█¬⌐ ═ ,"▄Æ▀' `▀▄╓⌐ ▐▄▀- MÆ;▀▄ ▌▄ ▀▄
Æ└ ═ ^ ∞ ` ▄Æ▀─∞ ▀▀▄▀ ═ ▀N,▄ ▄▀
▌╙⌐ + ' ∞ ▄Æ▀',,▄ . ⌐`▀▄ ∞ `▀▄▀
▀▄ ¬ *└⌐ ▄P▀¬ ╓ ╓`, `╓ ▀▄╛ ∞* "█
▄▀▌▀▀▀█▀N▄P▀ ` , ╒w ▀█ " +"╓ª┌ █
█▄ * ▄A▀▄▀r"⌐ "⌐ " , ▀▄═ ▄═▐,▄,▄▄▄▀└
ª-, ▄▀═ ^;" ; ▌ " ,*▄` ╙█▄▄█▄▄▄ "
└▀▀▄', ∞ ` ⌐¬ , , └ ² ═ ,▄Æ▀ ▀▄▄▄▌▄█
▀▀▄▓▄▓▄▄▄▄▄ ' "⌐ ⌐ ,▄mM▀▀▀█▀▀▀▄▄▄
▐██▌ + - ▐▀▀▀═MM∞∞∞MP▀▀ , "╒▀'`╤]▄▄▄A▀
This Kata is the second in the Do a Smart Guess collection series. If you haven't solved the first Kata, check it out: Find Out the Number of Gold Coins!.
After dealing with the guardian in the last Kata, you and your friends continue the RPG campaign, and now you encounter a mysterious wizard.
The wizard promises to give you a legendary magic item, but for that you must guess the number of grains of magic sand that are in the wizard's bag. For this, he gives the following tips:
. If the number of grains were divided between people, grains would be left.
. If the number of grains were divided between people, grains would be left.
. If the number of grains were divided between people, grains would be left.
. If the number of grains were divided between people, grains would be left.
Of course is always a positive integer and .
The wizard doesn't seem very trustworthy, so he might be trying to trick you, and there aren't any number of grains of sand that satisfy the conditions he gives.
Your Task
Given the wizard information, write the function number_of_grains
that returns the minimum number of grains of magic sand in the wizard's bag.
This function receives information in the form of a list of tuples:
[(a1, m1), (a2, m2), ... , (aN, mN)]
If the wizard is trying to trick you, and there is no number of grains of sand that satisfies the given information, your function should return None
.
Example
Suppose that the tips from the wizard are:
. If the number of grains were divided between people, grains would be left.
. If the number of grains were divided between people, grain would be left.
So, the minimum number of grains of sand is 7, because 7 is the smallest number that when divided by 4 has remainder 3 and when divided by 6 has remainder 1. Thus:
number_of_grains([(3, 4), (1, 6)]) = 7
Suppose the wizard gave one more tip:
- . If the number of grains were divided between people, no grain would be left.
In this case, the problem has no solution, because there is no number that divided by 2 has a remainder of 0 (that is, an even number) that when divided by 4 has a remainder of 3. Thus:
number_of_grains([(3, 4), (1, 6), (0, 2)]) = None
Performance Requirements
Consider that the maximum input length will be 15 (that is, the wizard will give at most 15 tips, ).
The values will be always less than , so the minimum number of grains of sand can be quite large. However, that shouldn't be a problem for your algorithm.
Have fun coding and please don't forget to vote and rank this kata! :-)
Similar Kata:
Stats:
Created | Mar 10, 2023 |
Published | Mar 10, 2023 |
Warriors Trained | 251 |
Total Skips | 119 |
Total Code Submissions | 62 |
Total Times Completed | 15 |
Python Completions | 15 |
Total Stars | 8 |
% of votes with a positive feedback rating | 100% of 7 |
Total "Very Satisfied" Votes | 7 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 4 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |