Announcements of available shared folders


Postby d_motto » Sun Aug 26, 2012 10:21 am

I have posted some programs in the Programming folder, and have since uploaded the folder for Oliver to look at and perhaps include some of the programs in other downloadable folders. Here is how the programs work:

cool numbers: AgeYou takes a date input and returns the absolute value of the difference in days from now.
example: "12/25/1970" AgeYou (can also use "December 25, 1970" with or without spaces)

integer input: Bell numbers, bit sum, Catalan, next Collatz number, Double Factorial, Derangements (Subfactorial), Digits, sum of digits, factors, farey function, Lucas numbers, Partition count, period of a fraction, unique factors, Ulam number, Unitary Divisors

123 BitSum returns 6 (sum of the bits in binary representation of 123)
10 Lucas returns 123 (Lucas numbers are like Fibonacci numbers, but start with 2, 1, 3, 4);
10 Bell returns 115975, the number of partitions of a set with 10 members.
10 Catalan returns 16976 (Catalan numbers are solutions to many combinatorial counting problems).
113 Collatz gives 340 (3n+1), running it again gives 170 (n/2). This is the next number in the the Collatz Conjecture/Ulam number series.
10 DblFact gives 3840, which is 10*8*6*4*2, the Double Factorial function.
10 Derange returns 1334961 (Derangements or subfactorials are the number of permutations where nothing is in the original position)
Digits returns the digits of a number as a vector, stopping if an "e" is found. 6.02e+23 would return [6 0 2] - using the split function would return [6 0 2 NaN NaN 2 3]).
digitSum gives the sum of digits, it uses Digits to get them, to avoid the NaN problem.
1000 Factors returns [2 2 2 5 5 5]
3 Farey gives 5, the number of Farey fractions between 0 and 1 with denominators less than or equal to 3 (0/1, 1/3, 1/2, 2/3, 1/1)
4 Partition returns 5, the number of ways to express 4 as the sum of positive integers (1+1+1+1, 1+1+2, 1+3, 2+2, 4)
7 Period returns 6, the number of repeating digits in the fraction 1/7
1000 UFactors returns [2 5], the unique prime factors of 1000
1000 Ulam gives 111, the number of iterations of Collatz to reach 1
1000 UniDivs returns [1 8 125 1000], the unitary divisors of 1000

fraction input: Egypt returns a vector of numbers whose inverses total to the original number
example: 2/7 returns [4 28], as (1/4 + 1/28) is (7/28 + 1/28) is 8/28 or 2/7

vector input: Diffs, PartConj
[1 4 9 16 25] Diffs gives [-3 -5 -7 -9], successive differences
[5 3 1 1] PartConj returns [4 2 2 1 1], the conjugate of the partition

Issues: No type or range checking is done
It would be nice for some functions to be able to handle different types of input (such as vectors and numbers, like factorial)
Automatically switching between numeric and bigint results would be nice, as the results get bigger.
Some numbers give tagged results in Period; and the program does not work correctly for some inputs.
Egyptian fractions don't work for some fractions (2/57); the last number in result vector is sometimes tagged as a fraction and sometimes isn't needed, due to rounding.

Dave Motto
Posts: 35
Joined: Tue Apr 17, 2012 9:19 am

Re: d_motto

Postby d_motto » Fri Sep 14, 2012 10:40 am

I have added one function, rewritten and renamed another, and improved some:

The new function is called DblFactB, and does a BigInt double factorial. I left the original function.

EgyptLG is a rewrite in JavaScript of the Egyptian Fraction function; the G indicates that I am using the Greedy Algorithm of Fibonacci (as I was before; take the largest unit fraction less than the number, subtract it, and continue). The difference is that I use a variable called tol (for tolerance), set now to 1e+12. This keeps the program from having denominators that are too large. Also, the program stops when a number repeats; this was the problem with 2/47. Last, the program stops when it returns a zero, as 1/0 is Inf.

Period now returns a negative number if the period of the fraction terminates (examples: 10 Period returns -2, as 1/10 is .01), and no longer returns a tagged number. It also appears to work correctly now.

Other changes from the original release: Bell now returns a BigInt, as does Lucas.

I have given this a version number of 1.2.

Dave Motto
Posts: 35
Joined: Tue Apr 17, 2012 9:19 am

Re: d_motto

Postby d_motto » Sat Nov 24, 2012 9:07 am

OK, version 1.3 has an added function and a couple of new things.

The new function is HappyQ, and takes an integer input, returning either a positive number, a negative number or zero. A happy number is one where, when you repeatedly take the digits, sum and square them, eventually returns a 1.
An unhappy number results in one of these numbers: 0, 4, 16, 20, 37, 42, 58, 89 or 145 (except for 0, the other numbers form a cycle).

The function returns the count of how many cycles it takes to get to a happy number (positive result), an unhappy number (negative result) or zero (if the number is one of the ones listed above - I can't figure out what else to return).

Also included is a function called Stuff that returns, for an integer input, many of the items from my other number theoretical functions, and something called PiObf which uses a function from Joe Horn to return an approximation of Pi, in a strange way.

David Motto
Posts: 35
Joined: Tue Apr 17, 2012 9:19 am

Return to Downloadable Folders / Shared Data

Who is online

Users browsing this forum: No registered users and 1 guest