What Does This Function Do?

1. Please, give your answers in comments – what does the function written below do:

a)      recognizes prime numbers

b)      recognizes prime numbers in interval [100;999]

c)      neither a) nor b) is correct

d)      other variant (please, specify)

2. And the second question is – is this function a correct solution if the task is as follows: `Please, write a function that recognizes all the prime numbers consisting of exactly 3 digits`:

a) yes

b) no

The function (in C++):

bool f(int x) {

 for (int y=2;y<x;y++)

  if (x%y==0) return false;

 return true;


P.S. I wish all of you wrote your thoughts in order to make a student of mine understand the essence of the thing!


Random Number Generator – As Easy As 01, 10, 11..

Someone told me it is not a trivial task to make a good function generating a random number. What a fool I was to believe him! It turns out you can write down the function very easily. For example, in C++:

int getRandomNumber() {

   return 3; // proven to be random – obtained by throwing a dice


Not too complicated function, eh?

Published in: on Thursday, January 10, 2008 at 6:50 pm  Comments (2)  
Tags: , , , , , , , , ,

Blog Stats Is an Interpolation of What?

When looking at the diagram of `Dashboard à Blog Stats` in my WordPress, I can’t stop wondering about this curve – it must be an interpolation of some function. How could this function look like? What would be other arguments of this function except for the date (what are factors that affect the value of this function)? Can anybody define it precisely? Or not so precisely?

Published in: on Thursday, January 10, 2008 at 2:43 pm  Comments (7)  
Tags: , , , , , , , , , ,

Very Interesting Problem

I just heard of a very interesting problem from my colleague. I would like to think about it some time, but since I have absolutely no time now, I propose it for you, my dear reader.

Let’s assume we have an integer n and an alphabet consisting of five symbols – `1`, `+`, `*`, `(`, and `)`. What is the biggest integer we can write down using no more than n symbols from our alphabet?

For example, if n=3, the biggest integer will be 2 (that is, 1+1); if n=15, my guess – it will be 9 ((1+1+1)*(1+1+1)), etc.

What is seen at once – there is only a sense of looking to just odd integers n because all the legal expressions can be only of an odd length.

So, what can we think about the answer – is it possible to make a function f(n) giving the right integer value depending only on n? Or maybe it is just possible to make a function with some other arguments as well? Maybe it isn’t possible at all to make such a function, but just to make an algorithm constructing such an integer? What do you think about it anyway?

Published in: on Thursday, November 1, 2007 at 5:15 pm  Comments (6)  
Tags: , , , , ,