I wrote this for BitPeople (https://bitpeople.org). I thought for years about how to agree by majority vote on a number in a range of numbers. The classical is to vote for one, and hope others do too. But, anyone sees issue with that. This one "nudges" the result in a direction, and resists change if target is ever reached. I do not know if this is a new idea or if similar solutions have been developed decades ago. It is new to me at least.
mapping (address => uint) public voteToken; uint max; uint result; mapping (uint => uint) votes; uint counter; // Votes in a way that approaches the target _vote, // your vote inches closer to _vote by one, // and resists change once _vote is reached, // changing from positive to negative or vice versa function vote(uint _vote) external { require(_vote <= max); require(voteToken[msg.sender] >= 1); voteToken[msg.sender]--; votes[_vote]+=2; uint res = result; if(_vote > res) { if(counter < votes[res]) counter++; else { require(res < max); result++; counter = 0; } } else if(_vote < res) { if(counter > 0) counter--; else { require(res > 0); result--; counter = votes[res-1]; } } else counter++; }
[link] [comments]
You can get bonuses upto $100 FREE BONUS when you:
π° Install these recommended apps:
π² SocialGood - 100% Crypto Back on Everyday Shopping
π² xPortal - The DeFi For The Next Billion
π² CryptoTab Browser - Lightweight, fast, and ready to mine!
π° Register on these recommended exchanges:
π‘ Binanceπ‘ Bitfinexπ‘ Bitmartπ‘ Bittrexπ‘ Bitget
π‘ CoinExπ‘ Crypto.comπ‘ Gate.ioπ‘ Huobiπ‘ Kucoin.
Comments