? Getting the Dimension Lengths from 2D Arrays (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
This website has been moved, please see this post

Getting the Dimension Lengths from 2D Arrays

  • #1 ✎ 90 HackTheWorlds Second Year My account is over 2 years old Website Summer 2016 Contest Participant I participated in the SmileBASIC Source Summer 2016 Contest! Programming Contest Reading I like to read books! Hobbies So I figured out how to determine the length of dimensions in 2D arrays. I don't want to explain how it works right now, so I'll just give you the key: E245W8V I also learned that you can COPY between arrays with fewer or lesser dimensions as long as there are enough total elements, which is strange. Posted Edited by HackTheWorlds
  • #2 ✎ 1882 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself broken key Posted
  • #3 ✎ 90 HackTheWorlds Second Year My account is over 2 years old Website Summer 2016 Contest Participant I participated in the SmileBASIC Source Summer 2016 Contest! Programming Contest Reading I like to read books! Hobbies Fixed. Posted
  • #4 ✎ 477 SquareFingers
    I don't want to explain how it works right now
    Well, I do. FILL, in the built-in help, is shown as FILL Array, Value [, Offset [, Number of elements]]. 'Offset' is a single number. In a 1D array, it corresponds exactly to the index. In a 2D array, it corresponds to (second index + (second dimension size)*(first index)). For 3D, (third index + (third dimension size)*(second index + (second dimension size)*(first index))). For 4D, the pattern continues. So, the program uses COPY to copy the array in question to a placeholder array. The placeholder array's elements are FILLed with their own 'offset' value. Then, array index [1,0] contains the size of the second dimension, the number of times this fits into the LEN of the array is the size of the first dimension. The code assumes the size of the first dimension is at least 2. It can be adapted for 3D, 4D arrays, but there is no way (so far as I know) to know, given just an array, how many dimensions it has.
    Posted
  • #5 ✎ 190 DFrost Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength I see how you put FILL A%, 42 They always said 42 was the answer to the universe. Anyways, this is AWESOME Posted Edited by DFrost