Programming Riddles

Re: Programming Riddles

Ok so I just realized that in C# using pure LINQ we can write one liner to achieve the same results .

Here you go … enjoy :slight_smile:




private static bool IsAnagrams(string one, string two)
{
                  return one                    
                    .ToLower()
                    .ToCharArray()
                    .OrderBy(o => o)
                    .SequenceEqual(
                        two
                        .ToLower()
                        .ToCharArray()
                        .OrderBy(o => o)
                        );
}



Re: Programming Riddles

I think these for loops will work. One for the upper half and other for the lower half.


for (int i = 1; i < 10; i += 2) 

{

for (int j = 0; j < 9 - i / 2; j++)

system.out.print (" ");

for (int j = 0; j < i; j++)

system.out.print ("*");
system.out.print ("
");

}


for (int i = 7; i > 0; i -= 2) 

{

for (int j = 0; j < 9 - i / 2; j++)
system.out.print(" ");

for (int j = 0; j < i; j++)
system.out.print("*");

system.out.print("
");

}

I guess this will work. starts with one star and increases 2 *s next line. goes upto 9 *s. and then the same odd number back to finish it.

Re: Programming Riddles

This is the output



         *
        ***
       *****
      *******
     *********
      *******
       *****
        ***
         *


Good job.

Re: Programming Riddles

Here is something in python:



lines = "".join(("*" * y, " " * (w - (y * 2)), "*" * y)) for y in xrange(w / 2, 0, -1)]
print "
".join(lines + lines-2::-1])




********************
*********  *********
********    ********
*******      *******
******        ******
*****          *****
****            ****
***              ***
**                **
*                  *
**                **
***              ***
****            ****
*****          *****
******        ******
*******      *******
********    ********
*********  *********
********************


Re: Programming Riddles

Great Joel . I never really worked with python so can you please explain the logic you are using . Thanks .

Re: Programming Riddles

Yeah I’ve never worked in python too so that was interesting. A little lecture on how and what happened there would be appreciated Joel.

Re: Programming Riddles

Here’s mine:

"jurh/dksgdg**‘’
dskjhkjbhdsakjhkjdbasjkbjkasd;kdhs"
sadjhb@jsdab"
kjhds/abajhdsbcm[ewui"rhbjkhdsbjhdsk;abhkehj
dkjs]hbjhbdsjkhbujdkhbjkdhsbdjbj
"jhdsvbhvreughthrj/khdsjhdb>skhsahjasdbj<hdsjhdbvjhdb
s
ywuq<ioqoy
yrixhgcjsjishdhs"njjdjjdhd

Iz good? :blush:

Re: Programming Riddles

Oya you stopped typing with hands again . . . pando production na howay tay

Re: Programming Riddles

But it was a code :naak: The ananangram one!