Challenge: Factors + Perfect (Easy - Intermediate)

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 17589 Views - Last Post: 15 December 2011 - 08:39 AM

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Challenge: Factors + Perfect (Easy - Intermediate)

Post icon  Posted 28 November 2011 - 07:15 PM

Challenge: Factors + Perfect

Rating: Easy - Intermediate
Challenge Description:

This challenge comes in two parts;-
  • Write a function that returns all of the perfect factors of an input integer.
  • Write a function that returns true/false if the number is a perfect number.

Edit:- For the Adventurous write a method that that returns all of the Perfect Numbers within a given positive range. (Note: 1 - 100000)

VB.net is preferred programming language for this challenge.

Entries must state the .net framework being used. Eg .net: >= 3.5 (Client Profile)
Enclose your code inside the following tags (obviously without the spaces.)
[ spoiler ] [ code ] [ /code ][ / spoiler]
Working examples must be in a Zip archive (No naked binarys!)

Closing date for submissions to be eligible for Awards (Monday 5th Dec 23:59 GMT).
Submissions can be posted afterwards.

Awards for
- Shortest Amount of Code
- Fastest Code (when run on my machine)
- Most interesting.

This post has been edited by AdamSpeight2008: 29 November 2011 - 07:09 PM


Is This A Good Question/Topic? 3
  • +

Replies To: Challenge: Factors + Perfect (Easy - Intermediate)

#2 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1906
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 29 November 2011 - 03:29 AM

Could you clarify the second part please? When you say "if the number is a perfect number", do you mean "if the integer is a perfect number"?

Not asking to be picky: It makes a difference to my implementation.

I guess another question is are you providing the test/benchmark code or should we provide a main method to go with the functions?

This post has been edited by cfoley: 29 November 2011 - 08:55 AM

Was This Post Helpful? 0
  • +
  • -

#3 SwiftStriker00  Icon User is offline

  • Microsoft Insider
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,596
  • Joined: 25-December 08

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 29 November 2011 - 12:32 PM

by perfect factor, you mean a factor that is a perfect number. Correct?
Was This Post Helpful? 0
  • +
  • -

#4 SwiftStriker00  Icon User is offline

  • Microsoft Insider
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,596
  • Joined: 25-December 08

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 29 November 2011 - 02:13 PM

Here ya go. I went for creative over speed, and it turns out the larger perfect number you go, the faster mine gets.

Spoiler

This post has been edited by SwiftStriker00: 29 November 2011 - 02:18 PM

Was This Post Helpful? 0
  • +
  • -

#5 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1906
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 29 November 2011 - 02:53 PM

Here is my effort. VB 2010 Express. Small code and fast (I'm sure a seasoned VB veteran would be able to make this smaller and faster)

Spoiler


You may think this is cheating so by way of explanation...

Spoiler

Was This Post Helpful? 0
  • +
  • -

#6 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1906
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 29 November 2011 - 03:11 PM

A wee addition:

Spoiler

Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 29 November 2011 - 06:25 PM

Perfect Factor is a Divisor of a number that leaves a no remainder, itself does not have to be a Perfect Number.

cfoley: Including a list of Perfect Number, I would class a not calculating - thus cheating.
Was This Post Helpful? 0
  • +
  • -

#8 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1906
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 29 November 2011 - 06:44 PM

Your competition, your rules. :)

I'll see if I can summon the energy to write a factorisation method.
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 29 November 2011 - 06:52 PM

My version just for fun.

Using features from the VS2011 version of VB and .net4.5
Spoiler

This post has been edited by AdamSpeight2008: 29 November 2011 - 07:18 PM

Was This Post Helpful? 0
  • +
  • -

#10 Beach_Coder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 123
  • Joined: 10-November 11

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 30 November 2011 - 10:07 AM

With respect to Part 1 of the Challenge, should Integer be interpreted as any Integer, any Whole Number, any Integer up to the limit of the Int32 datatype or any other subset of all Integers?



Also, if I may, due to the unnerving degree to which mathematicians disagree on the definition of various terms (as well my own OCD and mal-appropriate perfectionism) and I suppose with some risk of creating more confusion in an effort of disambiguity:

A Factor of any given Integer is commonly (and disturbingly) interpreted to mean Prime Factor. This is to such a degree that the term is effectively ambiguous. If one means Factor, one is better off specifying either All Factors or Prime Factors (or whatever other precisely descriptive term is appropriate to the situation). Further, the term Divisor is preferred over Factor because of the common interpretation of Factor to mean Prime Factor. All of this despite Divisor of an integer and Factor of an integer having the same meaning.

A Proper Divisor of a given positive Integer is a positive Divisor of the Integer other than the Integer itself which leaves a Remainder of zero. The terms Perfect Divisor and Perfect Factor are not widely used. However, in determining if a number is a Perfect Number, one evaluates the sum of the Proper Divisors in comparison to the number.
Was This Post Helpful? 0
  • +
  • -

#11 Beach_Coder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 123
  • Joined: 10-November 11

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 30 November 2011 - 10:52 AM

View PostAdamSpeight2008, on 28 November 2011 - 09:15 PM, said:

Challenge: Factors + Perfect

Rating: Easy - Intermediate
Challenge Description:

...
Awards for

- Fastest Code (when run on my machine)


How many processors does your machine have?
32 or 64 Bit?
What operating system?

I don't know if it's appropriate to ask, or even how to best exploit the differences among various scenarios here (yet), but I decided it couldn't hurt to ask.
Was This Post Helpful? 0
  • +
  • -

#12 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 01 December 2011 - 02:26 PM

You lot know how to suck the fun, out a challenge.

OK it an Int32, so it doesn't matter about the bit-ness of the OS.

Tt'll be tested either (not decided which yet)

1.8Ghz Dual Core Windows 7 Machine with 2Gb
or I may test run them on the Old Server I have with Dual Xeon (Hyperthreaded) 3.2Ghz 64-Bit 6GB RAMHypertreaded (OS: Windows Server 2008r2)
Was This Post Helpful? 0
  • +
  • -

#13 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2506
  • View blog
  • Posts: 4,615
  • Joined: 24-September 10

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 05 December 2011 - 01:03 PM

All these competitions do is make me want Visual Studio 2010 at my office... I have it at home, but not here at work. So I don't get the Yield functionality, which I love from C#... :(
Was This Post Helpful? 0
  • +
  • -

#14 Beach_Coder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 123
  • Joined: 10-November 11

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 06 December 2011 - 08:31 AM

So I suppose I could have just submitted the functions alone days ago, but I proceeded with creating an application (that has the wrong connotation though, little program more appropriate) which might have been a mistake since working my way around the publishing wizard is like throwing darts at a board.

Note: There is a proof that the smallest odd perfect number is at least 10 E 300.
I think 300 zeros might be in the area of super polynomial time to factor. If not it's close. Of course I didn't know that until after I spent a couple of days trying to remember some formula I though I forgot from high school that, as it turns out, doesn't yet exist.
Last week I stumbled across a paper that endeavors to demonstrate that the smallest odd perfect number is at least 10 E 1500. I'd comment on it, but it may as well have been written in Ancient Greek.

Spoiler


Okay I think I did this right (the posting that is). I am slightly less confident in how I used the publishing wizard and zip thing. My apologies if I did something awful.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#15 Beach_Coder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 123
  • Joined: 10-November 11

Re: Challenge: Factors + Perfect (Easy - Intermediate)

Posted 09 December 2011 - 06:54 PM

So, who won the challenge?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2