Rust Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```rust []\nuse std::collections::HashMap;\nuse std::collections::HashSet;\nimpl Solution {\n    pub fn count_pairs(nums: Vec<i32>) -> i32 {\n        let mut nums = nums;\n        nums.sort();\n\n        let mut mp = HashMap::<i32, i32>::new();\n        let mut p = vec![1; 8];\n        let mut ret = 0;\n\n        for i in 1 .. 8 { p[i] = 10 * p[i - 1]; }\n        for a in &nums {\n            if let Some(cnt) = mp.get(a) {\n                ret += *cnt;\n            }\n            *mp.entry(*a).or_insert(0) += 1;\n\n            let mut s = HashSet::from([*a]); \n            let m = Self::digits(*a);\n\n            for i1 in 0 .. m {\n                for i2 in i1 + 1 .. m {\n                    let b = Self::swap(*a, &p, i1, i2);\n                    if s.contains(&b) == false{\n                        if let Some(cnt) = mp.get(&b) { ret += *cnt; }\n                        s.insert(b); \n                    }\n                    for i3 in 0 .. m {\n                        for i4 in i3 + 1 .. m { \n                            let b = Self::swap(*a, &p, i1, i2);\n                            let b = Self::swap(b, &p, i3, i4);\n                            if s.contains(&b) == false {\n                                if let Some(cnt) = mp.get(&b) { ret += *cnt; }\n                                s.insert(b); \n                            } \n                        }\n                    }\n                } \n            }\n        }\n        ret\n    }\n\n\n    fn swap(a: i32, p: &Vec<i32>, i: usize, j: usize) -> i32 {\n        let x = a / p[i] % 10;\n        let y = a / p[j] % 10;\n        a - x * p[i] - y * p[j] + y * p[i] + x * p[j]   \n    }\n\n\n    fn digits(a: i32) -> usize {\n        let mut a = a;\n        let mut cnt = 0;\n        while a > 0 {\n            cnt += 1;\n            a /= 10;\n        }\n        cnt\n    }\n}\n```
['Rust']