mental challenge



#22

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!


#23

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.


#24

Nice, it only took you 111 minutes.

#25

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.


#26

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.


#27

Might the answer happen to be (in base 3 to confuse matters):

1001200012

Way less than ten minutes too :-)


- Pauli


#28

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?


#29

Oops, must learn to engage brain before responding....

:-(

- Pauli

#30

I get 7669 in 74 seconds with HPGCC2 on my 50g:

#include <hpgcc49.h>
#include <tommath.h>
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.

#31

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.

#32

Have you tried setting the clock to 203MHz?


#33

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.


#34

What?
Is that really available?
HPGCC works directly on a (mini)notebook using (32-bit) XP?


#35

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.


#36

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

#37

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

#38

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


#39

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.


#40

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.


#41

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.

#42

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 309 07-09-2009, 11:14 AM
Last Post: Thomas Klemm
  RE: 35s sorting routine challenge - Gene's Challenge Miguel Toro 4 236 08-01-2007, 08:36 AM
Last Post: Miguel Toro

Forum Jump: