mental challenge « Next Oldest | Next Newest »

 ▼ Don Shepherd Posting Freak Posts: 1,392 Threads: 142 Joined: Jun 2007 12-11-2008, 02:57 PM 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! ▼ Vladan Dugaric Junior Member Posts: 34 Threads: 0 Joined: Jul 2008 12-11-2008, 03:04 PM 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. ▼ Pal G. Senior Member Posts: 260 Threads: 21 Joined: Nov 2006 12-11-2008, 03:57 PM Nice, it only took you 111 minutes. hpmpdc Junior Member Posts: 1 Threads: 0 Joined: Jan 1970 12-11-2008, 03:38 PM 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. ▼ Don Shepherd Posting Freak Posts: 1,392 Threads: 142 Joined: Jun 2007 12-11-2008, 08:38 PM 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. ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 12-11-2008, 09:14 PM Might the answer happen to be (in base 3 to confuse matters): 1001200012 Way less than ten minutes too :-) - Pauli ▼ Don Shepherd Posting Freak Posts: 1,392 Threads: 142 Joined: Jun 2007 12-11-2008, 09:22 PM 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? ▼ Paul Dale Posting Freak Posts: 3,229 Threads: 42 Joined: Jul 2006 12-14-2008, 03:41 PM Oops, must learn to engage brain before responding.... :-( - Pauli Egan Ford Posting Freak Posts: 1,619 Threads: 147 Joined: May 2006 12-11-2008, 09:41 PM 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. ▼ Don Shepherd Posting Freak Posts: 1,392 Threads: 142 Joined: Jun 2007 12-11-2008, 09:52 PM 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. V-PN Posting Freak Posts: 785 Threads: 13 Joined: Jan 2005 12-12-2008, 03:22 AM Have you tried setting the clock to 203MHz? ▼ Egan Ford Posting Freak Posts: 1,619 Threads: 147 Joined: May 2006 12-12-2008, 02:31 PM 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. ▼ V-PN Posting Freak Posts: 785 Threads: 13 Joined: Jan 2005 12-13-2008, 01:14 PM What? Is that really available? HPGCC works directly on a (mini)notebook using (32-bit) XP? ▼ Egan Ford Posting Freak Posts: 1,619 Threads: 147 Joined: May 2006 12-14-2008, 11:58 AM 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. ▼ V-PN Posting Freak Posts: 785 Threads: 13 Joined: Jan 2005 12-14-2008, 03:15 PM 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 Thomas Klemm Senior Member Posts: 735 Threads: 34 Joined: May 2007 12-12-2008, 09:33 AM 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 ``` Chuck Senior Member Posts: 320 Threads: 59 Joined: Dec 2006 12-11-2008, 11:46 PM 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 ▼ Don Shepherd Posting Freak Posts: 1,392 Threads: 142 Joined: Jun 2007 12-12-2008, 07:07 AM 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. ▼ Chuck Senior Member Posts: 320 Threads: 59 Joined: Dec 2006 12-12-2008, 10:48 AM 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. ▼ Don Shepherd Posting Freak Posts: 1,392 Threads: 142 Joined: Jun 2007 12-12-2008, 02:49 PM 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. George Bailey (Bedford Falls) Senior Member Posts: 335 Threads: 12 Joined: Dec 2007 12-12-2008, 01:06 AM 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.

 Possibly Related Threads... Thread Author Replies Views Last Post Mental juggling: Calculating the day of week Thomas Klemm 8 702 07-09-2009, 11:14 AM Last Post: Thomas Klemm RE: 35s sorting routine challenge - Gene's Challenge Miguel Toro 4 543 08-01-2007, 08:36 AM Last Post: Miguel Toro

Forum Jump: