ChatGPT seems to better at rewriting python functions to C++ than rstats to C++. The code below shows the original Python function and the translation to C++ done by the AI (I changed very little). It failed to perform that with a similar R function.