Skip to content

Instantly share code, notes, and snippets.

@shouc
Last active June 10, 2020 23:53
Show Gist options
  • Save shouc/8ac0617875640399cea787a857cd74e3 to your computer and use it in GitHub Desktop.
Save shouc/8ac0617875640399cea787a857cd74e3 to your computer and use it in GitHub Desktop.
-- Following CCC's algorithm
-- @base + ( @top - @base ) / (1 + (max(0, solves -1)/ 11.92201) ** 1.206069)
CREATE EVENT IF NOT EXISTS `calc_challenges_new_score`
ON SCHEDULE
EVERY 3 SECOND
COMMENT 'Calculate points for challenges'
DO
UPDATE challenges AS c SET c.`point` = CONVERT(c.base_point + (c.top_point - c.base_point) / (1 + POW(GREATEST(c.solved_count - 1, 0) / 11.92201, 1.206069)), UNSIGNED);
CREATE EVENT IF NOT EXISTS `calc_challenges_new_score_for_all_submissions`
ON SCHEDULE
EVERY 3 SECOND
COMMENT 'Update points for each submission'
DO
UPDATE submissions AS s INNER JOIN challenges AS c ON s.challenge_id = c.id SET s.`point` = c.`point`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment