01 July 2022

Abundantly odd and ... Oh dear!

 Abundant odd numbers

Task 1 asks us to write a script to generate first 20 Abundant Odd Numbers (AONs). Wikipedia tells us that n is an abundant number if the sum of its divisors (including itself) σ(n) > 2n.  Some abundant numbers are even, but we only want the odd ones.

Finding the divisors of a number isn't too hard, but I save myself the trouble by invoking Math::Prime::Util qw(divisors), and simply by checking successive odd integers we get the required 20 AONs in milliseconds. The 20th AON is 8925, so we don't need BigInt, and in fact the 200th is 92925 and even the 2000th is a manageable 1002375.

References to functions

Task 2 asks:

Create sub compose($f, $g) which takes in two parameters $f and $g as subroutine refs and returns subroutine ref i.e. compose($f, $g)->($x) = $f->($g->($x))

Hmm.

I have written something like a million lines of code over 50 years in IT, and the number of times I have felt the need for a reference to a function is quite small - in fact I can only remember one occasion.  So perhaps my unfamiliarity helps to explain why I don't really grasp the question.

So I shall not submit an attempt this time, and will read others' responses with some interest.



No comments:

Post a Comment