to wrap around we can just pad the left side with the last cell of the row, 
and pad the right side with the first cell

On Sunday, 14 August 2022 at 12:59:55 UTC-4 Konstantin Astafurov wrote:

> ah shoot, I realized I didn't put [proposal] in the header so I deleted 
> this and then added more stuff including a use case.
> To summarize, let's say you want to make Conway's game of life. There are 
> many ways of doing it, but I did it by chunking each row into windows of 
> size 3 and then doing various operations. The problem is, that the first 
> and last windows should have a size of 2, as the first cell in a row only 
> has a neighbor ahead of it (we can also make stuff wrap around, using this 
> proposed chunk_every function, but ill explain that part later). So I wrote 
> this setup_arr function that makes an incomplete window, pads it, and pads 
> the incomplete window at the end of the chunks.
> Example:
> [0,1,0,1,0,0]
> would turn into:
> [0,1], [0,1,0] [1,0,1], [0,1,0], [1,0,0], [0,0]
> But with the leftover options, we could also add 0s (as the neighbor that 
> doesn't exist isn't alive)
> [0,0,1], [0,1,0] [1,0,1], [0,1,0], [1,0,0], [0,0,0]
>
>
> https://github.com/konstantin-aa/gamesoflife/blob/main/main.exs?fbclid=IwAR0BxNfsrAxY_ugCu-PyFP7TmvncagjwdlU5SegdovGrUV6zuDB9soUUEYg
>
> tweaked proposal:
> https://groups.google.com/g/elixir-lang-core/c/MAHgFIsThPo
> On Sunday, 14 August 2022 at 03:23:50 UTC-4 m...@achempion.com wrote:
>
>> Out of curiosity, what is the usecase where such function will be useful?
>>
>> On 14 Aug 2022, at 05:51, Konstantin Astafurov <konstantin...@gmail.com> 
>> wrote:
>>
>> I've noticed that in some cases, the chunking functionality provided by 
>> Enum.chunk_every isn't enough. For example, It'd be awesome if chunk_every 
>> could offset the window.
>>
>> so [1,2,3,4,5] with count 3 step 2 and offset of -2 would return
>> [1], [1,2], [1,2,3], [2,3,4], [3,4,5], [4,5], [5]
>>
>> Elements in the leftover option would be to the left of the initial 
>> chunks less than count. It'd also be neat if you could have different 
>> leftover options for the left-hand and right-hand leftovers.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elixir-lang-co...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/ecb42760-f5f2-447e-89be-dc1081654b5cn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/ecb42760-f5f2-447e-89be-dc1081654b5cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/1f3c392f-95bd-4a65-8dc2-24353dca7d3fn%40googlegroups.com.

Reply via email to