forked from marcelkunze/trackml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.h
executable file
·49 lines (43 loc) · 1.26 KB
/
load.h
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
// Minimal header library for progress bars
// The code has been adopted from Johan Sokrates Wind's award winning trackml Kaggle contribution
// Usage:
// for (int i = 0; i < 234; i++) {
// load(234);
// ...
// }
#include <stdio.h>
const int loading_len = 40;
void load_internal(long long a, long long b, const char*title = NULL, int keep_title = 0) {
static long long prev = -1;
long long pb = prev*b*2, x = a*2000+b;
if (a == b) {
if (title) {
for (int i = 0; title[i]; i++)
printf(" ");
}
for (int i = 0; i < loading_len+35+5; i++)
printf(" ");
printf("\r");
fflush(stdout);
if (title && keep_title) {
printf("%s ", title);
fflush(stdout);
}
return;
}
if (pb > x-b*2 && pb <= x) return;
long long p = prev = x/(2*b);
if (title) printf("%s ", title);
printf("|");
int dist = (int)(a*2LL*loading_len+(b>>1))/b;
for (int i = 0; i < dist>>1; i++)
printf("=");
if (dist&1)
printf("-");
for (int i = (dist+1)>>1; i < loading_len; i++)
printf(" ");
printf("| %lld / %lld (%lld.%lld%%)\r", a, b, p/10, p%10);
fflush(stdout);
}
#define GET_FIRST_ARG(n,...) n
#define load(...) {static unsigned int cc = 0; load_internal(++cc, __VA_ARGS__); if (cc == GET_FIRST_ARG(__VA_ARGS__)) cc = 0;}