Mathematical logic betting on the lottery

Asked

Viewed 806 times

1

I can’t think of the mathematical logic of the following issue:

Three friends played the lottery. In case they win, the prize must be apportioned in proportion to the amount each gave for the realization of the bet.

The goal is to make a program that reads the amount each bettor invested and the value of the prize and at the end, inform how much each bettor would win from the prize based on the amount invested.

For ease I have only the draft of the pseudocode.

float aposta1, aposta2, aposta3, premio, recebe1, recebe2, recebe3;
leia aposta1, aposta2, aposta3, premio;

The great difficulty for me is that there is no predefined range of values for betting, thus making it difficult to create the algorithm.

In the algorithm I should instead use very basic content of programming, if possible even without conditional.

  • 2

    If you take how much corresponds in percentage of each bet and at the end, the prize be based on the same percentage, resolves?

  • 2

    total bet = (bet 1 + bet 2 + bet 3); bet 1 is how many percent of (bet total); bet 2 is how many percent of (bet total); bet 3 is how many percent of (bet total); receive 1 = %bet 1 on the prize; receive 2=%bet 2 on the prize; receive 3=%bet 3 on the prize; I made a PHP to test the logic https://ideone.com/MR4Me4

  • Exact @Leocaracciolo. That’s the easy way to do it. Something I wasn’t even able to think about at that moment kkkk. Anyway, in the code you made, you used rule three to find the percentage of each bet, just a little different from what I thought just now, but that, anyway, comes if the problem described is solved. Thank you!!!

2 answers

3


Based on the answers of @David Dias and @Leo Caracciolo, I come to the simple conclusion that a good solution is to do the following:

Make the sum of all amounts wagered, in the form:

apostaTotal = aposta1 + aposta2 + aposta3;

And to find the corresponding percentage, simply split the bet by the total amount of the bet. Example:

porcentagem1 = aposta1 / apostaTotal;

And then, to have the individual prize value is just multiply the prize value by the percentage invested by each bettor.

Below follows the resolution of the question with an example of code written in the language C:

#include <stdio.h>
int main(){
    float aposta1, aposta2, aposta3, premio, p1, p2, p3, apostaTotal, recebe1, recebe2, recebe3;
    scanf("%f%f%f%f",&aposta1, &aposta2, &aposta3, &premio);

    apostaTotal = aposta1 + aposta2 + aposta3;
    p1 = aposta1 / apostaTotal;
    p2 = aposta2 / apostaTotal;
    p3 = aposta3 / apostaTotal;

    recebe1 = premio * p1;
    recebe2 = premio * p2;
    recebe3 = premio * p3;

    printf("\nO apostador 1 recebe: %f\n", recebe1);
    printf("O apostador 2 recebe: %f\n", recebe2);
    printf("O apostador 3 recebe: %f\n", recebe3);
    return 0;
}
  • 1

    Exactly, you simplified the steps in mathematics. I did step by step for better understanding. But it could be simpler still see receivable 1 = (prize * bet 1)/bookTotal; avoiding lines P1, P2, P3 See with PHP in Ideone https://ideone.com/1GNoxD

2

I’d be like this without pseudo code.

  var Premio, Apostador01, Apostador02, Apostador01, ApostadorPc01, ApostadorPc02,ApostadorPc03: float;
  leia  Premio
  leia  Apostador01;
  leia  Apostador02;
  leia  Apostador03;
  Aposta := Apostador01+Apostador02+Apostador03;

  ApostadorPc01  := (Apostador01.Value*100)/Aposta;
  ApostadorPc02  := (Apostador02.Value*100)/Aposta;
  ApostadorPc03  := (Apostador03.Value*100)/Aposta;

  Escreva 'porcentagem do Apostador1'+ ApostadorPc01  +'%';
  Escreva 'porcentagem do Apostador2'+ ApostadorPc02  +'%';
  Escreva 'porcentagem do Apostador3'+ ApostadorPc03  +'%';

  Escreva 'Premio do Apostador1'+ ((Premio*ApostadorPc01)/100);
  Escreva 'Premio do Apostador2'+ ((Premio*ApostadorPc02)/100);
  Escreva 'Premio do Apostador3'+ ((Premio*ApostadorPc03)/100);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.