B station video link
Have to joke, nuggets this article edit is too difficult to use…
Hi guys.
Let’s start with this chapter and look at the title.
The original:
Volume 1 square field
Wei Liuhui note
Tang Dynasty discussed the doctor line taishi order on the light car duwei minister Li Chunfeng and other rescript
Kata [with Oda Domain]
The title of the first volume of The Nine Chapters on Suanshu is “Fang Tian”. According to the annotation “The domain is defined by imperial field”, it shows that the content of the volume of Fang Tian is used to define the scope of fields. Range is the area and perimeter, so it can be seen that this volume of square fields should mainly involve the calculation of area and length.
The original:
Today you have tian Guang fifteen steps, from sixteen steps [1]. Ask for field geometry?
The answer: one mu.
And tien, twelve steps, from fourteen. Ask for field geometry?
One hundred and sixty-eight steps. [Figure 14, Guang 12]
Surveying of land
Art yue: wide from the number of steps multiplied product steps.
This product is called the power of the field.
[Minister Chun feng, etc., hereby press: Step by CSG from multiplied product, note wide cloud from the multiplication of power, view, pay attention to the product with power righteousness. Push Daniel, solid when not. Then? The power is on in the name of a single cloth, is known as modal inhabit. Live up to the name, all different. Both are to the same, I will not. Today to every word power according to widely from one of the party; destroyed step for the number of all product. By cloud multiplication product step, that is, the number of plaintext. Note cloud that is power, all good product step of the original meaning. This note before the cloud product is tian power, in principle makes sense.
Divide by 240 steps with mu method, namely mu number. One hundred acres are an hectare.
[Minister Chun feng, etc., hereby press: This the end, so, for a musical, mu, 2. No longer if the operation, from now on. An acre field, wide fifteen steps, to drain out, make for 15 lines, namely each step and step from 16. Cross and cut, make for 16 rows, the widespread step and step from 15 in a row. This is from the step of thin cross-sectional, for their respective parties. Every two hundred and forty steps. Steps for an acre of land is the same. In this way, that is, from the multiplication of the product step, test yi. Two hundred and forty steps, acres of law also. Hundreds of acres, ares law also. So in addition to, get.
Today there is tian Guangyi li [3], from one li. Ask for field geometry?
Answer: three ares seventy-five mu.
Tian Guang two li, from three li. Ask for field geometry?
The answer was: twenty-two hectares, fifty acres.
His entire
Art yue: wide get product from li number in multiply. Multiply it by 375, which is the number of acres.
There are three hectares of land in the square li, so by multiplying them you get the number of acres.
Note:
[1] Wide: wide. From: long.
[2] Liu Hui’s annotated drawings have been lost, and the complementary drawings in Li Huang’s Theory of Nine Chapters’ Fine Sketches on Arithmetic have been found.
[3] 1 li =300 steps.
We can see that square fields and litian fields, these two types of problems are essentially the problem of finding square field area, but there are differences in unit conversion. That’s why I put these two parts together in one chapter.
Square field part.
As there are many units involved, there is a length unit “step” and three area units “step”, “mu” and “inclination”.
So let’s figure out what the unit conversion is. The unit of area “step”, according to the original text, is the square area with one step in length and one step in width. To modern people’s habits, it should be called “square step”. In order to distinguish, the unit of area “step” is also called “square step”. Since this is the beginning of the book, we introduce conversion relations. According to the fang Tian shu mentioned “to mu method 240 steps divided, that is, mu number. A hundred acres is an hour.” , can get the unit conversion relationship: 1 mu =240 square steps, 1 ares =100 mu.
Next we look at the area method, the original text “Fang Tian shu yue: from the number of steps multiplied product steps.” , the number of steps of width multiplied by the number of steps of length is the (square) number of steps of area. (In fact, it is the basic multiplication that I learned at the beginning of primary school, plus an area unit conversion.)
The reedy part.
Here said “li tian”, according to my personal understanding, is the length of “li” as a unit (square) field. Here also involves a unit of length “li” and an area unit “li”, similarly the area unit “li” should be called “square li”.
According to “li Tian shu yue: from the miles multiplied by the product in. Multiply it by three hundred and seventy-five, which is the number of acres.” It is easy to understand that the number of miles of width multiplied by the number of miles of length yields the number of miles of area squared. It tells us that if you multiply square by 375 you get acres, but it doesn’t tell us why, it doesn’t tell us in the notes.
Here involves a unit conversion relationship of hidden knowledge, the original text did not mention the “li” and “step” conversion, should be 1 li =300 steps. Combined with the conversion relationship explained in Fang Tian, 1 square li =300 steps *300 steps = 90,000 square steps =90000/240 mu =375 mu, so we get the conversion relationship between “square li” and “mu”. (I guess the annotation does not mention the conversion relation, because the annotation is also 1 li =300 steps, which is the same as the original text, so there will be no misunderstanding.)
After understanding “area = width * length” and conversion relation of length unit and area unit, it is easy to understand the four questions in the original text:
(1) There are fifteen paces in the field, from sixteen. Ask for field geometry? The answer: one mu.
15 x 16 = 240 square steps = 1 acre
And tian-guang twelve steps, from fourteen steps. Ask for field geometry? One hundred and sixty-eight steps.
12 times 14 is 168 square steps
(Well, this question doesn’t even convert units.)
(3) Now there is one li tian Guang, from one li. Ask for field geometry? Answer: three ares seventy-five mu.
1 * 1 = 1 sq. li * 375 mu/sq. li = (375 mu)/(100 mu/ares) = 3 ares 75 mu
(4) There is a field of two li, from three li. Ask for field geometry? The answer was: twenty-two hectares, fifty acres.
2 * 3 = 6 sq. li * 375 mu/sq. li = (2250 mu)/(100 mu/ares) = 22 ares 50 mu
Although these questions are very simple after understanding the unit conversion relationship, based on our existing knowledge system. However, there is no denying that this is really based on the practical application of the problem. So when we also in line with the mentality of solving practical problems, to use the code to achieve the “shu” in the Nine Chapters of suanshu, maybe there will be different harvest.
Since square field and field field are both integer multiplication related problems, I’m going to use the same function to implement the calculations involved in both parts.
Obviously, the input required is the length and width of the field, and the return value is the area of the field.
Let me describe my analysis process:
Core calculation is “area = length * width”, the implementation is very simple, more complex is the need to consider the unit conversion problem. Input needs to determine the unit of “li” or “step”; The output needs to be converted to the form of “XX hectares XX square steps”.
We still use JSON as input and output.
Input: contains four fields {length miles, length steps, width miles, width steps}.
Output: contains three fields {area acres, area acres, area square steps}.
First the length and width of the input unified to “step” as a unit, calculated to “square step” as a unit of area, and then converted to “XX acres XX square step” in the form.
Calculation process:
Total length steps = Length miles * 300 + Length steps
Total width steps = width miles * 300 + width steps
Total area square steps = Total length steps x Total width steps
Area = (total area square steps/(240 * 100)) is rounded
Area mu = ((total area square steps % (240 * 100)) / 240) is rounded
Area square steps = (Total area square steps % (240 * 100)) % 240
[Note] : “%” is the remainder of the operation, A%B is to find the remainder of A divided by B.
It clarifies the calculation process, but also needs to think about error handling to improve the robustness of the code. I’m just going to multiply integers, so I don’t have to worry about entering decimals. We need to calculate the land area, so there are constraints, length and width must be positive integers, that is, the following conditions need to be met at the same time:
Steps length mileage < 0 | | length < 0 | | width size < 0 | | steps width < 0 is false
The length of the mileage > 0 | | steps length > 0 is true
The width size > 0 | | steps width > 0 is true
【 note 】 : “&” said and logical relations, “| |” said or logical relationship, “!” Represents a nonlogical relationship.
Next, translate this calculation into code.
Input: {length miles, length steps, width miles, width steps}
Output: {area acres, area acres, area square steps}
Code:
Function chOne01(input){// Input in json format: lenLi, lenStep, widStep, widStep let lenLi = input. LenLi; // Input in json format: lenLi, lenStep, widStep let lenLi = input. let lenStep = input.lenStep; let widLi = input.widLi; let widStep = input.widStep; If (lenLi < 0 | | lenStep < 0 | | widLi < 0 | | widStep < 0) {/ / filter error input return {" code ":" 001 ", "MSG" : "can't negative aspect, please input again"}; } if(! (lenLi > 0 | | lenStep > 0)) {return {" code ":" 002 ", "MSG" : "length cannot be 0, please input again"}; } if(! (widLi > 0 | | widStep > 0)) {return {" code ":" 003 ", "MSG" : "width is not 0, please input again"}; } length = lenLi * 300 + lenStep; Width = widLi * 300 + widStep; Area = length * width; Let qing = math. floor(area/(100 * 240)); let qing = math. floor(area/(100 * 240)); // Let mu = math. floor((area % (100 * 240)) / 240); Let step = (area % (100 * 240)) % 240; / / steps calculation area of square return {" the qing ": the qing," mu ": mu," step ": step}; // Return result in JSON format}Copy the code
Calling code and running results:
let input = {"lenLi":1,"lenStep":1,"widLi":1,"widStep":1}; console.log(chOne01(input)); PS D:\WorkSpace\JSWork\test> node "D:\WorkSpace\JSWork\test \ chone01.js" {qing: 3, mu: 77, step: 121}Copy the code