Friday, April 26, 2013

redoing a problem: 27

Problem 27: Quadratic primes in the form of n^2+an+b. Now I rewrote Python, and tried it in Haskell. My Haskell code runs slowly. I will try to learn in the forum.

Monday, April 22, 2013

redoing a problem: 26

Problem 26: Reciprocal cycles. I wrote it both in Python and Haskell.

Friday, April 19, 2013

redoing a problem: 25

Problem 25: 1000-digit Fibonacci number

I rewrote it in Python and Haskell.

Sunday, April 14, 2013

redoing a problem: 24

Problem 24: Lexicographic permutations

The old one brute forced the million permutations.  This time, I just calculated the number.

-----
(Update: 4/14) Rewrote the Python code in Haskell.

Monday, April 08, 2013

redoing a problem: 23

Problem 23: Non abundant sums.

Rewrote the python code.  The new code looks better than the old one, but it is slower.

Sunday, April 07, 2013

redoing a problem: 22

Problem 22: Names scores

I rewrote my Python code and wrote with a new C++ code. I also learned how to write it in Haskell in the forum.

Wednesday, December 26, 2012

Project euler memo: Problem 407

Problem 407: Finding the biggest a such that a^2 = a (mod n). This is an easy problem. But it took 30 minutes in Python.

-----
(Update 12/28/2012)
With better algorithm, it is now 18 minutes, still too slow.

Saturday, December 15, 2012

Hamming Problem

I do not have anything new, but I read about it this morning and I want to memorize it.


Hamming Problem is to generate a sequence of p^i * q^j * r*k, for the set of primes (p,q,r)  in increasing order.

I think I have seen this type of problem in Project Euler,  but I think my solution was not very efficient. 

The solution I've read was something like this.

def hammingproblem(p,q,r,n):
  a,b,c = 0,0,0
  t = [1]
  for k in xrange(1, n+1):
    x = p*t[a]
    if x > q*t[b]: x = q*t[b]
    if x > r*t[c]: x = r*t[c]
 
    if x == p*t[a]: a += 1
    if x == q*t[b]: b += 1
    if x == r*t[c]: c += 1
    t.append(x)

  return t

print hammingproblem(2,3,5,100)

n is the size of the sequence. (a,b,c) is the indexes of the candidate for a new number for (p,q,r). It is impressive to see the numbers in t are sorted. 

Thursday, November 29, 2012

Project euler memo: Problem 401

Problem 401: This one is easy. One minute and 40 seconds in Python.

I've just solved two problems including this one this month.

Tuesday, November 06, 2012

creating Kindle formatted document

I have a three-year-old Kindle2 device. I have bought some books, not a lot, from Amazon. And I put some PDF files in it. I like Kindle books because of their looks, but I do not like PDFs, because fonts are too small. I usually print unsolved problems from Project Euler into a PDF formatted file and put it in my Kindle2. I tried something different. There is the 'kindlegen' program to create Kindle formatted files. You can see a description here:
Kindle Publishing Programs
So I save the unsolved problems page in html, and just do:
$ kindlegen Project\ Euler.html
This creates Project\ Euler.mobi, and you can see it in Kindle devices and Kindle viewers. It seems there is difference in created htmls by browsers, and I use Google Chrome for this purpose. The file looks nicely in Kindle for Mac, but looks somewhat broken in the Kindle2 device, but still much better than PDF files.