Over at Stack Overflow, I answered a question about cutting fields from a CSV file. Paraphrasing: A file in CSV format has a header row containing field names followed by record rows containing actual data. The user wants to cut fields from the CSV file to create a new CSV file containing only the specified […]
Over on YouTube, Michael Penn proves that the sum of reciprocals of the palindromes converges: But he doesn’t compute the value to which the sum converges. Your task is to compute the infinite sum. When you are finished, you are welcome to read a suggested solution, or to post your own solution or discuss the […]
Today’s exercise is from a beginner programming web site: A prime number, such as 127, has no factors other than itself and one. A palindrome, such as 121, is the same number when its digits are reversed. A prime palindrome, such as 131, is both prime and a palindrome. Find the 100th prime palindrome. Your […]
[ I’ve had a couple of readers ask where I have been. I put in my retirement papers at work a few months ago, and will retire at the end of 2021. That sounds good, but setting up my post-retirement finances, learning about Medicare (it’s a huge mess) and deciding what to do with the […]
Aronson’s sequence 1, 4, 11, 16, 24, 29, 33, 35, 39, … (A005224) is an infinite self-referential sequence defined as: T is the first, fourth, eleventh, … letter in this sentence. Your task is to write a program that generates Aronson’s sequence and use it to compute the first hundred members of the sequence. When […]
Cardinal numbers are those used for counting; spelled in letters, they are one, two, three, four, and so on. Ordinal numbers are those used for ranking: spelled in letters, they are first, second, third, fourth, and so on. Your task is to write a program that takes a number and returns the spelled-out cardinal and […]
Lagarias and Sloane study the “approximate squaring” map f(x) = x⌈x⌉ and its behavior when iterated in this paper. Consider the fraction x = n / d when n > d > 1; let’s take 8/7 as an example. In the first step, the smallest integer greater than 8/7 (the “ceiling”) is 2, and 8/7 […]
I had an email from a reader who found my factoring program on Stack Overflow: Python 2.7.13 (default, Mar 13 2017, 20:56:15) [GCC 5.4.0] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> def isPrime(n, k=5): # miller-rabin ... from random import randint ... if n < 2: return False ... for […]
Today’s exercise comes from one of those online code exercises, via Stack Overflow: There is a machine that can fix all potholes along a road 3 units in length. A unit of road will be represented by a period in a string. For example, “…” is one section of road 3 units in length. Potholes […]
Today’s exercise comes from Stack Overflow: Given a number N and a set of numbers s = {s1, s2, …, sn} where s1 < s2 < … < sn < N, remove all multiples of {s1, s2, …, sn} from the range 1..N. You should look at the original post on Stack Overflow. The poster […]