Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

So, I was off hunting for another obfuscation/golfing challenge for myself and was thinking about writing up an abundant number generator (I'd discovered an old app I'd done as a wee college student in pascal for my CS 112 class), but considered it too simple a task. A little digging around yielded weird numbers, which are, of course, abundant numbers which are not semi-perfect.

So now I give you, in only 176 characters, a weird number generator.

{$s=eval join'+',@d=grep!($n%$_),1.. ++$n-1;eval{w(@d,$n)if$s>$n};print$n ,$/if$@=~/!/;redo}sub w{my$s=pop|| die;my$t=pop||die'!';eval{w(@_,$s-$t )},$@=~/!/||die if$t<=$s;w(@_,$s)}

Note that with only small modifications, this script can also easily print out deficient numbers, abundant numbers, perfect numbers, semi-perfect numbers, multiply perfect numbers, and who knows how many other variations on the theme. A more interested party may try stepping in to upgrade this program to print out this information (6 P, 10 D, 12 A, 20 S, 70 W, 120 3P, and so on) for all numbers it encounters.

Update: Shaved off a character.

Update 2: Shaved off 10 more characters.

Update 3: Shaved off another 13 characters. Obviously, this wasn't as golfed as I'd originally thought. Wow.

Update 4: Added in another example, explaining Limbic~Region's example set below


In reply to Weird number generator by jimt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-25 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found