Talk:Zig-zag matrix: Difference between revisions

→‎Pattern of memory addresses: Previous pattern searches.
m (→‎The first N squared integers: posed a question.)
(→‎Pattern of memory addresses: Previous pattern searches.)
 
(5 intermediate revisions by 2 users not shown)
Line 447:
 
So the question is now,   what is the first   ''natural number''?     -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 21:52, 24 January 2020 (UTC)
 
:If we allow zero or one to ''both'' be allowed then it could mean minimal rework of examples whilst hopefully retaining the spirit of the old task?
:(I am a little biased, as this is one of the existing tasks that first attracted me to RC - I based the second task I started, "Spiral matrix", on this one and have fond memories).
:--[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 09:20, 25 January 2020 (UTC)
 
== Pattern of memory addresses ==
 
If we assume that each entry is stored consecutively in memory like so (using size 5 as an example), and assuming an 8-bit computer where each memory address holds a byte and each address is 16-bit
 
<pre>;these are memory locations, the values within are as in the example.
$1200 $1201 $1202 $1203 $1204
$1205 $1206 $1207 $1208 $1209
$120A $120B $120C $120D $120E
$120F $1210 $1211 $1212 $1213
$1214 $1215 $1216 $1217 $1218
</pre>
 
Then to get to the next memory address, we add the following numbers to the one we're at.
Let N = the size of the array and K = N-1. Then:
<pre>
$1200 + 1 = $1201
$1201 + K = $1205
$1205 + N = $120A
$120A - K = $1206
$1206 - K = $1202
$1202 + 1 = $1203
$1203 + K = $1207
$1207 + K = $120B
$120B + K = $120F
$120F + N = $1214
$1214 - K = $1210
$1210 - K = $120C
$120C - K = $1208
$1208 - K = $1204
$1204 + N = $1209
$1209 + K = $120D
$120D + K = $1211
$1211 + K = $1215
$1215 + 1 = $1216
$1216 - K = $1212
$1212 - K = $120E
$120E + N = $1213
$1217 + 1 = $1218
</pre>
 
It seems to follow this pattern:
<pre> +1, +K, +N, -2K, +1, +3K, +N, -(K^2), +1, +N, +3K, +1, -2K, +N, +K, +1</pre>
 
I tried it again with a N=4 and got this sequence:
<pre> +1, +K, +N, -2K, +1, +(K^2), +1, -2K, +N, +K, +1</pre>
 
If you remove the <math>k^2</math> and +1 after it, the sequence is symmetric.
 
Might be helpful for establishing a pattern. I'll work on it more later. This logic should extend to 32-bit CPUs if you multiply N and K by 4.--[[User:Puppydrum64|Puppydrum64]] ([[User talk:Puppydrum64|talk]]) 17:06, 15 September 2021 (UTC)
 
:Hi Puppydrum64; at the top of the talk page the author of the J example talks about his solution that exploits patterns in indices. I just noticed that sort was involved and worked out something for the Python entry and explained it in my blog: [http://paddy3118.blogspot.com/2008/08/zig-zag.html paddy3118 blog explanation].
 
: There ''are'' patterns to be found :-)
: --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 07:44, 18 September 2021 (UTC)
Anonymous user