Exactly how it is done depends on the language/implementation, but generally you would read the csv into a structure (using a csv library) that could be described as an array of
n records like this:
Code:
tbl = [
{a0,b0,c0,d0,e0,f0},
{a1,b1,c1,d1,e1,f1},
...,
{an,bn,cn,dn,en,fn}
]
Since it is not looking for an exact match on 1 field, you probably will have to tell it how to find the correct row. A simple compare function like this could be defined:
Code:
compare(A,B,Z)
{
return ((Z >= A) && (Z < B))
}
Most of these scripting languages have search/find functions built into their objects, and the most you would have to do is define a compare function and pass it to the search function along with the search value, something like this:
tbl.find(Z, compare)
Under the hood of find():
To find the correct row, the first instinct might be to tell the program to start at the first row and check each one until compare is true. This works, but there are faster approaches. Assume a case where the correct row is the very last one, then it would take
n compare calls to find it. The built in find() will probably use a binary search, where for an array size
n, the first check will be at tbl[n/2]. If compare is false, the next check will be at tbl[n/4] or tbl[(n - n/2) / 2], depending on whether Z < A or Z > B. This approach would at worst take log
2(n) compare calls.
From there, the program would get 1 of the other 4 values, depending on filing status. This could also be added to the compare function so a single value would be returned (as opposed to the whole row) in one fell swoop. Technically, this would take log
2(n) + 4 compare calls, but most people still call it log
2(n).
The source comes from the HTML version of the 1040:
http://www.irs.gov/instructions/i1040gi/ar02.html
I just used text replacement to convert the html table to a csv.
Connect With Us