How to resolve the algorithm World Cup group stage step by step in the Common Lisp programming language
How to resolve the algorithm World Cup group stage step by step in the Common Lisp programming language
Table of Contents
Problem Statement
It's World Cup season (or at least it was when this page was created)! The World Cup is an international football/soccer tournament that happens every 4 years. Countries put their international teams together in the years between tournaments and qualify for the tournament based on their performance in other international games. Once a team has qualified they are put into a group with 3 other teams. For the first part of the World Cup tournament the teams play in "group stage" games where each of the four teams in a group plays all three other teams once. The results of these games determine which teams will move on to the "knockout stage" which is a standard single-elimination tournament. The two teams from each group with the most standings points move on to the knockout stage. Each game can result in a win for one team and a loss for the other team or it can result in a draw/tie for each team.
Don't worry about tiebreakers as they can get complicated. We are basically looking to answer the question "if a team gets x standings points, where can they expect to end up in the group standings?". Hint: there should be no possible way to end up in second place with less than two points as well as no way to end up in first with less than three. Oddly enough, there is no way to get 8 points at all.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm World Cup group stage step by step in the Common Lisp programming language
Source code in the common programming language
(defun histo ()
(let ((scoring (vector 0 1 3))
(histo (list (vector 0 0 0 0 0 0 0 0 0 0) (vector 0 0 0 0 0 0 0 0 0 0)
(vector 0 0 0 0 0 0 0 0 0 0) (vector 0 0 0 0 0 0 0 0 0 0)))
(team-combs (vector '(0 1) '(0 2) '(0 3) '(1 2) '(1 3) '(2 3)))
(single-tupel)
(sum))
; six nested dotimes produces the tupels of the cartesian product of
; six lists like '(0 1 2), but without to store all tuples in a list
(dotimes (x0 3) (dotimes (x1 3) (dotimes (x2 3)
(dotimes (x3 3) (dotimes (x4 3) (dotimes (x5 3)
(setf single-tupel (vector x0 x1 x2 x3 x4 x5))
(setf sum (vector 0 0 0 0))
(dotimes (i (length single-tupel))
(setf (elt sum (first (elt team-combs i)))
(+ (elt sum (first (elt team-combs i)))
(elt scoring (elt single-tupel i))))
(setf (elt sum (second (elt team-combs i)))
(+ (elt sum (second (elt team-combs i)))
(elt scoring (- 2 (elt single-tupel i))))))
(dotimes (i (length (sort sum #'<)))
(setf (elt (nth i histo) (elt sum i))
(1+ (elt (nth i histo) (elt sum i)))))
))))))
(reverse histo)))
; friendly output
(dolist (el (histo))
(dotimes (i (length el))
(format t "~3D " (aref el i)))
(format t "~%"))
You may also check:How to resolve the algorithm Undefined values step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Identity matrix step by step in the Nim programming language
You may also check:How to resolve the algorithm Mandelbrot set step by step in the Dart programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Lua programming language
You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the Frink programming language