I think this is too complex and specific to be made with available blocks. Maybe some specific block with custom code, in theory it's not impossible, but it will not be elegant to do things like this with blocks because there are many small calculations and conditions.