Posts
Showing posts from September, 2011
C++ Macro Concatenation
Source: http://www.gowrikumar.com Problem: What is the output of the following C++ code? #include <stdio.h> #define f ( a , b ) a ## b #define g ( a ) # a #define h ( a ) g ( a ) int main () { printf ( " %s \n " , h ( f ( 1 , 2 ))); printf ( " %s \n " , g ( f ( 1 , 2 ))); return 0 ; } Update (14 Sept 2011): Solution posted in comments by Prathmesh Prabhu (CSE IITB 2010 Alumnus and Wisonsin Madison II-year Graduate Student)
Arrange in a Sequence
Source: Asked to me by Amol Sahasrabudhe (IITB 2004 Alumnus, Worked at Morgan Stanley Quant Division, Deutsche Bank) Problem: You are given 2n numbers ( 1 to n and 1 to n ). You have to arrange these numbers in a sequence such that between any two i `s , there exists exactly i-1 numbers. Is it possible for all n ? If no, what are the values of n for which this is possible? Disclaimer: I have not been able to solve it. Sudhanshu Tungare (IITB 2008 EE Alumnus, Morgan Stanley) claims to have a solution. Cheers! Update (November 1, 2011): Part solution posted by Nishant Totla (CSE IITB Senior Undergraduate), Richie and Sarat in comments! Complete solution posted by Siddhant Agarwal (EE IITB Alumnus, CMI Grad student) in comments! Thanks a ton.