Fork me on GitHub
#beginners
<
2022-10-02
>
Yu01:10:03

I would like to find abundant number. so 12 is an abundant number as its divisors are 1, 2, 3, 4, 6, and 12, totaling 28. I am trying to write a function, abundance, that has one argument, an integer, and returns the sum of the proper divisors of the number minus the number itself. For example, (abundance 12) should return 4.

pppaul01:10:11

sounds like a code-academy problem. almost all the problems on code academy have detailed wikipedia solutions for their problems

Yu01:10:17

I was able to find divisor

``````(defn divisor [integer]
(into [] (filter (fn [x] (zero? (mod integer x))) (range 1 (inc integer)))))``````

pppaul01:10:35

you didn't define abundant number, you only gave an example

Stuart01:10:40

Don't you only need to find divisors upto half of `n` ? i.e. if you can divide 12 by 2, then you have know divisors 2 and 6. So your range can be smaller.

Yu01:10:16

I am thinking adding what I got from divisor function then minus the last num * 2. I get (divisor 12) => [1 2 3 4 6 12] So add them up and do 28 - (12*2) ??

seancorfield04:10:20

@U0LAJQLQ1 I didn't think Codecademy had any Clojure courses?

pppaul04:10:24

@U04V70XH6 no, they don't. i didn't know that they had courses either. from my experience (mostly with project Euler) a good place to start with problems like this is on wikipedia. in this case there are 2 definitions for the type of number, neither provided by the original question posted.

Yu06:10:41

I will brush up my question. Thank you for your advise everyone:bow:

walterl20:10:20

seancorfield20:10:35

This https://clojurians-log.clojureverse.org/beginners/2022-10-02 (on my phone otherwise I'd give a more accurate link)

❤️ 1
seancorfield20:10:12

@U044TFZTBRA please don't delete your questions after they've been answered.

Yu20:10:13

Sorry, I won't.

seancorfield22:10:24

Here's a direct link to the OP question for this thread: https://clojurians-log.clojureverse.org/beginners/2022-10-02/1664674023.842049 -- I'm going to drop a similar link into the other thread. And here's the text from the OP: I would like to find abundant number. so 12 is an abundant number as its divisors are 1, 2, 3, 4, 6, and 12, totaling 28. I am trying to write a function, abundance, that has one argument, an integer, and returns the sum of the proper divisors of the number minus the number itself. For example, (abundance 12) should return 4.

❤️ 1