arithma wroteThe idea is simple. If you have a loop, two operations per step versus one operation per step will collide with each other.
This eliminates the need to store or memorize what happened before to compare against.
could this be used in C# too? or the only way is to save the sums in a list?

btw here's my C# version:
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            uint n, s = 0;
            bool b=false;
            Console.Write("Enter a positif number to find out it's mood:");
            n = uint.Parse(Console.ReadLine());
            List<uint> li=new List<uint>();
            while(n!=1 && b==false)
            {
                li.Add(n);
                while (n != 0)
                {
                    s += (n % 10) * (n % 10);
                    n /= 10;
                    if (li.Contains(n)) { b = true; }
                }
                n = s;
                s = 0;
            }
            if (b == true) Console.WriteLine("sad");
            else Console.WriteLine("happy");
            Console.ReadLine();      
        }
    }
}
Yeah you can certainly do that in C# as well, I'll post up a translation here before I sleep.

Ok, here we go, C# version.
        static uint next(uint n)
        {
            uint sum = 0;
            while (n > 0)
            {
                uint digit = n % 10;
                sum += digit * digit;
                n /= 10;
            }

            return sum;
        }

        static void Main(string[] args)
        {
            Console.Write("Enter number: ");
            uint n = uint.Parse(Console.ReadLine());
            uint slow = next(n);
            uint fast = next(next(n));

            while (slow != fast)
            {
                slow = next(slow);
                fast = next(next(fast));
                Console.WriteLine(slow + "-" + fast);
            }

            if (slow == 1)
                Console.WriteLine(":)");
            else
                Console.WriteLine(":(");
        }
I have a question concerning Arithma's code, before i read your code, i thought of a solution similar to Joudi's.
I read your code and I understood it, but my question is why did you chose 2 operations versus 1 ? was it a random thing or not ?
because while trying changing the number of operations (3 vs 1 loops eternally, 4 vs 1 not , 5 vs 1 was looping , ...) when I've reached 8 operations vs 1, the number "fast" behaved like fast = fucntion(fast) , it didn't change through all the loop.
......
while(slow != fast){
        slow = next(slow);
        fast = next(next(next(next(next(next(next(next(fast))))))));
.......
this how i modified it and like i said fast became as if it was a constant, tried it for about more than 100 numbers (ma 2afda bele :P) and i always got results like that :
Enter a number: 6
36-89
45-89
41-89
17-89
50-89
25-89
29-89
85-89
89-89
slow = 89
:(
and many other similar results.
i don't think this is some coincidence, is it some arithmetic property ?
having that i removed the operation on "fast" numbers in the loop and replaced it in the first operation on "fast" (the one used to initialize fast) and i got this code at the end :
void main(){
    uint slow, fast;
    cout << "Enter number: ";
    cin >> slow;
    fast = next(next(next(next(next(next(next(next(next(slow)))))))));
    cout<<fast ;
    if(fast == 1)
        cout << "\n:)";
    else
        cout << "'n:("; 
}
and next() is the same as arithma defined it before.

it seems to be a right code but i don't know why :P
@GN90: You have my two thumbs up. Perfect questions.

In the case of next(next(n)), the distance will decrease always by 1 on each loop (distance to collide). However, as I'll show you in the code sample, next(next(next(n))) may always skip next(n).

This almost drove me crazy, but I got a test case that shows the danger of using next(next(next(n)))
#include <iostream>
using namespace std;

typedef unsigned int uint;

uint next(uint n){
    n++;

    return n % 4;
}

void main(){
    uint slow, fast;
    slow = 0;
    fast = next(slow);

    while(slow != fast){
        slow = next(slow);
        fast = next(next(next(fast)));

        cout << slow << "-" << fast << endl;
    }

    cout << "slow = " << slow << endl;
    if(slow == 1)
        cout << ":)\n";
    else
        cout << ":(\n";
}
The rationale behind this: next(n) versus next(next(n)) inside a cycle is the same as n versus next(n). However, the last form is used since we don't know we're already in the cycle yet. We don't know the size of the cycle either. So if we just fix slow and only advance fast, slow may stay out of the loop, and no collision may ever happen.

The following is a next function such that you may not necessarily start within the loop. (You may start at 1000, it will eventually loop inside the 0 to 3 sequence).
uint next(uint n){
	if(n > 4)
		return n / 2;

    n++;
    return n % 4;
}
Oh, btw, you owe me 2 hours :P
Pasted up the C# code translation.