[Perl] Prime numbers? xD

Talk about any languages right here. Share and discuss source, but don't expect your homework to be done for you.

[Perl] Prime numbers? xD

Postby Aiden » Thu Jan 07, 2010 5:48 pm

Don't mind me, just writing silly code. Forgive my lack of strict. Yes, you're right -- there is nothing in the body of those loops. What if we are all nothing in the body of loops?

Code: Select all
#!/usr/bin/perl

$max = 50;

while (((!defined $i ? $i = 1 : $i++) and ($i > $max ? exit() : $i) and ($j = 1)) or (!$i))
{
   while ((!defined $j ? $j = 1 : $j++) and ($j > $i ? last : $j) and ($j == $i ? print "$i\n" : $i) and ($i % $j != 0 ? $i : last))
{

   }
}


Or, when spaced out,
Code: Select all
#!/usr/bin/perl

$max = 50;

while (
   (
      (!defined $i ? $i = 1 : $i++)
      and
      ($i > $max ? exit() : $i)
      and
      ($j = 1)
   )

   or

   (!$i)

)
{

   while (
      (!defined $j ? $j = 1 : $j++)
      and
      ($j > $i ? last : $j)
      and
      ($j == $i ? print "$i\n" : $i )
      and
      ($i % $j != 0 ? $i : last)
      
   )
   {

   }
}


Output:
drusepth@bitdumpster:~$ perl lolwat.pl
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
"When it takes forever to learn all the rules, no time is left for breaking them."
User avatar
Aiden
Administrator
 
Posts: 1079
Joined: Tue Oct 31, 2006 11:11 pm
Location: /usr/bin/perl

Re: [Perl] Prime numbers? xD

Postby infinite_ » Sun Jan 10, 2010 11:28 am

Image
My effort to help you will never exceed your effort to explain the problem.
User avatar
infinite_
Bat Country
 
Posts: 1353
Joined: Fri Jun 04, 2004 7:19 pm
Location: Australia

Re: [Perl] Prime numbers? xD

Postby guidj0s » Sun Jan 10, 2010 1:13 pm

In writing my string utilities in C I also wrote some bodiless loops, so Im not complaining :) I might post what I have so far pretty soon.

I guess when writing code, you need to know what the purpose of it is. If it's just meant to be used in practical applications, then I guess smaller code is better code (the one you posted is a good example). If however the algorithm is to be transparent, visible, tangent, then I think it's fine to write larger, clearer files.

Thanks for sharing btw.

btw v0ide, I would so laugh out lout if I saw that tattooed on someone on the streets.
guidj0s
Hacker in Training
 
Posts: 74
Joined: Sat Oct 10, 2009 11:29 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests