|
VB arrays have an 0th element by default. It's just ignored/skipped by many programmers. The confusion of caused that the DIM statement doesn't actually give the dimension (as the equivalent in C/C++/C# does), but instead the upper limit.
Truth,
James
|
|
|
|
|
I'm with Greg on that one!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Your option 1 is precisely how I interpret the question. I could understand forgetting to start the index at 0 (getting some of #2), but printing the first index regardless is incorrect.
|
|
|
|
|
I don't think it's a question of English. "Every 10th number" is clear, but where to start means making an assumption. If stated in another language that I can read, I would feel the same way.
|
|
|
|
|
Greg Utas wrote: but where to start means making an assumption. I am not making any assumption. I am starting from the beginning of the array.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: a[0], a[10], a[20]... which are places 1st, 11th, 21st Don't you mean zeroth, tenth, etc?
|
|
|
|
|
From what base?
Yet another poorly-worded spec. You definitely need to know which element to start with. It should at least be something along the lines of, "starting with element n, select every mth element".
To cover the variants I can think of at the moment, I would write a method which takes three parameters: the index of the first element to select, how many elements to select from that position, and the number of elements to skip to get to the next element to select.
modified 12-Mar-20 19:46pm.
|
|
|
|
|
The ID of the first element of the array is irrelevant.
If you have an array that starts with an element identified as a(47), then the tenth element is a(56).
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
This explanation makes sense also for a protozoon like me.
It does not solve my Problem, but it answers my question
modified 19-Jan-21 21:04pm.
|
|
|
|
|
That's why people keep hiring me to do things with the English language, rather than C#.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
So you consider element 47 not as the first one.
The ninth element is #55, the eigth is #54... the 1st is #48, the 0th is #47. Fair enough, from a programmer point of view. Your grandmother might disaggree. But as we all know: Today, computer guys rule the world.
In sports games, we still rank the competitors as "1st place", "2nd place" and "3rd place". As soon as computer guys succeed in taking over sports, it most surelu will be changed to "0th place", "1st place" and "2nd place"...
|
|
|
|
|
Member 7989122 wrote: So you consider element 47 not as the first one. I think you must have misread. Element a(47) is the first element.
Treat the "a(47)" as an identifier (which is precisely what it is) and not as something to do with its cardinality.
It's like you can have variables named 'a', 'b', and 'c', but those names/identifiers have nothing to do with the order they're used in, their importance, etc.
"An array element by any other name would still be in the same cardinal position" -- Wm. Shakespeare, who predicted the existence of arrays centuries before computers were built.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
I agree.
Let's say you're instructed to "get on the highway headed east and drive to the second exit". You don't count the interchange you enter at. Nor do you consider where "exit 2" might be -- you may have entered at exit 2, or it may be to your west.
So "every tenth" has nothing to with how the elements may be indexed, only with which order they're encountered in.
For that matter, does it matter if an array cell is empty? Would those count?
|
|
|
|
|
PIEBALDconsult wrote: For that matter, does it matter if an array cell is empty? Would those count? Sure. If a hotel clerk has to check the tenth pigeonhole from the left for mail, he doesn't skip the empty ones.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
True, so it depends on the task.
A customs clerk who is checking every tenth boat in the harbor will skip empty slips.
|
|
|
|
|
I don't think this is a question about English but about "Computerese".
A well known joke is that "Computer amateurs think 256 is a round number. Real computer guys consider 255 a round number - they count from zero."
Before computer guys took over the world, arrays could have any base. In Pascal, an array could run from index 1814 to 2050. Ordinary people could relate to it, e.g. as years. That reduced the importance of the Computer Guys, so they detested it. Even the Fortran style, where the first element of array a was a[1], was too obvious to Common Man, reducing the power of the Computer Guy. Luckily, base zero index won the war. (There is only a small problem left: What if there is no "zero" element, like in the calender? What happened in year 1 belongs in eventsOfYear[1], but what about eventsOfYear[0]? That year never existed! Year -1 was immediately followed by year 1! ... Fortunately, the Unix epoch doesn't apply to historic dates!)
Yet, there is a question of where "every 10th" is counted from: Is the "first" (or zeroth, if you like) every tenth element the one with the lowest index, the one with the tenth lowest index, or the one ten above the lowest index? If we had had a quantum computer, it could have provided all three results, with varying degrees of probability/validity.
|
|
|
|
|
Even early FORTRAN compilers used the trick of using address of A(n) as being (address of fictitious A(0)) + (n * width of data type of A); or as the literature of the day put it (address of A(1)) + (n - 1) * (width of data type A)
[historical note: versions of FORTRAN prior to 1977 only had uppercase variable name and all versions used '(' and ')', not '[' and ']'; but that doesn't affect the validity of what I am saying]
|
|
|
|
|
The first computer I played around with at the instruction level had an instruction "MIX3" to decrement the accumulator by one and then multipy by 3. This was a 16-bit mini (PDP-11 class) with a 48 bit floating point format, 3 words (memory was not byte adressable). The instruction was tailor made for Fortran, to calculate the offset from the start of a 1-based float array of element "n" - just like you describe, but with a fixed element width of 3 words.
|
|
|
|
|
#1 is the way I would interpret the question. (English speaker)
"Go forth into the source" - Neal Morse
|
|
|
|
|
I know that you're a long time member Nelek, and I certainly don't have as high a reputation as you, so I can't help wondering:
At what rep point value should I start posting my programming questions in the Lounge instead of QA as well?
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
|
|
|
|
|
Johnny J. wrote: At what rep point value should I start posting my programming questions in the Lounge instead of QA as well
When you're above OG.
On the other hand, I see this more as a philosophical question about counting vs indexing (it's amazing how many people are mixing those up) rather than programming.
|
|
|
|
|
Johnny J. wrote: I know that you're a long time member Nelek and, I certainly don't have as high a reputation as you 1)You longer than me
2a) There is only a difference of 25k between you and me, so no that much to deserve this kind of ironic comment
2b) If you want it, you can have all my reputation added to yours. It is not going to bring food to my table or give me a rise at work, so all yours.
Johnny J. wrote: so I can't help wondering:
At what rep point value should I start posting my programming questions in the Lounge instead of QA as well? And I can't help but wondering:
if you see that as a programming question, do you need glasses?
The question was (simplified for you):
Does the english sentence "every 10th" imply that you have to start in the first one?
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
modified 13-Mar-20 11:49am.
|
|
|
|
|
Let's put it this way: Imagine the state you live in chose to simplify taxes, and told all people to line up. Then, with everyone in place, they say: "This year, we will require one tenth of your total income as taxes. To simplify the procedure, every tenth person should give us all their income, and everyone else can go."
Now, if you ask the people, I'm sure almost all will agree that the 10th must pay, not the first. After all, that is exactly what the politicians said.
But, if you ask the authorities, they'll say differently, because then they're in danger of ending up short in cash: If there are 99 lined up, and only 9 would pay, there wouldn't be enough taxes collected; in an extreme case, there are only nine people lined up, and no taxes collected. Therefore, the authorites will demand that for every group of 10 people or less, the first should pay.
Of course the authorities' stance - as so often - doesn't correspond to what the politicians said...
So, to answer your question:
The correct answer is #1, but the politicians stating the task actually meant #2.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I hope no politicians are reading this and getting stupid ideas.
|
|
|
|
|
Just make sure you are third to eighth and you'll be happy.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|