> 2021年04月11日信息消化 ### 每天学点算法 #### 康威生命游戏 来自Dropbox的算法题 [Program for Conway’s Game Of Life](https://www.geeksforgeeks.org/program-for-conways-game-of-life/) 最初,有一个网格,其中有一些单元格可能是活的或死的。我们的任务是根据以下规则生成下一代的细胞。 任何少于两个邻居的活细胞都会死亡,就像人口不足造成的一样。 任何有两个或三个活邻居的活细胞都能活到下一代。 任何有三个以上活邻居的活细胞都会死亡,如同人口过剩。 任何有三个活邻居的死细胞都会变成一个活细胞,就像通过繁殖一样。 Initially, there is a grid with some cells which may be alive or dead. Our task to generate the next generation of cells based on the following rules: 1. Any live cell with fewer than two live neighbors dies, as if caused by under population. 2. Any live cell with two or three live neighbors lives on to the next generation. 3. Any live cell with more than three live neighbors dies, as if by overpopulation. 4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. ```python // A simple Java program to implement Game of Life public class GameOfLife { public static void main(String[] args) { int M = 10, N = 10; // Intiliazing the grid. int[][] grid = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; // Displaying the grid System.out.println("Original Generation"); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { if (grid[i][j] == 0) System.out.print("."); else System.out.print("*"); } System.out.println(); } System.out.println(); nextGeneration(grid, M, N); } // Function to print next generation static void nextGeneration(int grid[][], int M, int N) { int[][] future = new int[M][N]; // Loop through every cell for (int l = 1; l < M - 1; l++) { for (int m = 1; m < N - 1; m++) { // finding no Of Neighbours that are alive int aliveNeighbours = 0; for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) aliveNeighbours += grid[l + i][m + j]; // The cell needs to be subtracted from // its neighbours as it was counted before aliveNeighbours -= grid[l][m]; // Implementing the Rules of Life // Cell is lonely and dies if ((grid[l][m] == 1) && (aliveNeighbours < 2)) future[l][m] = 0; // Cell dies due to over population else if ((grid[l][m] == 1) && (aliveNeighbours > 3)) future[l][m] = 0; // A new cell is born else if ((grid[l][m] == 0) && (aliveNeighbours == 3)) future[l][m] = 1; // Remains the same else future[l][m] = grid[l][m]; } } System.out.println("Next Generation"); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { if (future[i][j] == 0) System.out.print("."); else System.out.print("*"); } System.out.println(); } } } ``` ### 其他值得阅读 #### 现代生活的悖论 原文:[The Paradoxes of Modern Life](https://perell.com/note/the-paradoxes-of-modern-life/) 读书的悖论。你所读的书会深刻地改变你 即使你会忘记你所读的绝大多数内容。 > The Paradox of Reading: The books you read will profoundly change you even though you’ll forget the vast majority of what you read. 写作的悖论。伟大的写作看起来毫不费力 但因为思路太过清晰,普通读者并不懂得花了多少时间去完善它们。 > The Paradox of Writing: Great writing looks effortless. But because the ideas are so clear, casual readers don’t appreciate how much time it took to refine them. 创意的悖论。当你的作品看起来很简单的时候,你的作品就完成了,以至于消费者认为他们可以做到,这意味着他们不会欣赏你的努力。 > The Paradox of Creativity: Your work is done when it looks so simple that the consumer thinks they could’ve done it, which means they won’t appreciate how hard you worked. 决策的悖论。最好是选择、承诺、开始,而不是等待最好的选择,所以正确的决定实际上是次优的。 > The Paradox of Decision Making: It’s better to choose, commit, and get started instead of waiting for the best possible option, so the correct decisions are actually suboptimal. 原创性的悖论。许多历史上最伟大的艺术家都是通过模仿别人来找到自己的声音的。我们通过模仿别人,看着自己的独特性随着时间的推移而出现,从而发现自己是谁。 > The Paradox of Originality: Many of history’s greatest artists have found their voice by copying others. We discover who we are by imitating others and watching our uniqueness emerge over time. 新闻的悖论。通过告诉我们关心一切,新闻导致冷漠而不是行动。 > The Paradox of News: By telling us to care about everything, the news leads to apathy instead of action. 具体性的悖论。在互联网时代,当每个人都有谷歌搜索和社交媒体的时候 差异化就是免费的营销。你的目标越具体,你就会为自己创造更多的机会。缩小你的关注点,扩大你的视野。 > The Paradox of Specificity: In the age of the Internet, when everybody has Google search and social media, differentiation is free marketing. The more specific your goal, the more opportunities you’ll create for yourself. Narrow your focus to expand your horizons. 生产力悖论:我们一直在发明一些可以节省时间的东西,但感觉我们的时间比以前更少了。 > The Productivity Paradox: We keep inventing things that save us time, but it feels like we have less time than ever before. 阿比林悖论:叫10个人去吃冰淇淋。如果他们必须就一种口味达成一致,他们每次都会选择巧克力或香草。一群人不会就什么是酷或独特的东西达成一致。既然人们对容易的东西达成一致,那么 "共识 "只是平均的另一种说法。 > The Abilene Paradox: Tell 10 people to get ice cream. If they have to agree on a flavor, they’ll pick chocolate or vanilla every time. Groups of people don’t agree on what’s cool or unique. Since people agree on what’s easy, “consensus” is just another way of saying average. 战略的悖论。帮助你取得异乎寻常的成功的东西 也会增加你失败的几率。例如,用杠杆投资会增加你的风险和回报的机会。 > The Paradox of Strategy: The same things that help you achieve outlier success also increase your chances of outlandish failure. For example, investing with leverage increases your chances of risk and reward. #### 数学年表(mathigon.org) 原文:[Timeline of Mathematics (mathigon.org)](https://mathigon.org/timeline) - **Zeno of Elea** (c. 495 – 430 BCE) 是希腊哲学家,他以著名的悖论而闻名,几个世纪以来一直吸引着数学家。 其中一个例子是运动悖论:想象一下,你想跑100米的比赛。你首先要跑完一半的距离(50米)。但在这之前,你必须跑完1/4的距离(25米)。在跑1/4的距离之前,你必须先跑1/8,1/16...以此类推。这是一个无限量的任务,也就是说,你永远也到不了。 - **王贞仪**(1768—1797),字德卿,生于江宁府上元县(今南京),籍贯安徽天长,清代著名女科学家。 她总结了中国古代数学成就和西方筹算法,写下了当时的科普书,《勾股三角解》《历算简存》《筹算易知》《象数窥余》等等。她是世界上唯一一个从宇宙宏观与微观结合来理 [1] 解“天圆地方”这个概念的。她还弄清楚了日食、月食的形成原理,并写下了《月食解》。“**同是人也,则同是心性**”。 #### 使用简单脚本快速设置Mac开发环境 原文:[Quickly Set Up Your Mac Development Environment Using a Simple Script](https://betterprogramming.pub/quickly-set-up-your-mac-development-environment-using-a-simple-script-276c6b3074b1) 仓库:[*Laptop*](https://github.com/thoughtbot/laptop) ##### macOS tools - [Homebrew](http://brew.sh/) for managing operating system libraries. ##### Unix tools - [Exuberant Ctags](http://ctags.sourceforge.net/) for indexing files for vim tab completion. - [Git](https://git-scm.com/) for version control. - [OpenSSL](https://www.openssl.org/) for transport layer security (TLS). - [RCM](https://github.com/thoughtbot/rcm) for managing company and personal dotfiles. - [The Silver Searcher](https://github.com/ggreer/the_silver_searcher) for finding things in files. - [Tmux](http://tmux.github.io/) for saving project state and switching between projects. - [Watchman](https://facebook.github.io/watchman/) for watching for filesystem events. - [Zsh](http://www.zsh.org/) as your shell. ##### GitHub tools - [Hub](http://hub.github.com/) for interacting with the GitHub API. ##### Image tools - [ImageMagick](http://www.imagemagick.org/) for cropping and resizing images. ##### Testing tools - [Qt 5](http://qt-project.org/) for headless JavaScript testing via [Capybara Webkit](https://github.com/thoughtbot/capybara-webkit). ##### Programming languages, package managers, and configuration - [ASDF](https://github.com/asdf-vm/asdf) for managing programming language versions. - [Bundler](http://bundler.io/) for managing Ruby libraries. - [Node.js](http://nodejs.org/) and [npm](https://www.npmjs.org/), for running apps and installing JavaScript packages. ##### Databases - [Postgres](http://www.postgresql.org/) for storing relational data. - [Redis](http://redis.io/) for storing key-value data. ### 一点收获 - 推上 Sushant Sharma(@Sushant6759)谈到拖延症的根本原因: TL;DR - Give clarity, seek clarity。 - 有人回复很多人在从老板那里领到任务为止不愿意做任何事,是因为工作繁杂无趣。Sushant的回复:**People lack clarity. Clarity causes uncertainty. Uncertainty leads to procrastination.** Procrastination just grows into innate laziness/incompetence. Bosses give clarity and structure to work. [link](https://twitter.com/Sushant6759/status/1380472514082533380) - 我们拥有一种不论动物还是计算机都不具备的心智技术,即将语言的各个部分组合起来并从中构筑更宏大意义的能力。--David Adger [语言与心智:普遍语法是否存在?](https://new.qq.com/rain/a/20210409A0E35T00)