AWK, 25 29 27 bytes
{for(i=0;!($1%++i););$0=i}1
##AWK, 25 29Try it online!
Can save 3 bytes
{i=0;while(!($1%++i)){}$0=i}1 by leaving out the i=0
but then multi-line input would be incorrect.
As with all AWK
scripts, the code can be placed in a file or typed in at the command line.
Command Line Usage:
awk '{i=0;whilefor(i=0;!($1%++i);){}$0=i;$0=i}1' <<< inputNumber
or place numbers in a FILE each on its own line and do:
awk '{i=0;whilefor(i=0;!($1%++i);){}$0=i;$0=i}1' FILE
CorrectedTwo bytes saved by converting to account for subsequent usages. No longer using uninitialized variablefor
loop, also added TIO link.