# [Community Puzzle] Jack Silver: The Casino

Coding Games and Programming Challenges to Code Better

Is there something I donâ€™t understand about this puzzle? I did the math by hand and got the same answer for the first test as my program, which was 15563. But the answer should be 1153.

[I removed the code]

There is nothing wrong, I solved it.

You were adding too much money! Hereâ€™s how this works:

You have \$4, so you will bet \$1.

If you bet on ODD and lose, you have \$3.
If you bet on ODD and win, you have \$5.
If you bet on EVEN and lose, you have \$3.
If you bet on EVEN and win, you have \$5.
If you bet on PLAIN and lose, you have \$3.
If you bet on PLAIN and win, you have \$39.

Your code does not return 3, 5, 3, 5, 3, 39 for the above scenarios. It returns 3, 6, 3, 6, 3, 40. Take another look.

• danBhentschel

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!

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