Post Reply 
Programming puzzles: processing lists!
02-12-2019, 06:12 PM (This post was last modified: 02-12-2019 06:16 PM by pier4r.)
Post: #267
RE: Programming puzzles: processing lists!
Ok adapted the #44

Impressive how helpful listext is!

For the #44 I didn't want to use any loop or dosubs going through all the elements keeping track of the last value.

Ideally I wanted to do it with operations applied to lists (like you mentioned, 6 ADD) and if dosubs and co are used, they contain very little commands, ideally one command.

I found something with stream although I tested it on paper and not with the 50g

Code:

spoiler















we have an input list, say
I = {1 0 1 1 0 1 0 1 1 1 0 1 0 1}

we duplicate it: I 'I2' STO

then we add one leading zero to I, making a temp list
T = {0 1 0 1 1 0 1 0 1 1 1 0 1 0 1}

Then with 2 \<< AND \>> DOSUBS on the list we have the result T1
{0 1 0 1 1 0 1 0 1 1 1 0 1 0 1} T
  {0 0 0 1 0 0 0 0 1 1 0 0 0 0} T1 after the AND between adjacent elements

we check that T1 has at least one 1, with T1 1 POS. If no 1 is there, we are done.
If there is a 1, do I2 T1 ADD 'I2' STO. Thus
{1 0 1 1 0 1 0 1 1 1 0 1 0 1} I2
{0 0 0 1 0 0 0 0 1 1 0 0 0 0} T1
{1 0 1 2 0 1 0 1 2 2 0 1 0 1} new I2

Then repeat with a leading zero to make a new T and again with the and between adjacent elements to get a new T1
{0 0 0 0 1 0 0 0 0 1 1 0 0 0 0} new T
  {0 0 0 0 0 0 0 0 0 1 0 0 0 0} new T1

again T1 1 POS -> yes
I2 T1 ADD 'I2' STO
{1 0 1 2 0 1 0 1 2 2 0 1 0 1} I2
{0 0 0 0 0 0 0 0 0 1 0 0 0 0} T1
{1 0 1 2 0 1 0 1 2 3 0 1 0 1} new I2

at the next iteration T1 will be only zeroes, so the attempts are ended.

It is extremely slow compared to one pass with DOSUBS or a FOR loop, but I find it neat.

I made like 300 words errors, I am tired tonight.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming puzzles: processing lists! - pier4r - 02-12-2019 06:12 PM



User(s) browsing this thread: 1 Guest(s)