# Alter by Boolean Sequence

![Sequentially number true blocks](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FpOBxu4YxK8fXl8901lDj%2FsqnNum.png?alt=media\&token=a15191dd-8b29-42d9-ad10-b058abc4c756)

```d
def numTruSqn (lst01:var[]..[])
{
	//Seperate consecutive true and false
	cns01 = List.DropItems(lst01,1) == List.DropItems(lst01,-1);
	cns02 = List.Flatten([-1, List.AllIndicesOf(cns01,false),List.Count(lst01)-1], -1);
	cns03 = List.DropItems(cns02,1) - List.DropItems(cns02,-1);
	lst02 = List.Chop(lst01,cns03);

	// Assign value to true
	lst03 = List.Flatten(List.UniqueItems(lst02<1>));
	lst04 = Math.Sum(List.TakeItems(lst03 == true ? 1 : 0, 1..List.Count(lst03)));
	return lst02 == true ? lst04 : 0;
};
```

![Replace trues sequentially with elements from another list](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-MSkHaEAFDe1WYBWogEk%2F-MSkIQU5NFBeW87g3G1Z%2FreplaceTrue_2021-01-29_11-45-59.png?alt=media\&token=d3756d60-74c4-4677-9c24-43eea411417e)

```d
ls1 = List.Flatten(lst1,-1);
ls2 = List.GroupByKey(0..(List.Count(ls1)-1),ls1);
ls3 = List.SortByKey(ls2["groups"],ls2["unique keys"])["sortedList"];
ls4 = [List.OfRepeatedItem(null,List.CountFalse(ls1)),lst2];
ls5 = List.SortByKey(List.Flatten(ls4,-1),List.Flatten(ls3,-1));
ls6 = List.Chop(ls5["sortedList"],List.Count(lst1<1>));
```

![List chopped to correspond with true/false sequence](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-MMy0QNCdCm_NMmxwoBO%2F-MMy2Mfml6G4A9b5tDcp%2FchopByBooleanList_2020-11-25_11-47-39.png?alt=media\&token=574855d1-0ad8-4aa6-a743-63246b160214)

```d
bln2 = List.Sublists(bln1,0..1,1);
bln3 = List.AllTrue(bln2<1>) ? false
:List.LastItem(bln2<1>) == true ? true
:List.FirstItem(bln2<1>) == true ? true
:false;
ind0 = List.AllIndicesOf(bln3,true)+1;
ind1 = List.Flatten([0,ind0,List.Count(bln1)],-1);
ind2 = List.RestOfItems(ind1)-List.DropItems(ind1,-1);
lst1 = List.Chop(lst,ind2);
```

![](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-MMy0QNCdCm_NMmxwoBO%2F-MMy47pp7vDBxZcx1Hlx%2FchopByBooleanList_2020-11-25_11-55-08.png?alt=media\&token=03ee966d-c771-46a2-a0c6-5ecabc3ef842)

![Variation in which the first item varies from the rest](https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ld8QK19sjP1I9rhLouo%2F-MMy0QNCdCm_NMmxwoBO%2F-MMy31ixiFiRUzaacuQ3%2FchopByBoolSeq_2020-11-25_09-53-19.png?alt=media\&token=938cb461-9af6-49bd-bbb9-e072c55f1e6b)

```d
bln2 = List.Sublists(bln1,0..1,1);
bln3 = List.AllFalse(bln2<1>) ? false
: List.LastItem(bln2<1>) == true ? true
: List.FirstItem(bln2<1>) == true ? false
: true;
ind0 = List.AllIndicesOf(bln3,false)+1;
ind1 = List.Flatten([0,ind0,List.Count(bln1)],-1);
ind2 = List.RestOfItems(ind1)-List.DropItems(ind1,-1);
lst1 = List.Chop(lst,ind2);
```
