Skip to content

Instantly share code, notes, and snippets.

@unalfaruk
Created May 20, 2020 15:01
Show Gist options
  • Save unalfaruk/85117fd3309158a52f892a75b13d59d8 to your computer and use it in GitHub Desktop.
Save unalfaruk/85117fd3309158a52f892a75b13d59d8 to your computer and use it in GitHub Desktop.
function result = isKaprekarNumber(number)
result=0;
lenOfNumber = length(num2str(number));
numberArray = num2str(number);
sqOfNumber = number.^2;
sqNumberArray = num2str(sqOfNumber);
sqHead= sqNumberArray(1:lenOfNumber);
sqTail= sqNumberArray(lenOfNumber+1:lenOfNumber+lenOfNumber);
sumOfHeadAndTail = str2num(sqNumberArray(1:lenOfNumber))+str2num(sqNumberArray(lenOfNumber+1:lenOfNumber+lenOfNumber));
if isequal(number,sumOfHeadAndTail)
result=1;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment