Euler problem 12.1.1

(defmacro sq (x)
  `(* ,x ,x))

(defmacro last-item (lst)
  `(car (last ,lst)))

(defun good-reverse (lst)
  (labels ((rev (lst acc)
             (if (null lst)
                 acc
                 (rev
                  (cdr lst)
                  (cons (car lst) acc)))))
    (rev lst nil)))

(defun prime-sieve-a-list (input-lst)
  (labels ((sieve-iter (go-lst acc-list)
             (if (not go-lst) 
                 acc-list        
                 (if (> (sq (car go-lst))
                        (last-item go-lst))

                     (append (good-reverse acc-list)
                             go-lst)
                     
                     (sieve-iter
                      (remove-if #'(lambda (x)
                                     (=
                                      (mod x
                                           (car go-lst))
                                      0))
                                 (cdr go-lst))
                      (cons (car go-lst)
                            acc-list))))))

    (sieve-iter input-lst '())))

(defun range (max &key (min 0) (step 1))
  (loop :for n :from min :below max :by step
        collect n))

(defmacro prime-sieve (n)
  `(prime-sieve-a-list (cons 2
                             (range (1+ ,n)
                                    :min 3
                                    :step 2))))


(time (length (prime-sieve 20000000)))

;; Evaluation took:
;; 19.907 seconds of real time

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

(defun factor-iter (n p-list acc-list)
  (if (NULL p-list)
      acc-list         
      (let* ((p (car p-list))                                   
             (ps (cdr p-list)))  
        (cond ((> (* p p) n)           
               (good-reverse (cons n
                                   acc-list)))
              ((eql (mod n p) 0)
               (factor-iter (floor n p)
                            p-list
                            (cons p acc-list)))   
              ('t
               (factor-iter n ps acc-list))))))

(defparameter *pm* 2000000)

(defparameter *psi* (prime-sieve *pm*))

(defun factor (n)
  (if (> n (expt *pm* 2))
      
      (let ((m (floor (sqrt n))))
        (factor-iter n (prime-sieve m) '()))
      
      (factor-iter n *psi* '())))

(defun group-factors (lst)
  (labels ((gf (acc lst)
             (if (NULL lst)
                 (good-reverse acc)
                 (let* ((p (car lst))
                        (ps (cdr lst))
                        (lp1 (list p 1)))
                   (if (NULL acc)                      
                       (gf (list lp1) ps)                      
                       (if (eql p (caar acc))
                           (gf (cons
                                (list p
                                      (+ 1
                                         (cadar acc)))
                                (cdr acc))
                               ps)                  
                           (gf (cons lp1 acc) ps)))))))    
    (gf '() lst)))

(defmacro sum (lst)
  `(reduce #'+ ,lst))

(defmacro product (lst)
  `(reduce #'* ,lst))

(defun nDiv (n)
  (product (mapcar #'(lambda (x) (1+ (cadr x)))
                   (group-factors (factor n)))))

(defun fm (m n)
  (labels ((tri-div (n)
             (if (evenp n)
                 (* (nDiv (/ n 2)) (nDiv (1+ n)))
                 (* (nDiv n) (nDiv (/ (1+ n) 2))))))    

    (if (> (tri-div n) m)
        (/  (* n (1+ n)) 2) 
        (fm m (+ 1 n)))))

;

(time (fm 500 1))

;; Evaluation took:
;; 0.007 seconds of real time

;; 76576500

— Me@2023-03-25 07:51:18 PM

.

.

2023.03.27 Monday (c) All rights reserved by ACHK

Corsair Vengeance RGB Pro

你有「婚前性」的話,一定不會從一而終。

如果你宣稱,你的「婚前性」對象,由始至現在至未來,只有一位,亦只會有一位的話,那樣,你在一開始時,為何不先與其結婚?

.

第二,數字不是零或一的話,就不知是多少。

.

第三,可以前的話,就可以外。

— Me@2023-03-12 10:28:29 AM

.

.

2023.03.13 Monday (c) All rights reserved by ACHK

MangoHud

A Vulkan and OpenGL overlay for monitoring FPS, temperatures, CPU/GPU load and more.

.

.

vram
ram
swap
gpu_temp
cpu_temp
gpu_power
cpu_power

.

.

— Me@2023-03-07 09:14:51 AM

.

.

2023.03.07 Tuesday (c) All rights reserved by ACHK

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)
  where
    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

Euler problem 10.1

Find the sum of all the primes below two million.

(defmacro sq (x)
  `(* ,x ,x))

(defmacro last-item (lst)
  `(car (last ,lst)))

(defun good-reverse (lst)
  (labels ((rev (lst acc)
         (if (null lst)
         acc
         (rev
          (cdr lst)
          (cons (car lst) acc)))))
    (rev lst nil)))

(defun prime-sieve-a-list (input-lst)
  (labels ((sieve-iter (go-lst acc-list)
         (if (not go-lst) 
         acc-list        
         (if (> (sq (car go-lst))
            (last-item go-lst))

             (append (good-reverse acc-list)
                 go-lst)
             
             (sieve-iter
              (remove-if #'(lambda (x)
                     (=
                      (mod x (car go-lst))
                      0))
                 (cdr go-lst))
              (cons (car go-lst)
                acc-list))))))

    (sieve-iter input-lst '())))

(defun range (max &key (min 0) (step 1))
  (loop :for n :from min :below max :by step
    collect n))

(defmacro prime-sieve (n)
  `(prime-sieve-a-list (cons 2 (range (1+ ,n)
                      :min 3
                      :step 2))))

(defun sum (lst)
  (reduce #'+ lst))

(sum (prime-sieve 2000000))

(time (sum (prime-sieve 2000000)))

— Me@2023-02-16 11:34:49 PM

.

.

2023.02.21 Tuesday (c) All rights reserved by ACHK

G40-70

If you are using SSD, you should turn off the swap file:

1. In command line, run

swapoff --all

2. Backup the file

/etc/fstab

3. Then, in that file, comment out any lines that contain the word “swap”.

— Me@2023-02-14 05:00:26 PM

.

.

2023.02.15 Wednesday (c) All rights reserved by ACHK

Computing Note, 4

08[.]07[.]2002 

1. Use Computer Software to improve/[]upgrade 
your Brain Software  

10[.]07[.]2002 

2. Software Philosophy: 

Use it, enjoy it, but keep your ability 
to live without it. 

<<Conversation with God>>

Enjoy everything, but need nothing! 

(Even people? 
Especially people!) 

.

.

2023.02.11 Saturday (c) All rights reserved by ACHK

FF7R

Crucial MX500 1TB 3D NAND SATA SSD

.

Final Fantasy 7 Remake Steam version testing result:

1. With GTX 1050 Ti as the GPU, the bottleneck is the GPU, not the CPU, even though my CPU itself was weak.

2. However, once the GPU got upgraded, the CPU became the bottleneck.

The following settings can make the game smoother:

3. Set the Texture to Low. However, I do not recommend that.

4. Set the Shadow to Low.

5. Set the number of background people to be zero.

6. Set the resolution to 720p.

.

The following are the less obvious steps to release some CPU pressure:

7. Turn Steam into offline mode.

8. Turn off as many as other programs as possible.

9. In the controller setting, change the controller from the default “XInput” to “XBox 360“. However, I do not recommend that because that would disable the game’s rumble function.

.

After these settings, the game should be able to load Cloud’s headache memory cinematic scenes.

— Me@2023-01-11 12:39:59 AM

.

10. If not, start to repeat pressing the pause button every one second when a scene starts to load.

— Me@2023.01.23 05:17:38 PM

.

.

2023.01.24 Tuesday (c) All rights reserved by ACHK

MSI RTX 3060 Ti VENTUS 2X 8G OCV1 LHR

Visualizing higher dimensions, 2.2 | Remove time from physics, 2

.

Mathematics is local (left brain).

Physics is global (right brain).

— Me@2017-06-22 06:16:59 PM

.

Mathematical processes, i.e. the calculations, are local.

Physical intuitions before a calculation and the interpretations after are global.

— Me@2023-01-13 07:45:24 PM

.

However, in an opposite sense, physics is local and mathematics is global.

— Me@2023-01-14 08:13:17 PM

.

Geometry is global.

Space is what we can see at once.

Dynamics is local.

Time is what we cannot see at once.

— Me@2017-02-07 10:11:34 PM

.

… math is what you get when you remove time from physics.

.

.

2023.01.14 Saturday (c) All rights reserved by ACHK

MSI RTX 3060 VENTUS 2X 12G OC

Meta numbers 2.1 | Zeno’s paradox 5

.

Infinity is not a number. Instead, it is a meta number.

Numbers are for counting things. Infinity cannot be used for counting things. Infinity is for counting natural numbers. It is a number of numbers.

Numbers represent what there are. But infinity cannot do so. Infinity is only meaningful as a potential one.

Infinity and infinitesimal are processes, not states. Numbers are points on the number line. Infinity is not a point, but an arrow pointing to the right.

An infinite set is a set with an infinite number of elements. An infinite set is defined as a set that contains a subset which is as large as the set itself. In other words, the elements of the subset can have one-one correspondence to those of the origin set. The whole can have one-one mapping to the part because it is not a state of finished mappings, but a process.

Processes are meta states. Processes describe how an object changes its states. Processes describe not the states, but the changes.

— Me@2016-06-13 11:43:36 AM

— Me@2023-01-04 10:36:53 PM

.

.

2023.01.05 Thursday (c) All rights reserved by ACHK

Powermaster Optimus Prime


18[.]06[.]2003

Diary: [W]hen I teach taught [E]rg maths, I have had new 
ideas[. B]ut I have no new ideas in research now. 

09[.]07[.]2003

Yesterday, I went to Shatin [T]oys[R][U]s to buy a 
[robot] model for brother. But finally, I saw a 
[PowerMaster] Opimus [P]rime which I wanted to buy when 
I was small. 

Consider [whether to buy or not] for several some 
moment. [And then bought it.]

[.]

At home, we discovered that the small person-robot had 
been stolen. 

[So s]uddenly, I gave up my happiness. 

Luckily, after playing the robot with brother, instead 
of blaming me for not buying a model for him to 
construct, he loved the robot. I was very happy too as 
I discussed "the Transformers generation one" with him. 

.

.

2023.01.03 Tuesday (c) All rights reserved by ACHK

cmu-infix

is

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

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

.

2. Run the command

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

3. Follow the install instructions:

(quicklisp-quickstart:install)

(ql:add-to-init-file)

.

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))
     #I(a+b)))

(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

Direct from Dell

Euler problem 9.2

.

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

g p =
  [ [a, b, c]
    | m <- [2 .. limit],
      n <- [1 .. (m - 1)],
      let a = m ^ 2 - n ^ 2,
      let b = 2 * m * n,
      let c = m ^ 2 + n ^ 2,
      a + b + c == p
  ]
  where
    limit = floor . sqrt . fromIntegral $ p

— based on Haskell official

.

Euclid’s formula is a fundamental formula for generating Pythagorean triples given an arbitrary pair of integers m and n with m > n > 0. The formula states that the integers

\displaystyle{ a=m^{2}-n^{2},\ \,b=2mn,\ \,c=m^{2}+n^{2}}

form a Pythagorean triple. The triple generated by Euclid’s formula is primitive if and only if m and n are coprime and one of them is even. When both m and n are odd, then a, b, and c will be even, and the triple will not be primitive; however, dividing a, b, and c by 2 will yield a primitive triple when m and n are coprime.

Every primitive triple arises (after the exchange of a and b, if a is even) from a unique pair of coprime numbers m, n, one of which is even.

— Wikipedia on Pythagorean triple

— Me@2022-12-10 09:57:27 PM

.

.

2022.12.11 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

ParEdit

.

(autoload 'enable-paredit-mode
  "paredit" "Turn on pseudo-structural editing." t)

(add-hook 'emacs-lisp-mode-hook
      #'enable-paredit-mode)

(add-hook 'eval-expression-minibuffer-setup-hook   
      #'enable-paredit-mode)

(add-hook 'ielm-mode-hook
      #'enable-paredit-mode)

(add-hook 'lisp-mode-hook
      #'enable-paredit-mode)

(add-hook 'lisp-interaction-mode-hook
      #'enable-paredit-mode)

(add-hook 'scheme-mode-hook
      #'enable-paredit-mode)


(add-hook 'slime-repl-mode-hook
      (lambda () (paredit-mode +1)))

(defun override-slime-repl-bindings-with-paredit ()
   (define-key slime-repl-mode-map
     (read-kbd-macro paredit-backward-delete-key) nil))

(add-hook 'slime-repl-mode-hook
      'override-slime-repl-bindings-with-paredit)

.

— Me@2022-11-29 10:03:49 PM

.

.

2022.11.29 Tuesday (c) All rights reserved by ACHK

Euler problem 8.3

Directory[]

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,
                        n,
                        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

Importance, 2.2

Euler problem 8.2

.

.

import Data.Char

max13 lst = max13n lst 0
  where
    max13n lst n | (length lst) < 13 = n
                 | n > take13        = max13n (tail lst) n
                 | otherwise         = max13n (tail lst) take13
      where
        take13 = product (take 13 lst)

str <- readFile "n.txt"

max13 (map (fromIntegral . digitToInt) . concat . lines $ str)

.

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

.

.

2022.11.19 Saturday (c) All rights reserved by ACHK

Pier, 1.2

Euler problem 8.1

.

.

73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450

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)
      contents)))

(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
           (string-to-list
            (remove #\newline
                    (file-get-contents #P"n.txt"))))))

  (loop :for i :from 0 :to (- (length the-digits) 13)
        :maximize (apply #'*
                    (subseq
                      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