Lambda expression for bruteforce. Issue with segmentation fault after too many runs