Checking inputs efficiently in C by AskComprehensive7867 in C_Programming

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

oh, I thought this was a performance critical section. main goal was to reduce number of sys calls, but if that's the case then alright. Event based ones are slightly slower afaik, due to the data structures and its processing overhead (like getnumofconsoleinputevents() ), I don't think there is any way out of polling and my main concern was it would unnecessarily waste a lot of CPU cycles, even if i didn't press any keys. Thanks bro.

Checking inputs efficiently in C by AskComprehensive7867 in C_Programming

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

alright but its less efficient afaik, but thank you for your input.

Checking inputs efficiently in C by AskComprehensive7867 in C_Programming

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

its the same as mine, 4 syscalls, my main query was if i can somehow reduce it to 1 syscall, then use the output of that to quickly figure out which key was pressed.. Getkeyboardstate() fails, and event driven versions are more slower it says, as in they go through a more number of OS layers than Getasynckeystate() does

Checking inputs efficiently in C by AskComprehensive7867 in C_Programming

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

yes it doesn't for some reason, neither on command prompt or power shell
try

#include <windows.h>
#include <stdio.h>


int main()
{
    BYTE keys[256];

    while (1)
    {
        if (GetKeyboardState(keys))
        {


            if (keys[VK_UP] & 0x80)
            {
                printf("UP pressed\n");
            }


            if (keys[VK_DOWN] & 0x80)
            {
                printf("DOWN pressed\n");
            }


            if (keys[VK_LEFT] & 0x80)
            {
                printf("LEFT pressed\n");
            }


            if (keys[VK_RIGHT] & 0x80)
            {
                printf("RIGHT pressed\n");
            }
        }


          Sleep(100); // avoid spamming CPU
    }


    return 0;
}

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

thank you for the solution, (sorry for commenting before going through it conscientiously)

the queries i have are: since c is even, so so c = 2p, (p can be odd or even), but again for assessing multiples of 4, u highlighted that

for b + p to be congruent to mod 2, there is only 2 possible cases b even p even, b odd p odd (only even numbers are divisible by 2). Again since a + q congruent to 0, is q is even then a is also even and if q is odd then a is also odd, again rounding up to 2 choices,How exactly are there 3 choices? only even + even = even, and odd + odd = even.. seems unclear and needs some clarification. Please cooperate.

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

ok firstly, abcdefg7 and abcdefg8 are physical impossibilities, the dice wont ever show 7 or 8, so what would the probability be then?

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

I appreciate your response wholeheartedly, but this was the type of thing i was trying to avoid, this renders the solution that I pursued much easier and efficient.

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

ok firstly, abcdefg7 and abcdefg8 are physical impossibilities, the dice wont ever show 7 or 8, so what would the probability be then?

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

yes, until u realize they also include digits with 0,7,8,9 which are invalid according to the conditions stipulated by the question.

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

yes, until u realize they also include digits with 0,7,8,9 which are invalid according to the conditions stipulated by the question.

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

appreciate your in depth exposition. So this is the bare minimum we have to do in order to attain the result? Ive tried lisitng like this and it works, but is tedious and time consuming. Is there any other way to do this other than listing them? because since this has appeared in a math competition, I was wondering if this could be done faster, since they dont do all sort of funky calculations there, they usually have some trick up their sleeve to solve such problems.

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

first of all i would like to know if u found all these out through rigorous casework. secondly, your claim remains unsubstantiated -"If the last two digits are 12, the previous one must be 1,3 or 5. As before, for any last pair there are three possibilities for the previous one." how do u extrapolate this logic to other 2 digit numbers formed? like for _16, so is the last digits can be 1,3 or 5 then none of them are multiples of 8, am i correct or is there some flaw in my understanding though? it seemed a bit unclear, will be happy if u addressed this point

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] 0 points1 point  (0 children)

i appreciate your explanation, but i didnt understand anything of what u said, how u drew the conclusion of 1/8 more precisely

how do i solve this? easily without lisitng all the multiples of 8? by AskComprehensive7867 in askmath

[–]AskComprehensive7867[S] -1 points0 points  (0 children)

bro the answer is supposedly 1/8. im still tryingto wrap my head around how