/images/avatar.jpeg

使用简单算法两小时实现猎杀乌姆帕斯(Hunt the Wumpus)Python小游戏

“Hunt the Wumpus” 是什么?

引用wiki百科:

Hunt the Wumpus是Gregory Yob于 1973 年开发的一款基于文本的 冒险游戏。在游戏中,玩家在一系列连接的洞穴中穿行,这些洞穴排列为十二面体的顶点,他们狩猎一个名叫 Wumpus 的怪物。 在回合制游戏中有玩家试图避免致命的无底洞和“超级蝙蝠”,将移动他们周围的洞穴系统; 目标是通过洞穴发射他们的“弯曲箭”之一以杀死Wumpus。

Linux 磁盘挂载

查看磁盘

sudo fdisk -l
sudo lsblk
sudo mkfs -t ext4 /dev/mmcblk1 # 格式化
sudo mount /dev/mmcblk1 /home/root/data/

卸载挂载

sudo umount /dev/mmcblk1

自动挂载

sudo blkid # 获取UUID
sudo vim /etc/fstab
UUID=6b7eaf8d-0b66-6e26-bdff-fa63f7dd1126 /u01 ext4 defaults 1 1

leetcode-350-两个数组的交集 II

题目

给定两个数组,编写一个函数来计算它们的交集。

示例 1:

输入:nums1 = [1,2,2,1], nums2 = [2,2]
输出:[2,2]
示例 2:

输入:nums1 = [4,9,5], nums2 = [9,4,9,8,4]
输出:[4,9]
 

说明:

输出结果中每个元素出现的次数,应与元素在两个数组中出现次数的最小值一致。
我们可以不考虑输出结果的顺序。
进阶:

如果给定的数组已经排好序呢?你将如何优化你的算法?
如果 nums1 的大小比 nums2 小很多,哪种方法更优?
如果 nums2 的元素存储在磁盘上,内存是有限的,并且你不能一次加载所有的元素到内存中,你该怎么办?


来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/intersection-of-two-arrays-ii
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

题解 1

class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        result = []
        for i2, n2 in enumerate(nums2):
            for i1, n1 in enumerate(nums1):
                if n1 == n2:
                    result.append(n2)
                    nums1.pop(i1)
                    break
       return result          

题解2

class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        result = []
        len_num1 = len(nums1)
        len_num2 = len(nums2)
        if len_num1 >= len_num2:
            for i2, n2 in enumerate(nums2):
                for i1, n1 in enumerate(nums1):
                    if n1 == n2:
                        result.append(n2)
                        nums1.pop(i1)
                        break
        else:
            for i1, n1 in enumerate(nums1):
                for i2, n2 in enumerate(nums2):
                    if n1 == n2:
                        result.append(n2)
                        nums2.pop(i2)
                        break
        return result  

使用docker模拟双机环境测试mysql双机互为主备

MariaDB双主模式测试

1. 环境准备

创建目录 mkdir conf conf2 data data2 log log2 创建 MariaDB 配置文件 touch conf/my.cnf conf2/my.cnf conf/my.cnf文件

# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/

#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
[mysqld]
server-id=1
log-bin=mysql-bin
binlog_format = mixed
binlog-do-db=event_analysis 
binlog-ignore-db =mysql
binlog-ignore-db =information_schema
binlog-ignore-db =performance_schema

replicate-do-db=event_analysis
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
read-only=0

relay_log=mysqld-relay-bin
log-slave-updates=ON
auto-increment-increment = 2
auto-increment-offset = 1

conf/my.cnf文件

Linux下检测某个ip端口的连通状态

举个例子,要测试的 ip+port: 192.168.0.100:8080

  1. 使用 telnet 命令

    telnet 192.168.0.100 8080

    连通成功:

    Trying 192.168.0.100...
    Connected to 192.168.0.100.
    Escape character is '^]'.
    Connection closed by foreign host.

    连通失败:

    rying 192.168.0.100...
    telnet: Unable to connect to remote host: Connection refused
  2. 使用 nc 命令