The Museum of HP Calculators

HP Forum Archive 18

 mental challengeMessage #1 Posted by Don Shepherd on 11 Dec 2008, 2:57 p.m. OK, this isn't really a calculator challenge, it's just a mental challenge, and admittedly it isn't much of a challenge. The forum has been dull lately. Assume you have a digital clock that shows time as HH:MM:SS. It is a 24-hour clock, so HH goes from 00 to 23. How many seconds each day is the clock showing only "binary" time, that is, only ones and zeroes? The first poster with the correct answer has the satisfaction of being first!

 Re: mental challengeMessage #2 Posted by Vladan Dugaric on 11 Dec 2008, 3:04 p.m.,in response to message #1 by Don Shepherd 64 seconds. The reasoning goes like this: "binary" values for any 2-digit group (hour, minute, second) would be 00, 01, 10, 11, and they are all valid values for hours (00-23), minutes (00-59), and seconds (00-59). Therefore, each of these digit groups can have 4 different "binary" values, so we have 4 ENTER^ 3 Y^X possible values, each lasting one second. Edited: 11 Dec 2008, 3:43 p.m.

 Re: mental challengeMessage #3 Posted by Pal G. on 11 Dec 2008, 3:57 p.m.,in response to message #2 by Vladan Dugaric Nice, it only took you 111 minutes.

 Re: mental challengeMessage #4 Posted by hpmpdc on 11 Dec 2008, 3:38 p.m.,in response to message #1 by Don Shepherd 6 positions each with a possible value of 0 or 1... = 2^6 = 64. 'Would have answered sooner, but I had to create an account.

 Re: mental challengeMessage #5 Posted by Don Shepherd on 11 Dec 2008, 8:38 p.m.,in response to message #4 by hpmpdc OK all, very good. Now, for something a little harder. Same 24 hour clock. Of the 86,400 6-digit times displayed in a day (from 000000 to 235959), how many are prime numbers? Excel VBA took around 10 minutes to determine it.

 Re: mental challengeMessage #6 Posted by Paul Dale on 11 Dec 2008, 9:14 p.m.,in response to message #5 by Don Shepherd Might the answer happen to be (in base 3 to confuse matters): 1001200012 Way less than ten minutes too :-) - Pauli

 Re: mental challengeMessage #7 Posted by Don Shepherd on 11 Dec 2008, 9:22 p.m.,in response to message #6 by Paul Dale Hmmm, that's not what I got (after converting your base 3 number to base 10). I could be wrong, of course. You did not include impossible time numbers like 220673 did you?

 Re: mental challengeMessage #8 Posted by Paul Dale on 14 Dec 2008, 3:41 p.m.,in response to message #7 by Don Shepherd Oops, must learn to engage brain before responding.... :-( - Pauli

 Re: mental challengeMessage #9 Posted by Egan Ford on 11 Dec 2008, 9:41 p.m.,in response to message #5 by Don Shepherd I get 7669 in 74 seconds with HPGCC2 on my 50g: ```#include #include ``` ```int main() { mp_int a; mp_err ret; int c = 1, i, j, k; ``` ``` sys_slowOff(); mp_init(&a); for (i = 0; i < 24; i++) for (j = 0; j < 60; j++) for (k = 0; k < 60; k++) { if (k % 2 == 0 || k % 5 == 0) continue; mp_set_int(&a, i * 10000 + j * 100 + k); mp_prime_is_prime(&a, 1, &ret); if (ret) c++; } sat_push_zint_llong(c); return (0); } ``` I get the same with Sage on my notebook in about 1 second: ```c=0 for i in range(24): for j in range(60): for k in range(60): if is_prime(i*10000 + j*100 + k): c=c+1 print c ``` FYI, if you want a Mathematica-like environment for your Windows/OSX/Linux box checkout sagemath.org.

 Re: mental challengeMessage #10 Posted by Don Shepherd on 11 Dec 2008, 9:52 p.m.,in response to message #9 by Egan Ford Yeah, I got 7669 also, using VBA in Excel. It took about 3 minutes after I realized I didn't need to check the even seconds! That Sage code looks interesting, I'll have to check that out. Thanks, and thanks to Pauli too.

 Re: mental challengeMessage #11 Posted by V-PN on 12 Dec 2008, 3:22 a.m.,in response to message #9 by Egan Ford Have you tried setting the clock to 203MHz?

 Re: mental challengeMessage #12 Posted by Egan Ford on 12 Dec 2008, 2:31 p.m.,in response to message #11 by V-PN No, just 75MHz. BTW, I just ran it on an ARM-based 50g emulator in 24 seconds (i.e. not EMU48 (Saturn-based), not HPAPINE (Simulator) :-). That's about 231 MHz (on a 2.4 GHz notebook). Edited: 12 Dec 2008, 2:50 p.m.

 Re: mental challengeMessage #13 Posted by V-PN on 13 Dec 2008, 1:14 p.m.,in response to message #12 by Egan Ford What? Is that really available? HPGCC works directly on a (mini)notebook using (32-bit) XP?

 Re: mental challengeMessage #14 Posted by Egan Ford on 14 Dec 2008, 11:58 a.m.,in response to message #13 by V-PN Sadly OS/X and Linux only. I think I can get it working with Cygwin or you can try yourself: ```svn co https://x49gp.svn.sourceforge.net/svnroot/x49gp x49gp ``` I'll have a quick start guide checked in this weekend sometime. Worse case use Ubuntu 32-bit with VMware. I just tested it and it works just fine.

 Re: mental challengeMessage #15 Posted by V-PN on 14 Dec 2008, 3:15 p.m.,in response to message #14 by Egan Ford when I get my Xmas computer on-line, I give it a try - although installing software may take weeks I need 32&64:XP,Vista,Win7,Ubuntu,etc then add to that some software... wait - it will take months, since I have also other things to do

 Re: mental challengeMessage #16 Posted by Thomas Klemm on 12 Dec 2008, 9:33 a.m.,in response to message #9 by Egan Ford You can do that in pure python as well: ```max = 240000 is_prime = [True for i in range(max)] is_prime[0] = is_prime[1] = False for p in range(2, max): if is_prime[p]: for i in range(p, max/p): is_prime[i*p] = False c = 0 for i in range(24): for j in range(60): for k in range(60): if is_prime[i*10000 + j*100 + k]: c = c + 1 print c ```

 Re: mental challengeMessage #17 Posted by Chuck on 11 Dec 2008, 11:46 p.m.,in response to message #5 by Don Shepherd 0.171 seconds with Mathematica. However, this is still checking the evens, so it should be almost half that for an efficient line of code. ```Count[Flatten[PrimeQ[Table[10000h+100m+s,{h,0,23},{m,0,59},{s,0,59}]]],True] ``` =7669 Is this cheeting? Edited: 12 Dec 2008, 10:45 a.m. after one or more responses were posted

 Re: mental challengeMessage #18 Posted by Don Shepherd on 12 Dec 2008, 7:07 a.m.,in response to message #17 by Chuck Chuck, I pasted your code in Mathematica and it said you are missing a right bracket. I thought about trying this problem in Mathematica, but I use it so seldom that I can never remember the syntax rules and commands. I also tried to do it on the TI NSpire (because I knew it had an IsPrime function), but that was an exercise in frustration. The program development editor on the NSpire is horrible.

 Re: mental challengeMessage #19 Posted by Chuck on 12 Dec 2008, 10:48 a.m.,in response to message #18 by Don Shepherd Oops. you're right Don, thanks (I fixed the missing bracket.) I have several students that have purchased the NSpire, and I agree, it has to be one of the most frustrating machines ever.

 Re: mental challengeMessage #20 Posted by Don Shepherd on 12 Dec 2008, 2:49 p.m.,in response to message #19 by Chuck Chuck, I just downloaded a new NSpire CAS operating system, and this version contains a program editor the fixes many of the problems inherent in the old system. Interestingly, under the I/O menu there is still only Disp (for display). Still no provision for user input. Link to learning module for the NSpire.

 Re: mental challengeMessage #21 Posted by George Bailey (Bedford Falls) on 12 Dec 2008, 1:06 a.m.,in response to message #1 by Don Shepherd Quote: It is a 24-hour clock, so HH goes from 00 to 23. The odd thing about it is, that the clock on my micro wave shows 24:00:00 to 23:59:59... ;-) Going on with 24:00:01 - there is no 00 hour. Edited: 12 Dec 2008, 6:51 a.m.

Go back to the main exhibit hall