[Community Puzzle] Jack Silver: The Casino

These are my unit tests (in Rust)
#[test]
fn test_plain_win() {
    let mut cash = 100;
    play(&mut cash, &"32 PLAIN 32".to_owned());
    assert_eq!(cash, 975);
}
#[test]
fn test_plain_lose() {
    let mut cash = 100;
    play(&mut cash, &"32 PLAIN 15".to_owned());
    assert_eq!(cash, 75);
}
#[test]
fn test_even_win() {
    let mut cash = 100;
    play(&mut cash, &"32 EVEN".to_owned());
    assert_eq!(cash, 125);
}
#[test]
fn test_even_lose() {
    let mut cash = 100;
    play(&mut cash, &"15 EVEN".to_owned());
    assert_eq!(cash, 75);

    play(&mut cash, &"0 EVEN".to_owned());
    assert_eq!(cash, 56);
}
#[test]
fn test_odd_win() {
    let mut cash = 100;
    play(&mut cash, &"31 ODD".to_owned());
    assert_eq!(cash, 125);

    play(&mut cash, &"0 ODD".to_owned());
    assert_eq!(cash, 157);
}
#[test]
fn test_odd_lose() {
    let mut cash = 100;
    play(&mut cash, &"32 ODD".to_owned());
    assert_eq!(cash, 75);
}
#[test]
fn test_0_cash() {
    let mut cash = 0;
    play(&mut cash, &"32 ODD".to_owned());
    assert_eq!(cash, 0);

    play(&mut cash, &"15 ODD".to_owned());
    assert_eq!(cash, 0);

    play(&mut cash, &"32 EVEN".to_owned());
    assert_eq!(cash, 0);

    play(&mut cash, &"15 EVEN".to_owned());
    assert_eq!(cash, 0);

    play(&mut cash, &"32 PLAIN 15".to_owned());
    assert_eq!(cash, 0);

    play(&mut cash, &"32 PLAIN 32".to_owned());
    assert_eq!(cash, 0);
}
#[test]
fn test_1_cash() {
    let mut cash = 1;
    play(&mut cash, &"15 ODD".to_owned());
    assert_eq!(cash, 2);

    play(&mut cash, &"32 ODD".to_owned());
    assert_eq!(cash, 1);

    play(&mut cash, &"32 EVEN".to_owned());
    assert_eq!(cash, 2);

    play(&mut cash, &"15 EVEN".to_owned());
    assert_eq!(cash, 1);

    play(&mut cash, &"32 PLAIN 32".to_owned());
    assert_eq!(cash, 36);

    play(&mut cash, &"32 PLAIN 15".to_owned());
    assert_eq!(cash, 27);
}
#[test]
fn test_all_even() {
    for ball in 0..37 {
        let mut cash = 100;
        play(&mut cash, &format!("{} EVEN", ball));
        if ball % 2 == 1 || ball == 0 {
            assert!(cash == 75, "unexpected lose: {} EVEN", ball);
        } else {
            assert!(cash == 125, "unexpected win: {} EVEN", ball);
        }
    }
}
#[test]
fn test_all_odd() {
    for ball in 0..37 {
        let mut cash = 100;
        play(&mut cash, &format!("{} ODD", ball));
        if ball % 2 == 1 || ball == 0 {
            assert!(cash == 125, "unexpected win: {} ODD", ball);
        } else {
            assert!(cash == 75, "unexpected lose: {} ODD", ball);
        }
    }
}
#[test]
fn test_all_plain() {
    for target in 0..37 {
        for ball in 0..37 {
            let mut cash = 100;
            play(&mut cash, &format!("{} PLAIN {}", ball, target));

            if ball == target {
                assert!(cash == 975, "unexpected win: {} PLAIN {}", ball, target);
            } else {
                assert!(cash == 75, "unexpected lose: {} PLAIN {}", ball, target);
            }
        }
    }
}
#[test]
fn test_lose_for_0_to_1_000_000() {
    for bank in 0..1_000_001 {
        let mut cash = bank;
        play(&mut cash, &"32 ODD".to_owned());

        assert!(cash == (bank - ((bank as f64)/4.).ceil() as usize), "failed for bank={}", bank);
    }
}
#[test]
fn test_win_for_0_to_1_000_000() {
    for bank in 0..1_000_001 {
        let mut cash = bank;
        play(&mut cash, &"32 EVEN".to_owned());

        assert!(cash == (bank + ((bank as f64)/4.).ceil() as usize), "failed for bank={}", bank);
    }
}

And they all pass.

Hm, nailed it.

Actually that was a misunderstanding. 0 is considered neither odd nor even. I went too fast on this one.

Thank you.

1 Like

Pass all tests but get only 50% when submitting.Something I may forgot?

N.S

My mistake was that 0 is neither odd nor even.
Have you checked that ?

Yes I did…

0 is even but in this game it’s a special value.

Looks like the validators “Target #6” and “Target #7” include extra white space at the end of the line after a PLAIN bet. If you fail those two, check if that extra space would meddle with how you parse the input.

4 Likes

Thank you! :slight_smile:

Thanks to your help, i made it to 100%
I thought 0 was considered as an odd, since it’s not an even.

Long time, but may be useful for new users. You got that result because you are adding the bet result to your full money instead of 3/4 of your money (since 1/4 was your bet).

That’s exactly what I was thinking too. I even redid all of my code like 5 times trying to get 7 to work.

Hi, can you give me some clue? In my code 0 is neither odd or even, I deleted doubled spaces, or space if it appeared at the end of line. What else can I do to reach “Target #6”? I made this puzzle to 75%

Hello, i can’t pass the last test (0 is not even). But it is known that 0 is EVEN. Do i need to do things not based on real logic and math and consider it not EVEN here ?

As it is stated in the puzzle description :

  • The target’s calls, CALL, can be one of the three possibilities:
    – EVEN - He bets on an EVEN (non-zero) number
    – ODD - He bets on an ODD number
    – PLAIN - He bets on a specific number: NUMBER

Here the bets are similar to the roulette, 0 is a losing bet for EVEN and ODD bets :

3 Likes

Hi there,

I am validating all tests in the IDE, but when I submit I don’t validate test #7 which is not shown in the IDE.
Can anyone advise please? I’m stuck at 75% validation.

Thanks,
Ed

Hey,
You probably missed what hemhel posted just above.
On this problem, the value 0 should not be considered as EVEN… but not as ODD neither.

Hope it helps

3 Likes

Well I found one strange thing,it is not a bug but it may cause some problems.
I try to check if it is “PLAIN” like this
Console.ReadLine().Split(’ ‘).Count() == 3 and in final test I get only 50%
After I changed it to
Console.ReadLine().Split(’ ')[1].Equals(“PLAIN”)
I get 100%
So probably there is too much unnecessary spaces in some test cases.

Hello,

I don’t understand I passed all tests but not the last 2 validators (python 3)
I don’t understand why : 0 well treated etc…
Does anyone encountered this kind of bug ?

Thank you for the hint, that saved me!

I think the puzzle owner should fix that!

I’m not the creator but I just updated the contribution. Thanks for reporting and sorry for taking 2 years to react.

2 Likes