Home  >  Article  >  System Tutorial  >  Ant puzzle ~ interesting thinking exercise

Ant puzzle ~ interesting thinking exercise

王林
王林forward
2024-03-16 08:10:031065browse

Ant puzzle ~ interesting thinking exercise

Are algorithms important in today’s work?

Nowadays, computer science has developed to a relatively advanced stage. It is impossible for one person to learn all the algorithms. When solving specific problems, sometimes it is more necessary to analyze the problem first, then consult the information, think about the design, or even Discuss and finally solve it in a practical way.
Algorithms also have many different branches, which meet different needs and have different scopes of application. The usual "communication" circles are also different, such as "graphics algorithms", "artificial intelligence algorithms", and "distributed algorithms". The basic principles under different branches are also different. The concepts and ways of thinking are different, and the "common sense" needed to analyze problems and understand other people's methods is also different. Under each branch, a large number of new papers and new methods appear every year, which are constantly accompanied by new needs and new application scenarios. Therefore, it is a better choice to master the basic methods and concepts and study the relevant algorithms in depth according to your needs.

Compared with being proficient in certain specific algorithms, it is more important to develop good thinking and problem-solving abilities through studying algorithms. Algorithms are valuable, and thinking is more valuable.
question:

There are three ants sitting in the triangle. All ants randomly pick a direction and start moving along the edge of the triangle. What is the probability that two ants collide?

answer:

The triangle has three vertices, each vertex connects two sides, each ant has two options, and each option has a 1/2 probability.

There are two situations. When all ants move in the same direction, the ants will not collide

clockwise

The probability that all ants move in the same clockwise direction is 1/2 * 1/2 * 1/2 = 1/8

Counterclockwise

The probability that all ants move in the same counterclockwise direction is 1/2 * 1/2 * 1/2 = 1/8

The total probability of no collision is 1/8 1/8 = 1/4

So, the collision probability becomes: 1 - 1/4 = 3/4

Summarize

Algorithm is one of the most important cornerstones in the field of computer science, but it has been ignored by some domestic programmers. Many students have a misunderstanding when they see the variety of programming languages ​​required by some companies when recruiting. They think that learning computers means learning various programming languages, or that learning the latest languages, technologies, and standards is the best way to pave the way. In fact, everyone has been misled by these companies. Although programming language should be learned, it is more important to learn computer algorithms and theories, because computer languages ​​and development platforms are changing with each passing day, but what remains the same are those algorithms and theories, such as data structures, algorithms, Compilation principles, computer architecture, relational database principles, etc. On the "Kaifu Student Network", a student vividly compared these basic courses to "internal strength" and the new language, technology, and standards to "external strength." People who follow fashion all day long only know moves in the end. Without skill, it is impossible to become a master.

The above is the detailed content of Ant puzzle ~ interesting thinking exercise. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete