Saturday, January 28, 2017

mathematics - An Hourglass Puzzle


This puzzle follows from the well known sand timer puzzles: A Sand Timer Challenge http://www.crazyforcode.com/sand-timer-puzzle/
http://www.cut-the-knot.org/hg_solution.shtml


Warmup:
You are given a timer of 4 minutes, and a timer of 7 minutes. The time starts when the first timer is flipped. Is there a time for which all larger integer values of time can be measured? Prove why or why not.


Easy:
Same rules as above, but now your timers are 5 minutes and 8 minutes.


Medium:
Same rules as above, but now your timers are 6 minutes and 11 minutes.


Hard:

Same rules as above, but now your timers are $m$ minutes and $n$ minutes, where $m>n>0$ and $m,n \in\mathbb{Z}$. (Basically find a generalization. If you want to solve this first be my guest...)


EDIT:


If you couldn't understand what I was asking.
Let $T$ be the set of all times that can be timed using timers $m$ and $n$.
Find $s\in T:s-1\notin T,\forall x>s:x\in\mathbb{Z},x\in T$.



Answer



Taking a huge risk, but hey...


W/U:



Times in the form of $4n + 7m$ can be measured. As long as a number is large enough, you can add 2*4-7 = 1 if the 7-minute hourglass is to be used at least once to measure the previous time, or 3*7 - 5*4 = 1 if the 4-minute hourglass is to be used at least four times (for at least 20 mins!). At our most conservative guess, it's 27, but since values greater than 19 will either have an $m$ that's at least 1 or $n$ that's at least 5, 20 will do as as a slightly less-conservative one. Also, 7+(7-4) = 10 and 4*2 + 4*2 (mod 7) = 9 minutes can be measured. 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7 are reachable while 6 isn't, so $T$=6.




E:



If it's $5n + 8m$, it can be measured. As long as a number is large enough, you can add 5*5 - 3*8 = 1 if the 8-minute hourglass is to be used at least thrice to measure the previous time, or 2*8 - 3*5 = 1 if the 5-minute hourglass is to be used at least thrice. At our most conservative guess, the first $5n + 8m$ number whose $n$ and $m$ equal 3 (39) will do. However, 8+(8-5) = 11, mins can also be measured. 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18 are reachable while 17 isn't. 5*2 + 5*2 (mod 8) = 12 mins can also be measured, so that makes 17 also reachable. 16, 15 are measurable, and so is 14 (see the image in the comments section), 13, 12, 11 and 10. 9 isn't, so $T$=9.



M:



For $6n + 11m$, it can be measured. As long as a number is large enough, you can add 6*2 - 11*1 = 1 if the 11-minute hourglass is to be used at least once to measure the previous time, or 11*5 - 6*9 = 1 if the 6-minute hourglass is to be used at least nine times. At our most conservative guess, it's 54+11 = 65, but since values greater than 53 will either have an $m$ that's at least 1 or $n$ that's at least 9, 54 will do as a slightly less-conservative one. However, 11+(11-6) = 16 mins can also be measured. Then again, if we start out flipping any hourglass as soon as it empties, only 1 minute's worth of sand will remain in the upper half of the 6-min hourglass after 11 mins, while the other empties. To measure any time longer than that, we can also flip the bigger one, then flip both when the smaller one empties, then do it again when the bigger one does, and so on. 11 can be measured while 10 can't, so $T$=10.



H (incomplete):




As long as $n$ and $m$ are co-primes, $k$ and $j$ values to satisfy $nk$ ≡ 1 (mod $m$) and $mj$ ≡ 1 (mod $n$) can be found. In addition, $mx$ + $mx$ (mod $n$) and $ny$ + $ny$ (mod $m$) values can be used to measure time. Also, if there's some amount of sand left in only one of the hourglasses in the middle of a measurement, the time this sand corresponds to can be continuously added by flipping the other at the time, then flipping both whenever one empties, ... (rinse and repeat), making $mx$ + $rmx$ (mod $n$) if the latter without r is less than $m$ and $ny$ + $sny$ (mod $m$) if the latter without s is less than $n$ also measurable. That means the smaller one of the aforementioned $nk$ and $mj$ ($(n,m)max*[(n,m)min-1]$ at most) is enough for the conservative limit.







VERY LATE EDIT:


Just wrote a Java program to find the generalized solution:


package hourglass;

import java.util.ArrayList;

import java.util.List;

public class Unreachables {

public static void main(String[] args) {
// x = n, y = m
int x = 7;
int y = 9;

int MaxUnreachable = 0;


int ConsLim1 = 0;
int ConsLim2 = 0;

int ub1 = 1;
int ub2 = 1;
int SecGen = 0;

List FirstGenList = new ArrayList();
List SecGenList = new ArrayList();

List ReachablesList = new ArrayList();

SecGenList.add(0);

for (int i=0; i if ((i*x)%y == 1) {
ConsLim1 = i*x;
}
if ((i*y)%x == 1 && i ConsLim2 = i*y;

}
}

int LesserConsLim = Math.min(ConsLim1, ConsLim2);

int MaxXFac = LesserConsLim/x;
int MaxYFac = LesserConsLim/y;

///////////////////////////////////////////////////////////
for (int j=0; j<=MaxXFac; j++) {

for (int k=0; k<=MaxYFac; k++) {
if (j*x + k*y < LesserConsLim) {
FirstGenList.add(j*x + k*y);
}
}
}

///////////////////////////////////////////////////////////
for (int l=0; l int base = l*x;

int r = (l*x)%y;

if (r for (int m=0; m SecGen = base + r*m;
if (SecGen 0) {
SecGenList.add(SecGen);
ub1++;
}
}

}
}

ub2 = 1;
for (int n=0; n int base = n*y;
int t = (n*y)%x;

if (t for (int o=0; o
SecGen = base + t*o;
if (SecGen 0) {
SecGenList.add(SecGen);
ub2++;
}
}
}
}

for (int p=0; p
for (int r=0; r int PotRes = FirstGenList.get(p)+SecGenList.get(r);
if (PotRes ReachablesList.add(PotRes);
}
}
}

for (int z=LesserConsLim-1; z>0; z--){
if (ReachablesList.indexOf(z)<0){

MaxUnreachable = z;
break;
}
}


System.out.println(MaxUnreachable); // our solution

}
}

No comments:

Post a Comment

classical mechanics - Moment of a force about a given axis (Torque) - Scalar or vectorial?

I am studying Statics and saw that: The moment of a force about a given axis (or Torque) is defined by the equation: $M_X = (\vec r \times \...