Shadow

Euler problem 14.1.1

.

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

(defun col (n c)
  (cond ((= n 1) c)     
        ((evenp n) (col (/ n 2) (1+ c)))
        ('t (col (1+ (* 3 n)) (1+ c)))))

(defun max-item (lst)
  (loop :for item :in lst
        :maximize item))

(defun e14 ()
  (let* ((c-lst
           (mapcar #'(lambda (x)
                       (col x 1))
                   (range 1000001 :min 1)))
         (max-len
           (max-item c-lst))
         (max-index
           (1+ (position max-len c-lst))))    
    (list max-index max-len)))

(time (e14))

;; Evaluation took:
;; 1.084 seconds of real time
  
;; (837799 525)

— Me@2023-07-03 12:33:40 AM

.

.

2023.07.03 Monday (c) All rights reserved by ACHK

Emacs theme

(custom-set-variables
 '(cua-mode t nil (cua-base))
 '(custom-enabled-themes '(leuven))
 '(global-display-line-numbers-mode t))

(custom-set-faces
 '(default ((t (:family "DejaVu Sans Mono"
                        :foundry "PfEd"
                        :slant normal
                        :weight normal
                        :height 120
                        :width normal)))))

(prefer-coding-system 'utf-8)

(global-visual-line-mode t)

— Me@2023-06-18 01:27:37 PM

.

.

2023.06.18 Sunday (c) All rights reserved by ACHK

Euler problem 13.2

e13 :: IO ()
e13 = do
  str <- readFile "n.txt"
  let sList = lines str
      nList = map (\x -> read x :: Integer) sList
   in print $ take 10 . show . sum $ nList

— Me@2023-06-06 11:37:32 AM

.

.

2023.06.06 Tuesday (c) All rights reserved by ACHK

Quicklisp, 2

Euler problem 13

.

To run the following code, you have to install the Quicklisp library manager by following the steps in my blog post titled cmu-infix.

(ql:quickload "str")

(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-list (file-get-contents #P"n.txt")))
  (subseq
   (prin1-to-string
    (reduce
     #'+
     (mapcar
      #'parse-integer
      (butlast (str:split #\newline the-list)))))
   0 10))

— Me@2023-05-26 12:16:50 PM

.

.

2023.05.26 Friday (c) All rights reserved by ACHK

VirtualBox Start

In KDE, when a Virtualbox virtual machine is turned on, sometimes, both the guest OS and the host OS would capture the Super key at the same time. In order to avoid that, use the following steps:

1. Right-click the VirtualBox title bar

2. Choose:

More Actions
\to Special Window Settings
\to Ignore Global Shortcuts (in Appearance and Fixes)
\to Force \to Yes

— Me@2023-05-17 07:52:55 PM

.

.

2023.05.19 Friday (c) All rights reserved by ACHK

Euler problem 12.2

primes :: [Integer]
primes = 2 : filter (null . tail . primeFactors) [3, 5 ..]

primeFactors :: Integer -> [Integer]
primeFactors n = factor n primes
  where
    factor n (p : ps)
      | p * p > n = [n]
      | n `mod` p == 0 = p : factor (n `div` p) (p : ps)
      | otherwise = factor n ps

groupFactors :: [Integer] -> [[Integer]]
groupFactors = gf []
  where
    gf acc lst
      | null lst = reverse acc
      | null acc = gf [[p,1]] ps
      --
      | p == head (head acc) =
        gf ([p, head (tail (head acc)) + 1]:tail acc) ps
      --  
      | otherwise = gf ([p,1]:acc) ps
      where
        p = head lst
        ps = tail lst
        
nDiv :: Integer -> Integer
nDiv n = product (map ((1+) . head . tail)
                  (groupFactors (primeFactors n)))

fm :: Integer -> Integer -> Integer
fm m n
  | triDiv n > m = n*(n+1) `div` 2
  | otherwise = fm m (n+1)
  where
    triDiv n
      | even n = nDiv (n `div` 2)*nDiv (n+1)
      | otherwise = nDiv n*nDiv ((n+1) `div` 2)

λ> :set +s
λ> fm 500 1
76576500
(0.20 secs, 199,313,728 bytes)
λ> 

— Me@2023-05-04 09:51:19 AM

.

.

2023.05.04 Thursday (c) All rights reserved by ACHK

History 5

bambax on June 17, 2018

Not just music history, but history in general.

History told forwards is superstition: trying to show that what came after was inevitable, when in fact it was one future among an infinite number of different possible futures.

History told backwards makes sense: look for the seeds of post events, in the past.

However the human mind loves nothing more than causation; we see cause and effect everywhere even where it’s not, we like “stories”, we don’t understand, don’t believe in, and outright reject chance.

— We Should Teach Music History Backwards

— Hacker News

.

.

2023.04.01 Saturday ACHK

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