Thursday, June 29, 2023

implement add with + operator with racket

 #lang racket


; implement add without + operator


(define add

  (λ (n m)

    (cond

      ((zero? m) n)

      (else (add1

            (add n (sub1

                    m)))))))


One thing I want to notice is that add1 and sub1 are not what I defined myself.

racket basic

 #lang racket


; define a constant

(define myval 3.14)


; function without param

(define myfunc

  (λ ()

    (+ 3 4)))


; call function

(myfunc)


; function with param(which is one formal)

(define myfunc-mul-two

  (λ (x)

    (* 2 x)))


(myfunc-mul-two 4)


; outer function calls inner function

(define double-result-of-f

  (λ (f)

    (λ (z)

      (* 2 (f z)))))


(define add3

  (λ (x)

    (+ 3 x)))


((double-result-of-f add3) 4)


Thursday, June 22, 2023

binary search alternative

#include <iostream>

#include <vector>


using namespace std;


int main()

{

    int array[] = { 1,3,3,4,5,5,6,9,10,12,12,15 };

    int n = sizeof(array) / sizeof(int);

    int k = 0;

    int x = 3;


    for (int b = n / 2; b >= 1; b /= 2)

    {

        while (k + b < n && array[k + b] <= x)

        {

            k += b;

        }

    }

    

    if (array[k] == x)

    {

        int a = 10;

    }

}


remainder in racket

 #lang racket


(define remainder

  (λ (x y)

    (cond

      ((< x y) x)

      (else (remainder (- x y) y)))))

Wednesday, June 21, 2023

unix tree

minnie.tuhs.org/cgi-bin/utree.pl

which on linux

which is used to locate a command. which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in a strictly POSIX-conformant shell. It does this by searching the PATH for executable files matching the names of the arguments. It does not follow symbolic links.

Wednesday, June 14, 2023

stdc++

#include <bits/stdc++.h>
using namespace std;
int main()
{
}

stdc++.h allows us to include the entire standard library so I don't need to include each separate header files such as vector, iostream, algorithm and so on.

but it is only for competitive programming not for a professional developer.

use gdbm on ubuntu

First thing you have to do is checking whether gdbm is installed on your system or not.

normally it is installed on /usr/include


find /usr/include *dbm* is the command you can use.


even though gdbm is installed on your machine, you might need to install gdbm_compat if you use ndbm interface.


sudo apt-get install apt-file

apt-file update

apt-file search ndbm.h


then you will see packages that you should install on your machine.


Tuesday, June 6, 2023

안다는 것

子曰 由, 誨女知之乎. 知之爲知之, 不之爲不知, 是知也

Sunday, June 4, 2023

List symbols from object file on linux

 


search all of the symbols in a program. if you can see any of functions beginning of aio_ then for sure it uses async I/O.

Task in UnrealEngine

 https://www.youtube.com/watch?v=1lBadANnJaw