A perfect number is a number

nthat is equal to the sum of its divisors, excluding itself; in other words, a perfect numbernsatisfies the equation σn= 2n, where σ is the divisor-sum function. A triperfect number is a numbernsuch that σn= 3n. It is believed that there are six, and only six, triperfect numbers.

Your task is to compute the six triperfect numbers. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

]]>An integer

n> 1 is ak-almost-prime if it is the product ofkprimes. Further, ak-almost prime is squarefree if allkprimes are distinct.

You can learn more about *k*-almost-primes and their uses in number theory at Wikipedia or MathWorld.

Your task is to write programs that calculate the first ten *k*-almost-primes and squarefree *k*-almost-primes for 1 ≤ *k* ≤ 5. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Your task is to write a program that mimics the calculations made by Dr Grimes. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

]]>- Solve for
*x*and*y*where both are integers: 615 +*x*^{2}= 2^{y} - Find a three-digit number
*abc*= 100*a*+ 10*b*+*c*with none of the digits 0 such that*abc*=*a*! +*b*! +*c*! - Find a three-digit number
*pie*= 100*p*+ 10*i*+*e*with none of the digits 0 such that √pi + e = √ pie

Your task is to solve the three problems; you can write programs to solve them, if you wish, but it is fun to solve them by hand. When you are finished, you are welcome to or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

]]>`grep`

for that task. Sometimes `grep`

gives me unwanted records, because there is a match in some field that is not the field of interested, and I just ignore the extra records. But the other day I had a mess, with `awk`

to parse out the fields and find the records of interest.
I realized as I was performing that task that it would be useful to have a version of `grep`

that understood the CSV file format. So I wrote `grep-csv`

that takes a field number (counting from 1, like `awk`

) and a regular expression and returns the matching rows of a CSV file.

Your task is to write a `grep-csv`

program. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

`let-values ... apply values`

that makes the code concise at the cost of forcing readers to think through an uncommon idiom. What I wanted was something similar to the destructuring-bind macro of Common Lisp.
So I wrote one.

Your task is to write a macro similar to the destructuring-bind macro of Common Lisp and add it to your favorite programming language. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution in the comments below.

]]>implement Okasaki’s physicist’s queues, which you can read about in either his book (Figure 6.3 on page 73) or his thesis (Figure 3.4 on page 31). Queues provide two constructors

`empty`

and `snoc`

, two accessors `head`

and `tail`

, and a single predicate `isEmpty`

; it is an error if either `head`

or `tail`

are applied to an empty queue. This version comes from the book:
structure PhysicistsQueue : QUEUE struct type alpha Queue = α list × int × α list susp × int × α list val empty = ([], 0, $[], 0, []) fun isEmpty (_, lenf, _, _, _) = (lenf = 0) fun checkw ([], lenf, f, lenr, r) = (force f, lenf, f, lenr, r) | checkw q = q fun check (q as (w, lenf, f, lenr, r)) = if lenr < lenf then checkw q else let val f' = force f in checkw (f', lenf + lenr, $(f' @ rev r), 0, []) end fun snoc ((w, lenf, f, lenr, r), x) = check (w, lenf, f, lenr + 1, x :: r) fun head ([], lenf, f, lenr, r) = raise EMPTY | head (x :: w, lenf, f, lenr, r) = x fun tail ([], lenf, f, lenr, r) = raise EMPTY | tail (x :: w, lenf, f, lenr, r) = check (w, lenf - 1, $tl (force f), lenr, r) end

Your task is to implement Okasaki’s physicists queues. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

]]>The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …

Let us list the factors of the first seven triangle numbers:

1: 1

3: 1,3

6: 1,2,3,6

10: 1,2,5,10

15: 1,3,5,15

21: 1,3,7,21

28: 1,2,4,7,14,28We can see that 28 is the first triangle number to have over five divisors.

What is the value of the first triangle number to have over five hundred divisors?

Your task is to write a program to solve Project Euler 12. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

]]>Take a number. Multiply all its digits together. Repeat with the new number until it reaches a single digit. For instance, starting from 327, the product of the digits 3, 2 and 7 is 42, then recurring with 42 the product of the digits 4 and 2 is 8, which is the final answer; we say the sequence 327 → 42 → 8 finishes in 2 steps. What number leads to a sequence with the maximal number of steps?

The video includes some live-coding in Python by Matt.

Your task is to implement a function to compute the multiplicative persistance sequence starting from a given number, then “play with it” as Matt suggests. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

]]>I have a file like this:

AAKRKA HIST1H1B AAGAGAAKRKATGPP AAKRKA HIST1H1E RKSAGAAKRKASGPP AAKRLN ACAT1 LMTADAAKRLNVTPL AAKRLN SUCLG2 NEALEAAKRLNAKEI AAKRLR GTF2F1 VSEMPAAKRLRLDTG AAKRMA VCL NDIIAAAKRMALLMA AAKRPL WIZ YLGSVAAKRPLQEDR AAKRQK MTA2 SSSQPAAKRQKLNPAI would like to kind of merge 2 lines if they are exactly the same in the 1st column. The desired output is:

AAKRKA HIST1H1B,HIST1H1E AAGAGAAKRKATGPP,RKSAGAAKRKASGPP AAKRLN ACAT1,SUCLG2 LMTADAAKRLNVTPL,NEALEAAKRLNAKEI AAKRLR GTF2F1 VSEMPAAKRLRLDTG AAKRMA VCL NDIIAAAKRMALLMA AAKRPL WIZ YLGSVAAKRPLQEDR AAKRQK MTA2 SSSQPAAKRQKLNPASometimes there could be more than two lines starting with the same word. How could I reach the desired output with bash/awk?

Your task is to write a program to solve this simple task of data laundry. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

]]>