Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I am aware of how simply this could have been done could have been done, but I was trying to do this in a vacuum as much as possible.

I am aware of how simply this could have been done, but I was trying to do this in a vacuum as much as possible.

I am aware of how simply this could have been done, but I was trying to do this in a vacuum as much as possible.

Tweeted twitter.com/StackCodeReview/status/677826432970674176
added 1 character in body
Source Link
TheCoffeeCup
  • 9.5k
  • 4
  • 38
  • 96

In the pursuit of learning f#F#, I have been working through some Project Euler problems.

I am new to both prime factorization and F#,F#; however, I am really only looking for comments on F#, not how poorly my factorization algorithm works (I know it's bad). i.e. what style mistakes am I making, or how the code could be made more functional.

In the pursuit of learning f#, I have been working through some Project Euler problems.

I am new to both prime factorization and F#, however I am really only looking for comments on F# not how poorly my factorization algorithm works (I know it's bad). i.e. what style mistakes am I making, or how the code could be made more functional.

In the pursuit of learning F#, I have been working through some Project Euler problems.

I am new to both prime factorization and F#; however, I am really only looking for comments on F#, not how poorly my factorization algorithm works (I know it's bad) i.e. what style mistakes am I making, or how the code could be made more functional.

Update to provide rational for the code
Source Link

Update

After thinking more about my solution overnight, I had more thought about exactly what my solution was doing, and why the simpler methods are so much simpler.

During my research on factoring primes, I think I got too caught up in the sieve of Eratosthenes , and didn't focus on the actual problem.

What I should have been trying to do:

  1. Search for the smallest prime factor
  2. Once found save it to the list of prime factors
  3. Divide this factor out of the number to be factored
  4. Repeat from step 1 substituting the number to be factored with the quotient from step 3, and start the search from the prime factor found in step 2.
  5. Get the biggest prime from the list.

What I actually did:

  1. Search for all prime numbers from 2 to the square root of the number to be factored.
  2. During the search, check each prime to see if it divides evenly.
  3. Once complete divide each of these "small primes" to generate a list potential big primes.
  4. Divide each of the big primes by all of the small primes as a test for primality.
  5. Combined the lists, and get the biggest one.

Update

After thinking more about my solution overnight, I had more thought about exactly what my solution was doing, and why the simpler methods are so much simpler.

During my research on factoring primes, I think I got too caught up in the sieve of Eratosthenes , and didn't focus on the actual problem.

What I should have been trying to do:

  1. Search for the smallest prime factor
  2. Once found save it to the list of prime factors
  3. Divide this factor out of the number to be factored
  4. Repeat from step 1 substituting the number to be factored with the quotient from step 3, and start the search from the prime factor found in step 2.
  5. Get the biggest prime from the list.

What I actually did:

  1. Search for all prime numbers from 2 to the square root of the number to be factored.
  2. During the search, check each prime to see if it divides evenly.
  3. Once complete divide each of these "small primes" to generate a list potential big primes.
  4. Divide each of the big primes by all of the small primes as a test for primality.
  5. Combined the lists, and get the biggest one.
edited tags
Link
200_success
  • 145.5k
  • 22
  • 190
  • 479
Loading
deleted 81 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
Source Link
Loading
lang-ml

AltStyle によって変換されたページ (->オリジナル) /