Euler problem 10.2

Find the sum of all the primes below two million.

removeIf :: (a -> Bool) -> [a] -> [a]
removeIf p = filter (not . p)

sieveIter :: Integral a => [a] -> [a] -> [a]
sieveIter [] (x:xs) = x:xs
sieveIter (x:xs) acc
  | x^2 > last (x:xs) = reverse acc++(x:xs)
  | otherwise = sieveIter xss (x:acc)
    xss = removeIf (\n -> n `mod` x == 0) xs

primeList :: Integral a => [a] -> [a]
primeList xs = sieveIter xs []

pL :: [Integer]
pL = primeList [2..2000000]

f :: Integer
f = sum (takeWhile (< 2000000) pL)

— colorized by palette fm

— Me@2023-02-25 12:35:57 PM



2023.02.26 Sunday (c) All rights reserved by ACHK



a library for writing infix mathematical notation in Common Lisp.

To install it:

1. In the Bash terminal, get Quicklisp by the following command:

sudo apt-get install cl-quicklisp

The file quicklisp.lisp will be created at



2. Run the command

sbcl --load /usr/share/common-lisp/source/quicklisp/quicklisp.lisp

3. Follow the install instructions:




4. To enable the library, in the Common Lisp REPL, run the code:

(ql:quickload :cmu-infix)

5. And then run:

(named-readtables:in-readtable cmu-infix:syntax)


6. To test the library, run:

(defmacro add (x y)
  `(let ((a ,x)
         (b ,y))

(add 2 3)

(macroexpand-1 '(add 2 3))

(macroexpand-1 '#I(1+2-3*5^^6))

(eval (macroexpand-1 '#I(1+2-3*5^^6)))

— Me@2022-12-25 10:13:04 AM



2022.12.25 Sunday (c) All rights reserved by ACHK

Pier, 2.2

Euler problem 9.1


There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.

(defun e9c ()
  (loop :for a :from 1 :to 1000 :do
    (loop :for b :from 1 :to a :do
      (let ((c (- 1000 (+ a b))))
        (if (= (+ (* a a) (* b b)) (* c c))
            (return-from e9c
                (list a b c (* a b c))))))))

— colorized by palette fm

— Me@2022-12-05 05:59:49 PM



2022.12.05 Monday (c) All rights reserved by ACHK

Euler problem 8.3


mString := Import["n.txt"]

nString := StringDelete[mString, "\n" | "\r"]

nList := Map[FromDigits, Characters[nString]]

take13[lst_] := Times @@ Take[lst,13]

Fmax13n[lst_, n_] := If[Length[lst] < 13,
                        With[{t13 = take13[lst]},
                            If[n > t13,
                                Fmax13n[Rest[lst], n],
                                Fmax13n[Rest[lst], t13]]]]

Fmax13n[nList, 0]

Wmax13n[lst_, n_] := Which[
                        Length[lst] < 13, n,
                        t13 = take13[lst];
                            n > t13, Wmax13n[Rest[lst], n],
                            True, Wmax13n[Rest[lst], t13]]

Wmax13n[nList, 0]

Fmax13n[nList, 0] - Wmax13n[nList, 0]

— colorized by palette fm

— Me@2022-11-24 05:51:56 PM



2022.11.24 Thursday (c) All rights reserved by ACHK

Pier, 1.2

Euler problem 8.1




Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?

(defun file-get-contents (filename)
  (with-open-file (stream filename)
    (let ((contents (make-string
                     (file-length stream))))
      (read-sequence contents stream)

(defun file-get-lines (filename)
  (with-open-file (stream filename)
    (loop :for line = (read-line stream nil)
          :while line
          :collect line)))

(file-get-lines #P"n.txt")

(defun string-to-list (the-string)
  (loop :for char :across the-string
        :collect char))

(defun char-to-integer-list (char-list)
  (mapcar #'digit-char-p char-list))

(let ((the-digits (char-to-integer-list
            (remove #\newline
                    (file-get-contents #P"n.txt"))))))

  (loop :for i :from 0 :to (- (length the-digits) 13)
        :maximize (apply #'*
                      the-digits i (+ i 13)))))


— colorized by palette fm

— Me@2022-11-12 04:50:19 PM



2022.11.12 Saturday (c) All rights reserved by ACHK


This was my Art result. I had a great art teacher Mr Lo in that year. He taught us a lot of design concepts.

— Me@2020-12-29 10:52:04 AM



2020.12.29 Tuesday (c) All rights reserved by ACHK



It was a picture I drawn in 1997. It was the summer holiday after my HKCEE public exam. It was a drawing trip with my school’s Art Club. The location was Sai Kung Pier.

As far as I remember, I haven’t drawn since then. Perhaps I do not like to draw alone. Hope that one day I could find my girlfriend finally so that I have someone to draw with.

— Me@2020-03-24 10:37:58 PM



2020.03.26 Thursday (c) All rights reserved by ACHK

Genius 3


* If you knew how much work went into it, you would not call it genius.

o On the paintings in the Sistine Chapel

— Michelangelo Buonarroti




2011.01.10 Monday ACHK



An expert pianist can play notes faster than the brain can send signals to his hand. Likewise an artist, after a while, can make visual perception flow in through his eye and out through his hand as automatically as someone tapping his foot to a beat.

— Paul Graham




2010.06.12 Saturday ACHK

A pretty girl


Anybody can look at a pretty girl and see a pretty girl. An artist can look at a pretty girl and see the old woman she will become. A better artist can look at an old woman and see the pretty girl that she used to be. But a great artist — a master — and that is what Auguste Rodin was — can look at an old woman, portray her exactly as she is… and force the viewer to see the pretty girl she used to be…. and more than that, he can make anyone with the sensitivity of an armadillo, or even you, see that this lovely young girl is still alive, not old and ugly at all, but simply prisoned inside her ruined body. He can make you feel the quiet, endless tragedy that there was never a girl born who ever grew older than eighteen in her heart…. no matter what the merciless hours have done to her. Look at her, Ben. Growing old doesn’t matter to you and me; we were never meant to be admired — but it does to them. Look at her! (UC)

— Robert A. Heinlein




2010.03.09 Tuesday ACHK