Move History

Fork Selected
  • 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
    #[test]
    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)
        }
    }
    
  • 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 test
    • from 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)
    • }
    • }