-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.rmd
120 lines (86 loc) · 2.71 KB
/
index.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
title: "Syd Competitive Programming 2019 03 23"
output:
html_document
---
```{r setup, include=FALSE, cache=TRUE}
knitr::opts_chunk$set(echo = TRUE)
```
<!-- ## Presentation - Flutter & Dart by Khaled Assaf -->
<!-- <iframe width="560" height="315" src="https://www.youtube.com/embed/mkMpYApWqvI" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> -->
## The leaderboard
```{r add_data, include=FALSE}
library(data.table)
library(magrittr)
library(dplyr)
df = data.table()
num_attendees = 10
add_solution <- function(df, name, prob, bytes, valid) {
rbindlist(
list(
df,
data.table(name = name, prob = prob, bytes = bytes, valid=valid)),
fill = F, use.names = T)
};
df %<>%
add_solution("ZJ", 1, 888,T)
df[,seq := 1:.N]
df[, pts := 0L]
df[, penalty := n_distinct(name), .(prob)]
data.table::fwrite(df, "data_processed.csv")
```
```{r logic2, echo=FALSE, message=FALSE, warning=FALSE}
#
score_submission <- function(probn) {
df2 = copy(df[prob == probn & valid == T,])
# remove duplicates
df2[,min_seq := min(seq), name]
df3 = df2[min_seq == seq,]
df3[order(seq), placing_penaly := 1:.N]
df3[, pts := 2*num_attendees - penalty + 1 - placing_penaly]
df3
}
df_summ = purrr::map_dfr(1:3, ~{
score_submission(.x)
})
df_summ2 = df_summ[,.(pts = sum(pts)), name]
data.table::fwrite(df_summ2, "data_processed_summ.csv")
```
```{r code_golf, include=FALSE}
golf_score = function(probn) {
df_g = df[(valid == T) & (prob == probn), ]
df_g[order(bytes), seq_golf := 1:.N]
df_g2 = df_g
if(nrow(df_g) > 0) {
df_g[, min_seq_golf := min(seq_golf), name]
df_g2 = df_g[min_seq_golf == seq_golf, ]
}
df_g2[order(seq_golf), golf_placing_penaly := 1:.N]
df_g2[, pts_golf := 2*num_attendees - penalty + 1 - golf_placing_penaly]
df_g2[order(seq_golf),]
}
golf_scrs = purrr::map_dfr(1:3, ~golf_score(.x))
golf_scrs[,.(name, pts_golf)]
```
```{r tot, echo=FALSE, message=FALSE, warning=FALSE}
golf_scrs2 = golf_scrs[,.(name, pts = pts_golf)]
df_summ3 = rbindlist(list(df_summ2, golf_scrs2), fill = T, use.names = T)
df_summ4 = df_summ3[,.(pts = sum(pts)), name]
DT::datatable(df_summ4[order(pts, decreasing = T), ])
```
# Points by rank
```{r plot, echo=FALSE, dependson=df_summ2, cache=FALSE}
library(data.table)
df_summ5 = df_summ4[order(pts, decreasing = T), ]
barplot(df_summ5$pts, names.arg = df_summ5$name, cex.names = 0.6)
```
# Points from first to submit
```{r echo=FALSE}
DT::datatable(df_summ2[,.(pts=sum(pts)), name][order(pts, decreasing = T)])
```
# Points from golf
```{r echo=FALSE}
DT::datatable(golf_scrs[,.(name, pts_golf = sum(pts_golf)), name][
order(pts_golf, decreasing = T),
])
```