How do I remove all boxes with one element? E.g. I would like to turn this:
┌─────┬───┬─┬─────┐
│1 1 1│2 2│3│2 2 2│
└─────┴───┴─┴─────┘
Into this:
┌─────┬───┬─────┐
│1 1 1│2 2│2 2 2│
└─────┴───┴─────┘
Suppose your value is in a:
]a =. 1 1 1; 2 2; 3; 2 2 2
┌─────┬───┬─┬─────┐
│1 1 1│2 2│3│2 2 2│
└─────┴───┴─┴─────┘
The trick here is to get the length of each box:
#@> a
3 2 1 3
If the length > 1, you get a "mask" you can pass to copy.
1 < #@> a
1 1 0 1
a #~ 1 < #@> a
┌─────┬───┬─────┐
│1 1 1│2 2│2 2 2│
└─────┴───┴─────┘
13: will tell us how to make this tacit:
13 : 'y #~ 1<#@>y'
] #~ 1 < #@>
As it happens, needing to put id in the last position of a fork is exactly what a hook does, so we can even simplify one more step:
remsingles =. #~ 1 < #@>
remsingles a
┌─────┬───┬─────┐
│1 1 1│2 2│2 2 2│
└─────┴───┴─────┘
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With