Hello everyone... In this topic we'll be asking each other questions to test our skills.
Here are the rules:

1 - I ask the first question.
2 - The person who answers this question correctly will post another question and so on.
3 - Time will end every night at midnight.
4 - If no one answered correctly, the person who asked the question will select a person from those who answered to ask another question the next day.

- To make posts and Replies prettier, please use the "Quote" tag.
- Enumerate your questions and answers (example: Q1 - A1, Q1 - A2, Q2 - A5, ...)
- You may use hints and external links to help solve your question.

Okay, let's get started now...
Question 1:
What is the simple difference between the Bugatti Veyron and Jad Berro's Car?
Hints - The Veyron has a Top Speed of 401 Km/h, 1001 HP, and an 8.0 litre W16 engine with sixteen cylinders in two banks of eight, equivalent to two narrow-angle V8 engines mated in a "W" configuration.
Question 1:
What is the simple difference between the Bugatti Veyron and Jad Berro's Car?
Hints - The Veyron has a Top Speed of 401 Km/h, 1001 HP, and an 8.0 litre W16 engine with sixteen cylinders in two banks of eight, equivalent to two narrow-angle V8 engines mated in a "W" configuration.
Answer 1:

Jad Berros car its quite slower, and its engine is not like the veyrons
babum wrote
Question 1:
What is the simple difference between the Bugatti Veyron and Jad Berro's Car?
Hints - The Veyron has a Top Speed of 401 Km/h, 1001 HP, and an 8.0 litre W16 engine with sixteen cylinders in two banks of eight, equivalent to two narrow-angle V8 engines mated in a "W" configuration.
Answer 1: Jad Berros car its quite slower, and its engine is not like the veyrons
No... Think Smarter, as a geek.
crazy wroteThe color :D
No... It has nothing to do with the color, the shape, the power...
It's the Speed...
A1

the Bugatti obviously lacks the geek :P , on a more serious manner , a Bugatti drives you , while you drive the sirion , its a matter of soul over body :P
------- Time is Up... --------

Here's the solution:
The Bugatti's top speed is 401 KM/h while Jad's car reached 140 KM/h. so, what makes the daihatsu a Bugatti ?

It's a Shift Register... (Shifting the top speed once to the right)

Jad's Turn.
Q2

lets learn some digital logic .

simple one

i have 3 rooms with 3 doors . one light bulb .

design a circuit that would light the bulb only if the three doors are closed . you can use switches or the minimal number of logic gates .

you can draw it and post it here , use normal logic , ill be giving the shortest answer later .
Or you can just connect the doors to close the circuit when they are themselves closed and avoid using transistor ICs altogether.
arithma, i said digital logic :) and ayman's solution is correct :)

lets make this a bit tough .

I have 3 water tanks each with a sensor that goes high if the tank is empty .
design a circuit that would light an led on the left if any one of the tanks goes empty , the left and the middle LEDs if any two tanks are empty and the 3 LEDs if all tanks are empty . use the minimal number of logic gates possible or any decoder or multiplexer you might think of . you can research decoders and multiplexers.
happy solving !
you can use switches or the minimal number of logic gates .
Fuck no, you ain't barring my simple door solution!

I put 6 switches. Three of them close in the existence of water, and the others in it's absence.
Call them A, B, C, D, E, F respectively.
Connect A, D, F in series, B, D, F in series, and C, E, F in series. Combine them all in parallel and complete the circuit with the one-filled-indicator LED.
You can another similar D, E, F switches and connect them in series and connect it to the All three are empty.
The two tank case requires something similar to the one LED thing, only using the reverse instead.

As for a digital circuit: Call the inputs: A, B, C. On if the tanks are empty.
LED1 = OR(A, B, C)
LED2 = [A AND OR(B, C)] OR AND(B, C)
LED3 = AND(A, B, C)
arithma , gr8 logic ! :) but i will have to take a deeper look on what you wrote later :P .

anyhow the best way to make this is using a 3 to 8 decoder with its output ORed .
Jad... It's Ayman's Turn Now. Go ahead Ayman.

Another simpler solution for Q2...

Question 4:

Here is a little programming challenge, imagine you are working for the car registration authority. The new trend in license plates these days is that car numbers now are formed of 3 digits followed by 3 upper case letters for example: 007CAR. The assignment of License plates numbers is based ona first come first serve basis.

For example: The first customer will be assigned 000AAA, the second 000AAB and so on. Obviously, 000ABA comes after 000AAZ and 001AAA comes after 000ZZZ.

You are assigned to write a program, that gets the customers sequence (positive integer) number N and then prints out the respective plate number. When the sequence number exceeds the number of possible plates it should print: "Impossible".

For example: For N = 1 : 000AAA (First customer)
For N = 65 : 000ACM
For N = 1000000 : Impossible

For now it is not that hard, but to make it challenging, you have to solve it in the most efficient way possible i.e. pure arithmetics with reliance on modding(%), division(/), addition, subtraction, and multiplication. No loops, if statements, recursive functions or any conditions.

All you can use is arithmetic operators to make out formulas that will lead to the correct output. To be able to work with incrementing the letters you need to rely on their ASCII value, so type casting from int to char and char to int is allowed. Only one if statement is allowed to be used, this is the condition in which you have to print "Impossible".

I hope you find this question fun, and I hope we can get to a solution. In case no one solves it after some time, I will post the solution. Have a good day :)
Nice one ayman:
Solution written in pseudocode..
x: int input
s: string output

set s to ""
repeat three times{
 append ((char) (x % 26 + int('A'))) to s
 x /= 26
}
repeat three times{
 append ((char) (x % 10 + int('0'))) to s
 x /= 10
}
if x > 0 error "Impossible"
ayman are you sure N=1mil is impossible?
it should be anything above 10*10*10*26*26*26 = 17,576,000
In any case, I'm writing here a PHP code that would do what you asked.
I'm only missing echoing 'impossible' for values larger than 17576000 without a conditional
<?php

$customer_number = 65;
showplate($customer_number);

function showplate($customer_number) {
	$number = $customer_number-1;
	$plate=array();
	$plate[1]= floor(($number/(26*26*26*10*10))%10);
	$plate[2]= floor(($number/(26*26*26*10))%10);
	$plate[3]= floor(($number/(26*26*10))%10);
	$plate[4]= toletters(floor(($number/(26*26))%26));
	$plate[5]= toletters(floor(($number/26)%26));
	$plate[6]= toletters($number%26);
	$plate_number = implode($plate,"");
	echo $plate_number;
}

// this function prints the ascii value of the letters
function toletters($num) {
	return "&#".($num+65).";";
}

?>
Try changing $customer_number.
65 returns 000ACM
17576000 returns 999ZZZ
Correct answer for both arithma and duckster although ducster you should have added one condition so that in case the number is above 17,576,000 it would print impossible just as arithma did but thats okay.

Good job guys, now it is your turn arithma or duckster :)
ayman are you sure N=1mil is impossible?
it should be anything above 10*10*10*26*26*26 = 17,576,000
Actually in the example I meant 1000,000,000 instead of 1000,000 it was a typo :)
Reverse a single connected linked list. Best optimized algo (performance first, then memory usage) wins.
airthma made use of recursive calls and conditionals, which you noted was prohibited :)
and the no-conditionals rule was behind the reason I didn't check for 'impossible' numbers
airthma made use of recursive calls and conditionals, which you noted was prohibited :)
and the no-conditionals rule was behind the reason I didn't check for 'impossible' numbers
The concept is correct though, I liked his idea :P

If you look into my post, this is what I said:
Only one if statement is allowed to be used, this is the condition in which you have to print "Impossible".
Anyways, yours is correct, thanks for participating :)
yo ayman, guess we need to show the guys the correct answer (no loops, and pure algorithming (which excludes PHP built-in functions). So here it goes:

int N = 0;
int n1=0;
int n2=0;
int n3=0;
int c1=65;
int c2=65;
int c3=65;

N = "user entry" //may vary from language to language
//assume we are using java:
N=JOptionPane.showMessageInput("Enter a user number");

N=N-1;
c3=c3+N%26;
N=N/26;
c2=c2+N%26;
N=N/26;
c1=c1+N%26;
N=N/26;
n3=n3+N%10;
N=N/10;
n2=n2+N%10;
N=N/10;
n1=n1+N%10;
N=N/10;

if(N>0)
{
System.out.println("IMPOSSIBLE");
}
else
{
System.out.println(n1+""+n2+""+n3+""+(char)c1+""+(char)c2+""+(char)c3);
}
Wrong!!

What is the value of c3 if N = 10000 ?

Look at duckster's solution, you'll see what is wrong with yours . ;)
OK, back to reversing a single linked list already?

Here's a naive implementation that you should not put in:
define node as {int data; ref node next;} // contains a data member and a reference to the next node

void reverse_list(ref node n){
  ref node current = break_last(n); // declaration
  while( (ref node last = break_last(n)) != null ){
    current.next = last;
    current = last;
  }
}

ref node break_last(ref node n){
  while(n.next != null && n.next.next != null) n = n.next;

  if(n.next == null) return n;
  
  ref node result = n.next;
  n.next = null;
  return result;
}
Reverse a single connected linked list. Best optimized algo (performance first, then memory usage) wins.
so is this correct ?
struct node{ int data ; node * next }

node* reverse (node * list) {

           node *pt , *temp ;

           pt = list.next ;
           list.next = null ;
           while (pt != null){
                  temp = pt.next ;
                  pt.next = list ;
                  list = pt ;
                  pt = temp ;
           }
           return list ;
}
@GN90, you got it right.

The algorithm should be easier to think about in those terms that helped me while deriving the same algo, but in a recursive style:
void reverse_recursive( node * & rev, node * rest ){
	if(rest == 0) return;

	node * next = rest->next;
	rest->next = rev;
	rev = rest;
	reverse_recursive(rev, next);
}
Here's some code that I used to confirm your posted code and mine.
Your turn to question our abilities!

#include <iostream>
using namespace std;

struct node {
	int data;
	node * next;
};

node* reverse (node * list) {
	node *pt , *temp ;

	pt = list->next ;
	list->next = 0 ;
	while (pt != 0){
		temp = pt->next ;
		pt->next = list ;
		list = pt ;
		pt = temp ;
	}
	return list ;
}

void reverse_recursive( node * & rev, node * rest ){
	if(rest == 0) return;

	node * next = rest->next;
	rest->next = rev;
	rev = rest;
	reverse_recursive(rev, next);
}

void spit_list(node * p){
	while(p != 0) {
		cout << p->data << endl;
		p = p->next;
	}
}

void main(){
	node a = {1, 0};
	node b = {2, 0};
	node c = {3, 0};
	node d = {4, 0};

	a.next = &b;
	b.next = &c;
	c.next = &d;

	node * p = reverse(&a);
	spit_list(p);

	node * reverse = 0;
	reverse_recursive(reverse, p);
	spit_list(reverse);
}
Here is my entry in Java, not recursive but does the job, I should have posted it earlier yesterday :P
public void reverseList() 
{
    ListNode current = head;
    head = null;
    while (current != null) 
    {
        ListNode ptr = current;
        current = current.next;
        ptr.next = head;
        head = ptr;
    }
}
Same algo as GN90 actually :)
OK, here's one I haven't had the chance to solve yet (the problem is my original)
On christmas, our office has a secret santa event. Everyone's name is put into a bowl. Each employee comes in random order, and picks a name from the bowl (there is the unfortunate possibility of one picking their own name).

Looking at the (employee name - A, name of employee on card - B), there must be at least one loop (starting with a random employee, then going to the next employee based on the card the previous one chose).

A loop configuration is a list of the size of loops in ascending order.
An employee configuration is a list of numbers, giving each employee the number of the other employee on the car he chose.

For n employees, there are n! employee configurations.

Return, given n, the number of employee configurations for each loop configuration.

Example: n=1
{Loop Configurations, Corresponding employee configurations} = {(1), 1} -- there is only one loop possible, the employee to himself. There is only one employee configuration to begin with.

Example: n=2
{Loop, Configs} = {(2), 1}
{Loop, Configs} = {(1, 1), 1}
Either a loop of two employees, each being the santa of the other, or two loops, each employee being the santa of himself.
The sum of configs sums to 2! which is 2.

Example: n=3
{(3), 2}
{(2, 1), 3}
{(1, 1, 1), 1}
There are 3! employee configs in total. Each one being the santa of himself amounts to a single config. A loop going through all the employees has two possibilities (one in each direction (1, 2, 0) or (2, 0, 1) ). The rest of configurations belong to the middle case. Those configs are detailed below:
(0, 2, 1)
(2, 1, 0)
(1, 0, 2)
I haven't come down to an implementation yet, but the problem itself needs some understanding. I am working on my writing-a-problem skills, so please let me know where it needs clarification.
@ arithma : i didn't understand what should we do in the question you've posted

