Chile

cancel
Showing results for
Search instead for
Did you mean:
Specialist II

Conjetura de Collatz

Hola!, muy simple script Qlik Sense Business  para generar números enteros para evaluar la conjetura de Collatz

https://es.wikipedia.org/wiki/Conjetura_de_Collatz

https://www.youtube.com/watch?v=q_dvxXc7d2Y

La imagen muestra los pasos requeridos para los números 6 (9)  y 7 (17)

///Generate Data

Set vIterationsIni = 0;
Set vIterations = 100000;

For vIter = vIterationsIni to vIterations

Let vN = vIter;
Let vValue = \$(vN);

Do Until vValue = 1

Data:
Load
\$(vIter) as Iter,
autonumber(\$(vValue), \$(vIter)) as Step,
\$(vValue) as Value
Autogenerate(1);

Let vValue = if(even(\$(vValue)), \$(vValue) / 2, (\$(vValue) * 3 ) + 1);

Loop

Max_Step:
Load
max(Step) + 1 as Max_Step
Resident Data
Where
Iter = \$(vIter);

Data:
Load
\$(vIter) as Iter,
peek('Max_Step', 0, 'Max_Step') as Step,
1 as Value
Autogenerate(1);
drop table Max_Step;

store Data into [lib://Collatz (fabian_fabian)/Data_Iter_\$(vIter).qvd];
drop table Data;

Next

// Grouping Data
Data:
LOAD
Iter,
"Step",
Value
FROM [lib://Collatz (fabian_fabian)/Data_Iter_*.qvd] (qvd);

store Data into [lib://Collatz (fabian_fabian)/Data.qvd];

//Presenting Data
Collats:
Load
Iter,
Step,
Iter & ' | ' & Step as [Iter-Step],
Value,
if(Value = 1 or Value = 2 or Value = 4, 1) as Step_421
Resident Data;
drop table Data;

QFabian
0 Replies
Tags