[Community puzzle] Jack Silver: The Casino Part 1 _ Issue with Test#7

I have an issue with this puzzle.

It is a pretty simple puzzle though I can’t get 100%.
I checked the math, I do everything correctly, All the tests passes but when I submit Test#7 dramatically fails.

I don’t know what special cases it focuses but I check output boundary which are false since it is said
1 <= MONEY <= 1000000 but Test#3 expect a 0 dans money (and cash) can exceed 1 000 000 on 0 is not EVEN.

I also tried to check the number of round (I was looping until nothing more come on stdin). It still dont pass.
Does anybody has a clue for the direction I should look at ?

Hi, just did this puzzle, didn’t notice any problem (except the little mistake in the constraint of Money).
You should try to test with your own “custom” test cases to see how your code is working for all possibilities, doing them one by one might help you to find where your code isn’t working.

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.

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%

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