0

Why is this program a mistake? [7]

When i try the "poker hand" challenge (https://www.sololearn.com/coach/97?ref=app) in code coach i write a code like this: https://sololearn.com/compiler-playground/cBqSQmj9SJM8/?ref=app But somehow my code can't satisfy test case 6. What should i do to fix it?

13th Nov 2024, 3:15 AM
Celvien Kurniawan
Celvien Kurniawan - avatar
13 Respostas
+ 1
FINALLY, i fix the code!!! https://sololearn.com/compiler-playground/c5Dqi6gjUm7R/?ref=app Really, i just found the main culprit (bug) is at line 10... Which is actually unexpected... (â â•Żâ Â°â â–Ąâ Â°â ïŒ‰â â•Żâ ïž”â Â â â”»â â”â â”»
16th Nov 2024, 7:49 AM
Celvien Kurniawan
Celvien Kurniawan - avatar
+ 3
Your code is far too cryptic for me to have any interest in reading your code. But I will GUESS two things: 1. You probably are not handling the number 10 properly. 2. The error message that appears when the code finishes could be a problem as well.
13th Nov 2024, 4:08 AM
Jerry Hobby
Jerry Hobby - avatar
+ 2
Celvien Kurniawan Congratulations! Yeah, if fixing bugs is something you can enjoy, you're have the right mindset of a programmer. Now all that's left is to cleanup the print debugging and take care of that compiler warning...
16th Nov 2024, 12:36 PM
Bob_Li
Bob_Li - avatar
+ 2
19th Nov 2024, 3:08 AM
Bob_Li
Bob_Li - avatar
+ 1
Jerry Hobby about that, i'm sorry about my code is hard to understand. Because in the value function i tried to integrate the logic of poker rank in one operation of loops.
13th Nov 2024, 3:43 PM
Celvien Kurniawan
Celvien Kurniawan - avatar
+ 1
5S 2S 2H 3S 3C get a core dump. but rearranging it to 3S 2S 5S 2H 3C does not result in a core dump the order of the cards seem to affect it. maybe your algorithm was expecting a certain order? It should ideally be order-independent. or maybe it's simpler if you sort the cards first.
14th Nov 2024, 3:44 AM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li oh, that's a good idea! Honestly, i just found another bug when it has two aces. When the input is like this: AS AC 2S 3S 4S. Really, this challenge is definitely a complex one for me.
15th Nov 2024, 3:42 PM
Celvien Kurniawan
Celvien Kurniawan - avatar
+ 1
Celvien Kurniawan your poker hand evaluator sparked the idea for this one. The algorithm is one I found online. The crappy gui is something I added for easy user input. https://sololearn.com/compiler-playground/WgB7KhxHx2mf/?ref=app
18th Nov 2024, 6:45 AM
Bob_Li
Bob_Li - avatar
+ 1
Wow. Thank you Bob_Li. Your code is awesome!
19th Nov 2024, 1:47 AM
Celvien Kurniawan
Celvien Kurniawan - avatar
+ 1
Wow. The link you give me is actually using bitwise comparison logic (i hear that it is faster than normal logic comparison) which is very interesting. The efficiency of the bit usage to store multiple information (instead of usual byte) is magnificent there. After reading the article, actually my concept is similar with that web. But the only difference i use integer datatype to store the value (which fortunately save me from quadratic calculation for bit setting). Because i hear that in C, "bit form value creation" (like a=0b00110000) is not supported by default. So to use bit manipulation could be more complex to write. But i have to admit that my variable use in code is somewhat inefficient.
19th Nov 2024, 10:10 AM
Celvien Kurniawan
Celvien Kurniawan - avatar
+ 1
Celvien Kurniawan The fastest way is to store a precomputed lookup table and just look for the answer. So if you really go down the optimization rabbit hole, you can get near instantaneous results...
19th Nov 2024, 10:43 AM
Bob_Li
Bob_Li - avatar
0
in your function "value", add a return 0; to cover the else branch of all your if statements. This fixes the error message and supplies the base return value of your function. int value(int a[]){ ... your codes... //add this before the closing brace return 0; } I also prettified the formatting so it would not be too hard to look at. https://sololearn.com/compiler-playground/cn9K4Opv7O9W/?ref=app
13th Nov 2024, 3:03 PM
Bob_Li
Bob_Li - avatar
0
Ah, i just found out that when i use input: 5S 2S 2H 3S 3C I get a core dump. Also i have updated the code (added some comment in value function to clarify its function process.) Sorry, if my code is hard to understand.
14th Nov 2024, 3:03 AM
Celvien Kurniawan
Celvien Kurniawan - avatar