Test if two numbers have the same digits - MATLAB Cody - MATLAB Central

Problem 1081. Test if two numbers have the same digits

Difficulty:Rate

Given two integers x1 and x2, return true if the numbers written with no leading zeros contain the same digits. That is, the string representation of one number is a permutation of the string representation of the other.

For example

    x1 = 1234;
    x2 = 4321;
    tf = same_digits(x1,x2)

would output

    tf = true

whereas

    x1 = 1234;
    x2 = 1244;
    tf = same_digits(x1,x2)

would output

    tf = false

Solution Stats

43.75% Correct | 56.25% Incorrect
Last Solution submitted on May 06, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
2
3

Problem Recent Solvers250

Suggested Problems

More from this Author56

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!