OK, enough winners for this problem 😉
By far the most viewed topic in this blog!
and the most solved problem
I really have enjoyed noticing how every one tried to reduce it to 1 line .. to the extend that we don’t have a Second Place !
First Place 1 line (in order of who sent first)
- Alaa Shaker
- Mohammad Diab
- Anonymous ! .. he didn’t leave a second name so i can’t really tell which Anonymous is he 😀 .. please send a name man .. a nickname is also fine 😀
- Amr Saqr
- Mohamed Samy
- Mohamed Hesham – Filipino
- Mohamed Abdelghani
- Mohamed Abd-Elmone’m
- Tasniem Seliem
now to the solution 😀
while( *dest++ = *src++ );
we use a very unique feature .. a very dangerous feature .. its .. well i don’t know what do they call it 😀
its when an arithmetic expression can be converted implicitly to a boolean expression .. so its “implicit conversion” i think (A)
i am sure that every one of us has spent hours and hours in debugging some code that doesn’t work as it should .. only to find out at the end that he left out some “=”..
if( x = 5 )
if( x == 5 )
right ? 😛
of course for old programmers its usually not an issue .. but for new comers .. well i think they still feel the sour of it 😀
but i think now that you have seen that feature being helpful sometimes .. you will never fall in that trap again.
Since i am extremely bored, and i have been staring into lots of code recently .. i have no intention to do this in the blog .. so this weeks problem will be about the shortest code ever ..
ok .. go on .. i need the Shortest implementation of..
yeah.. strcpy().. our strcpy().. 😉
void strcpy(char *destination, const char *source);
is welcome .. but C/C++ are preferred.
any library functions or classes are absolutely not welcome..
i don’t care for the return .. keep it void
the function must take 2 arguments, one is the destination string and the other is the source string .. you can assume
that both are valid (not null) pointers nor empty strings.. so forget your QA sprit for a while
all strings are “null terminated char arrays”.. very normal “C strings”.
input string must be kept intact, you can notice const char *
read the first comment about the const char * 😀
send me CODE .. and only CODE .. you can explain it , you can comment it .. but don’t send ideas alone 😀 .. try to code it 😀 .. this is the challenge.
for the new faces .. welcome! 😀 .. you post the solution in the comments, and if it is right i will not approve it until it’s time, otherwise, i will approve it and say what went wrong.. that’s why you should read the comments before posting a solution.
after we are done ان شاء الله.. i will show you how to make use of a couple of features in C++ to solve this problem .. one of them is EXTREAMELY annoying feature..
OK .. That’s it .. let the race .. begin .. 😀
the solution can be found here
As promised, this is the second video i liked from OSCON 2008
Mark Shuttleworth is the founder of Canonical Ltd., the company behind Ubuntu Linux
In the keynote he mentions his thoughts about the open source business and so..
Images via Wikipedia
if you think last week’s problem from Alaa wasn’t that easy. 😀
and mine in the week before that was a little strange. 😀
so this week the problem will be a bit easier.. in spite of the fact that i couldn’t solve it right a way in an interview .. but i grew smart enough to solve it yesterday.. “i think its the salad 😎 ”
“some salad picture goes here .. but i couldn’t find any nice one”
How to detect a Cycle in a Linked List ??
- you are not Allowed to use any other data structures in you solution, no stacks no arrays no other lists .. nothing!
- the list is single linked .. a very normal list i mean
and you are not allowed to change this class or add a Visited Boolean or any similar trick .. u can assume that the list Nodes are like…
int val; //assuming this is an integer List
Node next; //this is a pointer for those who doesnt know C#
- you can use any constant number of temporary variables or pointers .. as long as the number is constant (i want an in place algorithm) — i suggest 4 or 5 extra pointers
- you are not required to keep the list intact .. you may play with it or destroy it as you please 😀
- i don’t strictly require the source code .. just the idea .. but i may request it later if you insist that your answer is right 😀
- THOSE WHO ARE AFRAID OF BEING WRONG .. please go away .. if you are afraid of getting it wrong yo will never try .. then you will never get it right
- note 6 does not mean throwing me some idea and i have to think about it :@ .. you have to be 80% sure of your solution and think how may it go wrong and all the cases ..
- Read the comments -if there is any- before you post your solution .. it might remind you of some thing you forgot in your solution 😉
if you would like the next problem to be about some certain topic, then please tell me in the comments .. and it would be great if you said that in the very comment where you place your solution 😀
now to the winners:
thanks every one
and still no one requested a topic for the next week’s problems! .. seems like it will be very hard one (6) !
كثيرون اندهشوا عندما قرأوا اسم أمجد صبحى فى ملف المستقبل
و لكنهم – الكثيرون- أيضا لم يتوقعوا ان يقرأوا يوما اسم أدهم صبرى فى ملف المستقبل
هذه المره لن يكون كهلا.. و هذه المره لن يكون وحده .. و هذه المره سيجتمع الفريقين
انتظروا هذه الرواية فى معرض لكتاب القادم بأذن لله
المصادر: هنا و هنا
How to write “X” so that:
int a= 0;
cout<<"a = "<<a;
//console says a = 5 Positive five!
cout<<"a = "<<a;
//console says a = -5 Negative five!
waiting for the answers in the comments (comments are moderated) .. i will show them after a couple of right answers..
if your answer is wrong “which is fine”, i will pass the comment..
if it is right .. i will reply on the comment or maybe to your mail telling you to stop trying..
now to the Winners (in order of who replied first):
i have tried to follow the O’Reilly’s Open Source Convention (OSCON) for a bit .. but since i am not very familiar with most of the names .. i lost my interest later..
until i seen a video by GreggPollack titled Oscon in 37 minutes where every speaker summarizes his talk in 30 seconds..
i will try to cover the most interesting talks -for me- later .. but for now .. i will start with most i liked
it was by Robert ‘r0ml‘ Lefkowitz about Exceptional Software..Explained you can watch the 30 seconds from the previously mentioned video here
i will quote what he said
one of the things we are trying to do is encourage large enterprises to adopt the open source practices..
difficulty that .. although we have open source practices .. we don’t have open source methodology..
large companies are used to methodologies like Rational Unified Process or the Microsoft Solutions Framework or SCRUM or eXtreme Programming .. that define “how it is that you go about it”
and there is NO open source methodology for HOW YOU DEFINE SOFTWARE ?
and then you think that “MAN .. this is going to get very boring” .. but you must watch the 30 seconds and then you will get why it is not .. especially that he presents a totally new methodology other than what we are used to
i have dug for the complete talk .. and found it here
the talk is extremely fun .. and very insightful
you can download most of the presentations from here
since you might be digging the internet for a notepad replacement or an explorer extension that makes searching files easier..
i thought to save u some bandwidth .. and tell you about some tools i like
most of these are Free Software. برامج حرة
Exploring, Navigation and GUI
no need to Dig through Start>All Programs or fill the desktop with millions if files .. or look for Calc each time you need to add 55 + 78 …find your programs and run them in no time
use Ctrl+Shift+V .. to paste stuff that you copied and overwritten .. like office Clipboard but cooler
if you like HackIt .. you will love PM, send any window to System Tray, makes it transparent or On Top
- Rocket Dock
Coolest app from the Mac World
Copy, Pause, Cancel and Resume in Windows Explorer and On Lan, hundreds of files.
adds a Toolbar in your Explorer, with some handy stuff (open ComandLine here, copy all pathes, copy names, rename all) .. extremely useful.
if you are a Linux fan .. then u know grep .. and u also know that windows search is useless .. grepWin Lets you search inside files with a RegEx or for normal Text
No matter what you do .. u can never rely on that.. so i will mention NONE
Network and Chat
u can see a cant be bias here
P2P file sharing program .. very configurable
Image via Wikipedia
- Orbit / Free Download Manager
may be slower than LogMeIn.. lets you share the desktop with your friend.. very helpfull for remote assistance
aside the fact that current GTK+ release on windows is extremely buggy, Pidgin is All In One Chat Client, very light, very cool .. simply you can have 2 Gtalk accounts + 1 yahoo + 3 MSN in one window, one program
the smallest of all, compared to its feature richness.
- FireFTP .. obvious
Sync your bookmarks across machines and even access them online
Proxy management, go TOR or any other Proxy in seconds
Drag and Drop any link in a new background tab .. instead of Ctrl+Click every time
- Shareaholic Found something awesome and cant wait to pass it on ? share over GReader, digg or anyother..
bookmarks in a smart way
- Sxipper Manages your passwords and fills-web forms .. extremely SMART
want to make your tabs at the bottom of the page , control ordering , force 1 instance of FF ?
- Zemanta a blogger ? .. u MUST try this
- Foxit Reader
compared to Adobe reader ? .. this one should be rated (999/5)
aka Churchill, a compact Dictionary, with shourtcut keys , just select, press ALT+T and u see the meaning. the last version is wierd, but its free any way
take alook for yourself, it can replace Notpad interly by the way
- Winamp ..
A Free, Cross-Platform Digital Audio Editor under GPL
Convert from any thing to any thing.. another verygood OSS
OpenSource Image Burner .. a free/Light Nero alternative and works great!
- Daemon Tools
OpenSource, Simulates a CD from an image, much compact than PowerISO and VirtualCD
Tired of the “your evaluation Copy expired” every time you open a zip file in WinRAR ?, 7-zip is the OpenSource alternative
Now to the best part
- pInvoke VS addon
get the pinvok signature of any function from PInvoke.Net
Not Free, but simply addictive
gives you every detail about any process in your system
Know what DLL’s your program loads.. know what symbols are exported by your DLL, TakeALook
Source Control Management .. if you are still makeing copies of your code and sending them through mail in zip files to your friends .. then you should start using SVN
convert Makefiles into VS Solutions
merge two code files or folders, see what changed , bla bla .. the best windows diff tool
i think that’s all.. you want to share a tool you like ? .. place it in the comments