Click here to Skip to main content
15,915,081 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone is my first post and question.

I was doing a challenge in CodeFights | Test Your Coding Skills![^]

So was about a math pattern like:

n,
(n + 1) * 2,
((n + 1) * 2 + 1) *2,
(((n + 1) * 2 + 1) * 2 + 1) * 2
...

and the solution was like :
Java
int pattern(int i) {
    return ( 3 << -- i ) - 2;
}


it was a easy solution, not made by me.

can any one explain me this "<<";
Or how the return works.

Thank you.

What I have tried:

i tried to do by myself but i never figure out this was a solution. Its my first time i saw this.
Posted
Comments
Sergey Alexandrovich Kryukov 18-Jun-16 10:08am    
Sorry, this simply means that you fail in the competition. This is normal; just keep learning. A competition, or testing your skills only makes sense if you solve the problem 100% by yourself. Getting any help would be not only cheating, but even cheating yourself, when it comes to "testing skills".

By the way, engineering profession imply that you always do something you see first time, otherwise it would not be engineering. You are supposed to solve problems requiring creative approach and learning; this is not the same as acting as a member of trained personnel doing only what someone tells you to do.

—SA
redchain 18-Jun-16 11:39am    
Well i was expecting some explanation.

But your answer is so right.

I ll keep conding and learning. Ty

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900