making different numbers with same digits
Show older comments
hello,
how do I make sure to find the next number greater and less than the number requested from the user, but it must contain the same digits as the requested number
for exemple: you get 536 so the answer will be 365 and 635
Accepted Answer
More Answers (1)
Ameer Hamza
on 15 Nov 2020
Try this
x = 536;
y = num2str(x);
idx1 = randi([2 numel(y)]); % to make sure we don't get same number
idx = [idx1 setdiff(randperm(numel(y)), idx1)];
y = str2double(y(idx));
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!