Off-by-one error#Fencepost error

The term fence post problem describes a logic problem of indexing. A fence post problem is always there, where some uncertainty as to whether a single figure represents a space or a point, or whether including a distance one, both, or neither of the end members. A fencepost error is a special case of an off-by -one errors. Often, they are encountered in the data processing.

Example

Question: If one wants to build a 30 m long straight fence and the fence posts should be 3 m apart, how many posts do you need?

The intuitive answer is " 10 piles " is wrong, because the fence does have 10 segments, but 11 piles. Beginning and end of the fence ever need a stake.

The reverse error occurs if the number is given piles and erroneously assumed, the length of the fence would result from the pile spacing multiplied by the number of piles. From 11 piles but not 33 m long fence, but only a 30 m long results.

History

One of the earliest examples of a fencepost error happened at the calendar reform of Gaius Julius Caesar. Caesar had the circuit placed in every fourth year, the priests understood this, however by the inclusive counting ( see below) as a circuit every three years.

Fencepost problems in computer science

In computer science, where the term of the fencepost problem most commonly use is, similar problems occur. These belong to two main groups:

Example: What distance have element 20 and element 30 in a list?

  • Count including both limits ( " Inclusive Count" ): 11
  • Count including 20, but without 30: 10
  • Without counting 20, but including 30: 10
  • Counting without both limits ( the intervening elements ): 9

Related problems

The historical inclusive counting

Distances, distances and periods were counted from antiquity to post-medieval period into after the " inclusive counting ". In this counting, both the initial and the end element of a sequence is counted. The starting point is defined as "1" and incremented therefrom. The distance 0 is thus the numerical value " 1" is assigned, the distance 1 is the value " 2 ", etc. The values ​​for distances, time periods, etc. are therefore always greater by 1 than by today's mathematical convention for Inclusive counting. Historically, the inclusive counting has its cause in the fact that the concept of the number zero was known until the introduction of the Arabic-Indic numbers from the 13th century in Europe.

From the inclusive count stirred for instance ago the custom of " in a week " in addition to saying " seven days " and " in eight days ," even though everyone knows that a week has seven days. The actual day is counted in the census included:

Another example of the inclusive count are the names of musical intervals:

That the one used in the music name of each interval of 1 is too large, it provides, inter alia, the addition of intervals. A fourth and a fifth have a combined octave. But 4 5 is not 8 - rather is 3 4 = 7

Calendar

Year zero

The Christian era knows no year zero, but goes from year 1 BC directly into year 1 AD on. In the astronomical chronology, however, the year 1 BC is counted as year zero.

Centuries

There was no " zeroth century ". The 1st century lasted from January 1, 1 CE to December 31, 100 AD A century always includes the hundred years ending with the corresponding full year. According to the period from 1 January 1901 to 31 December 2000 is referred to as the 20th century and the 21st century began on January 1, 2001.

In Italian, in addition to the normal designation of the centuries ( "XX secolo " ) also colloquially named the centuries so that " Novecento " (literally: nine hundred ) denotes the period of 1900-1999. However, this is only possible for centuries from the year 1100. In English there is the possibility of the period to denote " 1900s " from 1900 to 1999 in a similar manner. At the last turn of the millennium, many celebrated in the German-speaking area of the millennium already 1999/2000 instead of 2000/2001.

Anniversaries

Anniversaries (eg, birthdays) celebrate the completion and not the beginning of the years indicated. A person who is celebrating his 18th birthday, so does not begin on that day be 18 years - rather, he has lived a full 18 years, beginning his 19th year.

The day of birth of a person is so to speak, be " 0 Birthday ", similar to the marking 0 on a centimeter scale.

Birthday: Birth 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18                     \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / Age: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 In some cultures (eg China) is, however, different: the day of birth is the " first Birthday ".

Find the center

Starting the counting by 1, then the center can not equal to half the number of elements. For example, a scale 1 to 10 is given. 5 is in this case not in the center of the scale, but below. The actual center is 5.5:

1 2 3 4 5 6 7 8 9 10           ^ middle Also, the following may seem counter-intuitive or " surprise ": Of the five elements, numbered 1 2 3 4 5, the middle element is the number 3 - even though half of 5 is known to be 2 ½.

On a scale from 0 to 10, however, has 11 indexes and the center is 5:

0 1 2 3 4 5 6 7 8 9 10            ^ middle The reason for this is the same fence post problem as described in the above. The upper scale has indexes 1 through 10 These are considered as points. In order for the scale describes only a length ( distance, distance between start and end) of 9, because 10-1 = 9 your middle therefore is half of 9, starting from the index 1: 1 ( 9/2) = 5.5.

The lower scale with the indices from 0 to 10, however, describes a length of 10 and its center is at 0 ( 10/2) = 5

Floors

In the German -speaking area of the 1st floor is the first spiked floor, in contrast to the ground floor. In many cultures, however, the ground floor has the number 1 Again, it comes to a fence post problem: Floor 3 or three flights of stairs? When are numbered in Germany instead of storeys levels, then it is often started on the ground floor counting at 1.

For three or three?

"? For three or three " is a famous quote from the action movie Lethal Weapon series. Here is the problem, if you want to start jointly planned, surprising action after you have counted to three or exactly when it says three.

  • Mathematical Logic
500899
de