本文发表在 rolia.net 枫下论坛a)
We have known:
Time per cycle = 1 / 50MHz = 1 / 50,000,000 seconds.
The total memory space = 1 MBytes = 1024 * 1024 bytes ~ 1,000,000 bytes.
Let's suppose:
the average length of instructions is n (bytes);
the average time cycles for one instruction is m (times);
the number of instructions for a iteration operation (for(){...} or while(){...}) is i;
the machine word length is w bits.
My answer:
The approximate upper bound is
(m / 50,000,000) * i * (2^w - 1)^(1,000,000 / (i * n)) (seconds)
For simplicity, we assume: n = 1, m = 1, i = 1, w = 32, then
(m / 50,000,000) * i * (2^w - 1)^(1,000,000 / (i * n))
= (1 / 50,000,000) * (2^32 - 1)^1,000,000 (seconds)
b)
10^100 years = 365 * 24 * 60 * 60 * 10^100 (seconds)
= 365 * 24 * 3600 * 10^100 (seconds)
~ 30,000,000 * 10^100 (seconds)
= (1 / 50,000,000) * 50,000,000 * 30,000,000 * 10^100
= (1 / 50,000,000) * 1.5 * 10^115 (seconds)
< (1 / 50,000,000) * 10^(15 * 8) (seconds)
My 9 lines (less than 10 lines) program:
for (double d1 = 0.0; d1 < (1.0e15 - 1.0); d1 += 1.0)
for (double d2 = 0.0; d2 < (1.0e15 - 1.0); d2 += 1.0)
for (double d3 = 0.0; d3 < (1.0e15 - 1.0); d3 += 1.0)
for (double d4 = 0.0; d4 < (1.0e15 - 1.0); d4 += 1.0)
for (double d5 = 0.0; d5 < (1.0e15 - 1.0); d5 += 1.0)
for (double d6 = 0.0; d6 < (1.0e15 - 1.0); d6 += 1.0)
for (double d7 = 0.0; d6 < (1.0e15 - 1.0); d7 += 1.0)
for (double d8 = 0.0; d8 < (1.0e15 - 1.0); d8 += 1.0)
;
c) Some errors in your answers
void main ()
{
int *vals,*ptr;
vals = malloc(sizeof(int)*200);
memset (vals,'\0',sizeof(int)*201); // error: you only allocated sizeof(int)*200 bytes
while(!vals[200]) // error: vals[200] is out of the block of you allocated
{
// What does these mean? You program seems to will
// never terminate itself.
//
*(ptr = vals) += 1;
while (*ptr == 10)
{
*ptr++ = 0;
*ptr += 1;
}
}
free(vals);
}
**My suggestion after finishing this homework**
I kindly suggest you don't touch any "C" related job at present stage until you learn much more about "C", in order to save your valuable time and energy and the interviewers' valuable time and energy. Otherwise, even if you accidentally get a "C" related job, you will suffer from it very much.
**My feelings after finishing this homework**
I sadly see some of the reasons why Canadian IT companies suspect Chinese IT job seekers so much.
**My wonder after finishing this homework**
How could you get the interview opportunity?更多精彩文章及讨论,请光临枫下论坛 rolia.net
We have known:
Time per cycle = 1 / 50MHz = 1 / 50,000,000 seconds.
The total memory space = 1 MBytes = 1024 * 1024 bytes ~ 1,000,000 bytes.
Let's suppose:
the average length of instructions is n (bytes);
the average time cycles for one instruction is m (times);
the number of instructions for a iteration operation (for(){...} or while(){...}) is i;
the machine word length is w bits.
My answer:
The approximate upper bound is
(m / 50,000,000) * i * (2^w - 1)^(1,000,000 / (i * n)) (seconds)
For simplicity, we assume: n = 1, m = 1, i = 1, w = 32, then
(m / 50,000,000) * i * (2^w - 1)^(1,000,000 / (i * n))
= (1 / 50,000,000) * (2^32 - 1)^1,000,000 (seconds)
b)
10^100 years = 365 * 24 * 60 * 60 * 10^100 (seconds)
= 365 * 24 * 3600 * 10^100 (seconds)
~ 30,000,000 * 10^100 (seconds)
= (1 / 50,000,000) * 50,000,000 * 30,000,000 * 10^100
= (1 / 50,000,000) * 1.5 * 10^115 (seconds)
< (1 / 50,000,000) * 10^(15 * 8) (seconds)
My 9 lines (less than 10 lines) program:
for (double d1 = 0.0; d1 < (1.0e15 - 1.0); d1 += 1.0)
for (double d2 = 0.0; d2 < (1.0e15 - 1.0); d2 += 1.0)
for (double d3 = 0.0; d3 < (1.0e15 - 1.0); d3 += 1.0)
for (double d4 = 0.0; d4 < (1.0e15 - 1.0); d4 += 1.0)
for (double d5 = 0.0; d5 < (1.0e15 - 1.0); d5 += 1.0)
for (double d6 = 0.0; d6 < (1.0e15 - 1.0); d6 += 1.0)
for (double d7 = 0.0; d6 < (1.0e15 - 1.0); d7 += 1.0)
for (double d8 = 0.0; d8 < (1.0e15 - 1.0); d8 += 1.0)
;
c) Some errors in your answers
void main ()
{
int *vals,*ptr;
vals = malloc(sizeof(int)*200);
memset (vals,'\0',sizeof(int)*201); // error: you only allocated sizeof(int)*200 bytes
while(!vals[200]) // error: vals[200] is out of the block of you allocated
{
// What does these mean? You program seems to will
// never terminate itself.
//
*(ptr = vals) += 1;
while (*ptr == 10)
{
*ptr++ = 0;
*ptr += 1;
}
}
free(vals);
}
**My suggestion after finishing this homework**
I kindly suggest you don't touch any "C" related job at present stage until you learn much more about "C", in order to save your valuable time and energy and the interviewers' valuable time and energy. Otherwise, even if you accidentally get a "C" related job, you will suffer from it very much.
**My feelings after finishing this homework**
I sadly see some of the reasons why Canadian IT companies suspect Chinese IT job seekers so much.
**My wonder after finishing this homework**
How could you get the interview opportunity?更多精彩文章及讨论,请光临枫下论坛 rolia.net