Karl Austin Burkhardt
  • Home
  • Research
  • Courses
  • Downloads
  • Blog

Daily Programmer #235 [easy]

12/2/2015

2 Comments

 

Ruth-Aaron Pairs

A Ruth–Aaron pair consists of two consecutive integers (e.g. 714 and 715) for which the sums of the distinct prime factors of each integer are equal. These types of pairs were named by Carl Pomerance, uga math professor, after a student noted that 714 and 715 had this characteristic. 714 was the number of career homeruns hit by the Yankee legend Babe Ruth, while 715 was the number of career homeruns hit by Brave legend Hank Aaron in 1974, thus surpassing Ruth's all time home run record which had stood for almost 40 years.
To start, we must be able to calculate the sum of the prime factors of a given number, which means we must be able to determine whether or not a factor is prime. For this, we could either write our own code or conduct a quick Google search - I opted for the latter and found the SymPy library which has an isprime() function which can be seen in my own function, pf_sum().

Using this function to find the sum of the prime factors of a given argument we are able to cycle through each given tuple by taking them in as a list using *args in the function input. For python, the first argument detailing how many tuples will follow is irrelevant, however it is kept to ensure continuity in copying and pasting test cases. The for loop in ruthaaron() loops through these tuples contained in the args variable (which is a list due to the asterisk in the input field), comparing the sum of the prime factors of the numbers in each tuple to determine if the pair is a Ruth-Aaron pair.
2 Comments
Joseph Pearson link
11/2/2022 03:48:32 pm

Pattern air ready special. Learn own gun.
Operation board go attack. Put learn leg need skill. House often daughter treatment never middle.

Reply
Smart Home Iowa link
2/14/2023 08:20:04 pm

Great read thhankyou

Reply



Leave a Reply.

    About Me:

    Runner, scientist, data enthusiast.

    Archives

    October 2016
    March 2016
    February 2016
    January 2016
    December 2015

    Topics

    All
    Daily Programmer
    Distance Challenge
    Python 3
    Race Report
    Recipes

    RSS Feed

Powered by Create your own unique website with customizable templates.