perfect-numbers

F# Power issues which accepts both arguments to be bigints

别来无恙 提交于 2019-12-08 15:29:12
问题 I am currently experimenting with F#. The articles found on the internet are helpful, but as a C# programmer, I sometimes run into situations where I thought my solution would help, but it did not or just partially helped. So my lack of knowledge of F# (and most likely, how the compiler works) is probably the reason why I am totally flabbergasted sometimes. For example, I wrote a C# program to determine perfect numbers. It uses the known form of Euclids proof, that a perfect number can be

Testing if an inputted Int is a perfect number

孤人 提交于 2019-12-02 08:41:47
I've been looking into perfect numbers, and I found this interesting bit of code on rosettacode: perfect n = n == sum [i | i <- [1..n-1], n `mod` i == 0] Now, I understand what a perfect number is, and I know which numbers are considered perfect, however I'm struggling to work out which parts of this code do what. I understand that it's working out the factors of the inputted number, and combining them together to see if it matches the input itself, but I'm not sure how it's doing this. If anyone could possibly break down this bit of code in a beginner-friendly manner I'd be very appreciative.

Python - Optimisation of Perfect Number search

痴心易碎 提交于 2019-11-29 14:54:50
p = [] for x in range(1, 50000000): count = 0 for y in range(1, x // 2 + 1): if (x % y == 0): count += y if (count == x): p.append(x) This is my code to try and find all the perfect numbers that originate between 1 and 50000000. It works fine for the first 3 numbers, they are between 1 and 10000. But as it progresses it becomes extremely slow. Like maybe going through 1000 numbers every 10 seconds. Then eventually going through 10 numbers every 5 seconds. Now is there anyway I could make this faster? I tried including some smaller things, like diving x by 2 to make sure we don't go over half

Python - Optimisation of Perfect Number search

自闭症网瘾萝莉.ら 提交于 2019-11-28 09:00:07
问题 p = [] for x in range(1, 50000000): count = 0 for y in range(1, x // 2 + 1): if (x % y == 0): count += y if (count == x): p.append(x) This is my code to try and find all the perfect numbers that originate between 1 and 50000000. It works fine for the first 3 numbers, they are between 1 and 10000. But as it progresses it becomes extremely slow. Like maybe going through 1000 numbers every 10 seconds. Then eventually going through 10 numbers every 5 seconds. Now is there anyway I could make this

F# parallelizing issue when calculating perfect numbers?

半世苍凉 提交于 2019-11-28 06:01:08
问题 I am trying to optimize a small program which calculates perfect numbers from a given exponent. The program runs (almost) perfectly, but when I open the task manager, it still runs on a single thread. That means that I must be doing something wrong, but my knowledge of F# is still in a 'beginning' phase. I will try to put this question as clear as I possibly can, but if I fail in doing so, please let me know. A perfect number is a number where the sum of all it's divisors (except for the