Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Voting.sol: Gas Optimizations #307

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Level1/BingoDecentrailized/Voting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ contract voting{
//Voter[] public voters;
mapping(uint=>address) voters;
mapping(address=>bool) voted;
uint public len=0;
uint public sum=0;
uint public len;
uint public sum;
uint public candidate_winner;
uint public winner;

Expand All @@ -35,9 +35,9 @@ contract voting{

//Winner of Each round can be seen
function findWinner() private{
uint max=0;
uint max;

for(uint i=0;i<25;i++){
for(uint i; i<25; ++i){
if(freq[i]>max){
max=freq[i];
winner=i+1;
Expand All @@ -49,11 +49,11 @@ contract voting{

//Restart a round
function reset() private{
for(uint i=0;i<len;i++){
for(uint i; i<len; ++i){
voted[voters[i]]=false;
}

for(uint i=0;i<25;i++) freq[i]=0;
for(uint i; i<25; ++i) freq[i]=0;
}

//Vote for cross out (with error handling)
Expand All @@ -77,4 +77,4 @@ contract voting{
}
}

}
}
Loading