20240611

The work was hard…

ping

$ ping nippo.huyfififi.com -c 5
PING nippo.huyfififi.com (172.67.175.186): 56 data bytes
64 bytes from 172.67.175.186: icmp_seq=0 ttl=55 time=19.744 ms
64 bytes from 172.67.175.186: icmp_seq=1 ttl=55 time=19.450 ms
64 bytes from 172.67.175.186: icmp_seq=2 ttl=55 time=21.113 ms
64 bytes from 172.67.175.186: icmp_seq=3 ttl=55 time=19.446 ms
64 bytes from 172.67.175.186: icmp_seq=4 ttl=55 time=20.897 ms

--- nippo.huyfififi.com ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 19.446/20.130/21.113/0.726 ms

I use ping to check the internet connection or server availability, but I didn't know how it works.

$ man ping
...
NAME         Stop after sending (and receiving) count ECHO_RESPONSE packets.  If this option is not specified, ping will operate until
     ping – send ICMP ECHO_REQUEST packets to network hostsonjunction with ping sweeps, each sweep will consist of count packets.
...

What is ICMP then?

CloudFlare: What is the Internet Control Message Protocol (ICMP)?

The Internet Control Message Protocol (ICMP) is a network layer protocol used by network devices to diagnose network communication issues.

ICMP is mainly used to determine whether or not data is reaching its intended destination in a timely manner.

Commonly, the ICMP protocol is used on network devices, such as routers.

So, ICMP is a network layer protocol. When sending ICMP packets from my computer to a server (domain -> IP translation is involved), the server replies packages back to my computer ('s IP address). The logic is in OS, so without explicitly writing logic for it with Nginx or Apache, the protocol works.

The primary purpose of ICMP is for error reporting. When two devices connect over the Internet, the ICMP generates errors to share with the sending device in the event that any of the data did not get to its intended destination. For example, if a packet of data is too large for a router, the router will drop the packet and send an ICMP message back to the original source for the data.

A secondary use of ICMP protocol is to perform network diagnostics; the commonly used terminal utilities traceroute and ping both operate using ICMP. The traceroute utility is used to display the routing path between two Internet devices. The routing path is the actual physical path of connected routers that a request must pass through before it reaches its destination. The journey between one router and another is known as a ‘hop,’ and a traceroute also reports the time required for each hop along the way. This can be useful for determining sources of network delay.

I was not aware of these use cases. I'm not a network engineer, so I feel that the knowledge won't stay in my brain long. Maybe I should check traceroute tomorrow?

1559B. Mocha and Red and Blue

Managed to make it work by a greedy approach, but the code is messy, and it was very difficult to spot a bug. I'll check the editorial tomorrow.

updated: 20240612

Codeforces Round #738 Editorial

It seems my approach is good, and with my current knowledge, extracing some common operations can be done, but it does not affect the solution drastically.

def solve(n: int, s: str) -> str:
    res: str = ""

    prev_i: int = -1
    for i in range(n):
        if s[i] == "?":
            continue
        elif s[i] == "B":
            if (i - prev_i) % 2 == 1:
                res += "BR" * ((i - prev_i) // 2) + "B"
            else:
                res += "RB" * ((i - prev_i) // 2)
            prev_i = i
        elif s[i] == "R":
            if (i - prev_i) % 2 == 1:
                res += "RB" * ((i - prev_i) // 2) + "R"
            else:
                res += "BR" * ((i - prev_i) // 2)
            prev_i = i

    if prev_i != n - 1:
        if len(res) == 0:
            if (n - prev_i) % 2 == 0:
                res = "B" + "RB" * ((n - 1 - prev_i) // 2)
            else:
                res = "BR" * ((n - 1 - prev_i) // 2)
        elif res[-1] == "B":
            if (n - prev_i) % 2 == 0:
                res += "R" + "BR" * ((n - 1 - prev_i) // 2)
            else:
                res += "RB" * ((n - 1 - prev_i) // 2)
        else:
            if (n - prev_i) % 2 == 0:
                res += "B" + "RB" * ((n - 1 - prev_i) // 2)
            else:
                res += "BR" * ((n - 1 - prev_i) // 2)

    return res



for _ in range(int(input())):
    n = int(input())
    s = input()
    print(solve(n, s))

Sushi 1000 Avocado 200 Lunchable 300 Bagel 300

Total 1800 kcal

*vomiting sound*

6k run pull ups


TODO:


index 20240610 20240612