Icon representing a recipe

Recipe: Walker subroutine 1.1

created by Bruno Kestemont

Profile


Name
Walker subroutine 1.1
ID
101601
Shared with
Public
Parent
None
Children
None
Created on
November 25, 2015 at 18:25 PM UTC
Updated on
November 25, 2015 at 18:25 PM UTC
Description

For Cookers only: various ways of walking in a segment list

Best for


Code


--[[Mix Table Subroutine by Bruno Kestemont 16/11/2015, idea by Puxatudo & Jeff101 from Go Science ]]-- --Example needed inits in recipe if used for segments (from tvdl) segCnt=structure.GetCount() flagligand=false segCnt2=segCnt -- ligands while structure.GetSecondaryStructure(segCnt2)=="M" do segCnt2=segCnt2-1 end segStart=1 --start from segEnd=segCnt2 --end seg --WORKON={{segStart,segCnt2}} WORKONBIS={} -- the table to use is a simple list of segments in any order compteur=0 for i = segStart, segEnd do -- basic list of segments (init of WORKONBIS) compteur=compteur+1 WORKONBIS[compteur]=i end --calculate REALLY good seed for the pseudorandom in random (avoids to always have the same sequence) seed=os.time()/math.abs(current.GetScore()) seed=seed%0.001 seed=1/seed while seed<10000000 do seed=seed*1000 end seed=seed-seed%1 print("Seed is: "..seed) math.randomseed(seed) --REALLY good seed made by rav3n_pl :P --START MIX TABLE subroutine by Bruno Kestemont 16/11/2015, idea by Puxatudo & Jeff101 from Go Science function down(x) return x-x%1 end function ShuffleTable(tab) --randomize order of elements local cnt=#tab for i=1,cnt do local r=math.random(cnt) -- not very convincing ! it gives always the same number on same puzzle tab[i],tab[r]=tab[r],tab[i] end return tab end function MixInwardTable(tab) -- 1234567 = 7254361 WARNING: if done twice, it returns to the original table local cnt=#tab -- 1234567 = 7254361 local mid=down(cnt/2) local adjust=1 -- case of pair number of segments local result={} local pair=true if mid<cnt/2 then adjust=0 end -- case of impair number of segments for i=1,mid-adjust do -- mid remains untouched if impair cnt pair = not pair if pair then result[i],result[cnt+1-i]=tab[i],tab[cnt+1-i] -- pair segs are kept untouched else result[i],result[cnt+1-i]=tab[cnt+1-i],tab[i] -- impairs segs are shifted (loop starts with last seg) end end return result end function InwardTable(tab) -- 1234567 = 7162534 WARNING: if done twice, it mixes everything like a feuillete bakery local cnt=#tab -- 1234567 = 7162534 local cntup=1 local result={} local pair=true for i=1,#tab do pair = not pair if pair then result[i]=tab[cntup] -- pairs segments are taken from bottom cntup=cntup+1 else result[i]=tab[cnt] -- impairs segs are taken from end (loop starts with last seg) cnt=cnt-1 end end return result end function Reverselist(tab) -- 1234567=7654321 local cnt=#tab local result={} for i=1,#tab do -- simply inverts the table 7162534=4536271 result[i]=tab[cnt+1-i] end return result end function OutwardTable(tab) --1234567=4352617 local result={} result=Reverselist(InwardTable(tab)) return result end --END MIX TABLE --Example with segments mixtables=1 dlg = dialog.CreateDialog("Mix Table Subroutine") dlg.l1aaa=dialog.AddLabel("1=up; 2=back; 3=random; 4=out; 5=in; 6=slice") dlg.mixtables = dialog.AddSlider("Order: ", mixtables, 1, 6, 0) dlg.OK = dialog.AddButton("OK",1) dlg.Cancel = dialog.AddButton("Cancel",0) if dialog.Show(dlg) > 0 then --For MIXTABLES mixtables=dlg.mixtables.value WORKONBIS={} -- reset / the table to use is a simple list of segments in any order local compteur=0 for i = segStart, segEnd do -- basic list of segments (reset of WORKONBIS) compteur=compteur+1 WORKONBIS[compteur]=i end if mixtables==2 then WORKONBIS=Reverselist(WORKONBIS) elseif mixtables==3 then randomly=true WORKONBIS=ShuffleTable(WORKONBIS) elseif mixtables==4 then WORKONBIS=OutwardTable(WORKONBIS) elseif mixtables==5 then WORKONBIS=InwardTable(WORKONBIS) elseif mixtables==6 then WORKONBIS=MixInwardTable(WORKONBIS) end -- else normal from first to last in the list end function test(worklist) worklist=worklist or WORKONBIS for j=1,#worklist do local i=worklist[j] print(i) selection.Select(i) structure.LocalWiggleSelected(1) end end test()

Comments


Bruno Kestemont Lv 1

Example for a puzzle of 7 segments:

Normal : 1234567
Reverse: 7654321
Outward: 4536271
Inward: 7162534
Sliceward: 7254361

Ideas from puxatudo & jeff101