-
Description Two can play at that game 🦀 (admittedly less straightforward since Rust is more explicit around operations and potential errors)
Code fn reverse_int(n: u128) -> u128 { n.to_string().chars().rev().collect::<String>().parse().unwrap() }
Test Cases fn tests() { let test_samples = [ (776, 677), (12345, 54321), (3121534312, 2134351213), (726376882009597984841891, 198148489795900288673627), ]; for (s, e) in test_samples { assert_eq!(reverse_int(s), e) } }
Output:
-
Code def reverse_int(n):return int(str(n)[::-1])- fn reverse_int(n: u128) -> u128 {
- n.to_string().chars().rev().collect::<String>().parse().unwrap()
- }
Test Cases import codewars_test as testfrom solution import reverse_int- #[test]
- fn tests() {
- let test_samples = [
- (776, 677),
- (12345, 54321),
- (3121534312, 2134351213),
- (726376882009597984841891, 198148489795900288673627),
- ];
@test.describe("Example")def test_group():@test.it("test case")def test_case():test_samples = ((776,677),(12345,54321),(3121534312,2134351213),(726376882009597984841891,198148489795900288673627),)for s, e in test_samples:test.assert_equals(reverse_int(s), e)- for (s, e) in test_samples {
- assert_eq!(reverse_int(s), e)
- }
- }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}