Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Weird number generator

by jimt (Chaplain)
on Oct 23, 2006 at 15:53 UTC ( #580083=obfuscated: 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

Comment on Weird number generator
Select or Download Code
Re: Weird number generator
by Limbic~Region (Chancellor) on Oct 24, 2006 at 16:29 UTC
    jimt,
    From your spoiler:
    Okay, this function will determine if for a given set of natural numbers, is there a subset of those numbers that add up to the given sum.

    Since your explanation of this function is in the spoiler, I will put my comment in a spoiler as well.

    Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://580083]
Approved by Albannach
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2014-09-21 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls