Open main menu

CDOT Wiki β

Changes

Solo Act

11 bytes removed, 05:39, 16 April 2018
Assignment 3
[[File:njsimasroot.png|500px ]]
 
The first step was using modulus to set the odd value in the leaf pair equal to the greater value:
modIndex =((ti + q) + (ti + 1) % 2)
I needed the number of nodes in the previous round, plus one, to later subtract from the current array index:
I needed the number of nodes in the previous round, plus one, to later subtract from the current array index, basically 'walking backwards':  prevLeafTotal = leafTotal ((t / 2) + 1);
Basically 'walking backwards'
The next step was making the thread index progression correspond to the root progression.
Progression = (((ti + 1) / 2) – 1) + ((ti + q) + (ti + 1) % 2)
 
Finally, I add this progression to the previous leaf total, and subtract the result from the new array index from stage 1:
root = modIndex – (leafTotal + progression)
 
Since this was all to be done by a single thread, in a single step, I condensed the formula into one line.
((ti + q) + ((ti + 1) % 2)) - (((((ti + 1) / 2) - 1) + ((ti + 1) % 2)) + (t / 2) + 1);
120
edits