And here's my question: (its not a programing question cause I don't know what to post)
A drinks machine offers three selections - Tea, Coffee or Random
(Either tea or Coffee)but the machine has been wired up wrongly
so that each button does not give what it claims. If each drink
costs 50p, how much minimum money do you have to put into the
machine to find out which button gives which selection?
@GN90: The challenge itself is to figure out what the question is about, jokingly. I admit I failed to make it clear what the question is about.

I believe your question was asked and answered somewhere on this forum before. Something about entering a single coin and hitting random. The result determines what random is wired to. If it's coffee, then coffee button is tea, and tea button is random.

I think the question is more interesting if the wiring is done really randomly (with the possibility of a correct wiring).
arithma wrote@GN90: The challenge itself is to figure out what the question is about, jokingly. I admit I failed to make it clear what the question is about.

I believe your question was asked and answered somewhere on this forum before. Something about entering a single coin and hitting random. The result determines what random is wired to. If it's coffee, then coffee button is tea, and tea button is random.

I think the question is more interesting if the wiring is done really randomly (with the possibility of a correct wiring).
yeah , maybe it was asked.
and your answer is correct , sorry for this stupid question anyways :p

and it should be your turn now.
I think the question is more interesting if the wiring is done really randomly (with the possibility of a correct wiring).
Not really, since there is no way of solving this. If the wiring is done completely randomly, then there's no possibility of actually knowing. Think about it, the random button could (theoretically) give out Tea a million times straight. So technically there is no minimum amount of tries that guarantees a solution.

What would be impressive though is to modelize what I just wrote in a mathematical equation (or set of equations) that cannot be solved, thus proving that there is no way of finding a minimum value (Do I make sense to anyone ?)
To prove what you just said, the random button can return the same type of cup indefinitely, rendering any attempt to discover what the wiring is inept. Still, the truly random wiring is the more possible situation to face in real life.

I was thinking more about the problem being an optimization problem over the space of click sequence.
As in, what is the click sequence that will maximize your certainty (or minimize your uncertainty) about the wiring of the machine.

Machine has three Buttons: A, B, C; the types of drinks are A, B, R(random).

Think of this example sequence:

Click A. Returns A (we are calling the first drink it returns A to avoid unnecessary symmetry). 50% -> (A is wired to A) & 50% -> (A is wired to R)
Then Click B. case 1: Returns A: C is most definitely wired to B.
case 2: Returns B: All hell is loose probability wise.

I think the most suiting representation for the probabilities would be some kind of tree with assumptions and their probabilities as branches. We'd also have to represent the click sequences.
The difficulty is insane since we're modeling logic, and basing other logic on top of that.
a month later
Write a function to check if a number is Happy Number or not.
A happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers (or sad numbers[1]).
e.g. 7 is happy, as the associated sequence is:

7^2 = 49
4^2 + 9^2 = 97
9^2 + 7^2 = 130
1^2 + 3^2 + 0^2 = 10
1^2 + 0^2 = 1

For more information you can refer to http://en.wikipedia.org/wiki/Happy_number Good luck :)

P.S. This is a classic exercise but I just thought of making this thread live again. :)
#include <iostream>
using namespace std;

typedef unsigned int uint;

uint next(uint n){
	uint sum = 0;

	while(n > 0){
		uint digit = n % 10;
		sum += digit * digit;
		n /= 10;
	}

	return sum;
}

void main(){
	uint slow, fast;
	cout << "Enter number: ";
	cin >> slow;
	fast = next(slow);

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

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

	cout << "slow = " << slow << endl;
	if(slow == 1)
		cout << ":)\n";
	else
		cout << ":(\n";
}
The 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.
kteer belkon fadi !
kteer belkon fadi !
Niyelna :P
Here's a translation of arithma's implementation into F#
let f x =
    x.ToString().ToCharArray()
    |> Seq.map (fun c -> pown ((int c) - 48) 2)
    |> Seq.sum

let happy n next =
    let rec compare a b =
        match a = b with
        | true -> a
        | false -> compare (next a) (next (next b))
    compare n (next n)
Example: 4 numbers (true means happy) :
Code: [7;20;92;487] |> Seq.map (fun x -> happy x f = 1)

Output:  [true; false; false; true]

Example: Number of happy numbers between 1 and 1000

Code: [1 .. 1000] |> Seq.map (fun x -> happy x f) |> Seq.filter (fun x -> x = 1 ) |> Seq.sum

Output: 143