diff --git a/README.md b/README.md index 879449ec..db467aed 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,27 @@ ## Git Training ##### Don't think about git, just do git ! -##### (Based on a scenario; c programming with Git (Knapsack problem)) +##### (Based on a scenario; c programming with Git (Report card, Knapsack problem)) ### Training Environment -1. Download [tutorial](https://www.dropbox.com/s/0bplreunw6vf69p/Git-training.pdf?dl=1&pv=1) & [example code for this scenario](https://www.dropbox.com/sh/9q2emkhxmyckoj6/AAA_H55BVhfRvGHOs9j7l9N2a?dl=1&pv=1) +1. Download tutorial + - [tutorial v3](https://www.dropbox.com/s/jwpkfn5c8d1z74y/Git-training-v3.pdf?dl=1&pv=1) + - [tutorial v2](https://www.dropbox.com/s/6o5sfs1iyd9cxdq/Git-training-v2.pdf?dl=1&pv=1) & [example code v2](https://www.dropbox.com/sh/3ywkargf9xzcfoi/AAC63uvN4eQBQhT_1m4GmCMLa?dl=1&pv=1) + - [tutorial v1](https://www.dropbox.com/s/0bplreunw6vf69p/Git-training.pdf?dl=1&pv=1) & [example code v1](https://www.dropbox.com/sh/9q2emkhxmyckoj6/AAA_H55BVhfRvGHOs9j7l9N2a?dl=1&pv=1) 2. Install Git ([git](https://git-scm.com/downloads), [source tree](https://www.sourcetreeapp.com)) 3. Editor ([atom](https://atom.io/), [sublime text](https://www.sublimetext.com/3)) 4. Github account ([sign up](https://github.com/join)) 5. Download [the courage](https://www.dropbox.com/s/36ifeasvhhshqj8/you_can_do_git?dl=1&pv=1) ### Stage -1. Basic : Stage 1 ~ 10 -2. Advanced : Stage 11 ~ 14 +1. New version (v2) + - Basic : Stage 1 ~ 7 + - Advanced : Stage 8 ~ 11 -### The results +2. Old version (v1) + - Basic : Stage 1 ~ 10 + - Advanced : Stage 11 ~ 14 + +### The results (v1) ![screenshot](img/results_20160327.png) [git-training.docs.google](https://docs.google.com/spreadsheets/d/1uPMCOKISMgj_svsoxG1LF1RbozA9RMKfx7h9vT80Atc/edit#gid=0) \ No newline at end of file diff --git a/packing_knapsack/generator_test_script.py b/packing_knapsack/generator_test_script.py new file mode 100644 index 00000000..7a792299 --- /dev/null +++ b/packing_knapsack/generator_test_script.py @@ -0,0 +1,22 @@ +#!/bin/python +import random + +test_script = open("test.sh","w") + +test_script.write("#!/bin/bash\n") +test_script.write("echo -e \"") + +nr = random.randrange(1,1000) +w = random.randrange(1,10000) + +test_script.write(str(nr)+" "+str(w)+"\\n\\\n") + + +for i in range(1,nr-1): + j_p = random.randrange(1,w) + j_w = random.randrange(1,w) + test_script.write(str(j_p)+" "+str(j_w)+"\\n\\\n") + +j_p = random.randrange(1,w) +j_w = random.randrange(1,w) +test_script.write(str(j_p)+" "+str(j_w)+"\\n\" | ./a.out") diff --git a/packing_knapsack/knapsack_problem.pdf b/packing_knapsack/knapsack_problem.pdf new file mode 100644 index 00000000..0949b30f Binary files /dev/null and b/packing_knapsack/knapsack_problem.pdf differ diff --git a/packing_knapsack/packing_knapsack.c b/packing_knapsack/packing_knapsack.c new file mode 100644 index 00000000..debdfbb0 --- /dev/null +++ b/packing_knapsack/packing_knapsack.c @@ -0,0 +1,115 @@ +/* + * Packing knapsack question + * + * Copyright (C) 2016, Taeung Song + * + */ +#include +#include +#include +#include + +#define MAX_INPUT 16 + +struct knapsack { + unsigned int maxprice; +} *knapsack_list; + +struct jewelry { + unsigned int wgt; + unsigned int price; +}; + +unsigned int limited_wgt; + +unsigned int get_cond_maxprice(int wgt, struct jewelry *jewelry) +{ + /* Get maximum price based on a specific weight + * following a specific jewelry. + */ + int i; + int rest_wgt = wgt - jewelry->wgt; + int price = jewelry->price + knapsack_list[rest_wgt].maxprice; + + return knapsack_list[wgt].maxprice < price ? + price : knapsack_list[wgt].maxprice; +} + +void pack_knapsack(struct jewelry *jewelry) +{ + /* Case by case pack knapsack following maximum + * price per limited weight. + */ + int wgt; + + if (limited_wgt < jewelry->wgt) + return; + + for (wgt = 0; wgt <= limited_wgt; wgt++) { + if (jewelry->wgt <= wgt) { + unsigned int maxprice = get_cond_maxprice(wgt, jewelry); + + if (knapsack_list[wgt].maxprice < maxprice) + knapsack_list[wgt].maxprice = maxprice; + } + } +} + +bool get_values_from(char *input, unsigned int *val1, unsigned int *val2) +{ + char *arg; + char *ptr = strdup(input); + + if (!ptr) { + printf("%s: strdup failed\n", __func__); + exit(1); + } + + arg = strsep(&ptr, " "); + *val1 = atoi(arg); + if (ptr == NULL) { + printf("Error: Need a whitespace\n"); + return false; + } + + *val2 = atoi(ptr); + + return true; +} + +int main(int argc, const char **argv) +{ + int i; + struct jewelry *jewels; + char input[MAX_INPUT]; + unsigned int nr_jewels; + + fgets(input, sizeof(input), stdin); + if (get_values_from(input, &nr_jewels, &limited_wgt) == false) + return -1; + + jewels = malloc(sizeof(struct jewelry) * nr_jewels); + for (i = 0; i < nr_jewels; i++) { + bool ret; + + fgets(input, sizeof(input), stdin); + ret = get_values_from(input, &jewels[i].wgt, + &jewels[i].price); + if (ret == false) + return -1; + } + + /* from 0 to last limited weight */ + knapsack_list = malloc(sizeof(struct knapsack) * (limited_wgt + 1)); + + for (i = 0; i <= limited_wgt; i++) + knapsack_list[i].maxprice = 0; + + for (i = 0; i < nr_jewels; i++) + pack_knapsack(&jewels[i]); + + printf("%d\n", knapsack_list[limited_wgt].maxprice); + free(jewels); + free(knapsack_list); + return 0; +} diff --git a/packing_knapsack/test.sh b/packing_knapsack/test.sh new file mode 100755 index 00000000..e54bd882 --- /dev/null +++ b/packing_knapsack/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo -e "4 14\n\ +2 40\n\ +5 110\n\ +10 200\n\ +3 50\n" | ./$1 diff --git a/pull_reqeust_test/taeung/packing_knapsack/generator_test_script.py b/pull_reqeust_test/taeung/packing_knapsack/generator_test_script.py new file mode 100644 index 00000000..7a792299 --- /dev/null +++ b/pull_reqeust_test/taeung/packing_knapsack/generator_test_script.py @@ -0,0 +1,22 @@ +#!/bin/python +import random + +test_script = open("test.sh","w") + +test_script.write("#!/bin/bash\n") +test_script.write("echo -e \"") + +nr = random.randrange(1,1000) +w = random.randrange(1,10000) + +test_script.write(str(nr)+" "+str(w)+"\\n\\\n") + + +for i in range(1,nr-1): + j_p = random.randrange(1,w) + j_w = random.randrange(1,w) + test_script.write(str(j_p)+" "+str(j_w)+"\\n\\\n") + +j_p = random.randrange(1,w) +j_w = random.randrange(1,w) +test_script.write(str(j_p)+" "+str(j_w)+"\\n\" | ./a.out") diff --git a/pull_reqeust_test/taeung/packing_knapsack/knapsack_problem.pdf b/pull_reqeust_test/taeung/packing_knapsack/knapsack_problem.pdf new file mode 100644 index 00000000..0949b30f Binary files /dev/null and b/pull_reqeust_test/taeung/packing_knapsack/knapsack_problem.pdf differ diff --git a/pull_reqeust_test/taeung/packing_knapsack/packing_knapsack.c b/pull_reqeust_test/taeung/packing_knapsack/packing_knapsack.c new file mode 100644 index 00000000..debdfbb0 --- /dev/null +++ b/pull_reqeust_test/taeung/packing_knapsack/packing_knapsack.c @@ -0,0 +1,115 @@ +/* + * Packing knapsack question + * + * Copyright (C) 2016, Taeung Song + * + */ +#include +#include +#include +#include + +#define MAX_INPUT 16 + +struct knapsack { + unsigned int maxprice; +} *knapsack_list; + +struct jewelry { + unsigned int wgt; + unsigned int price; +}; + +unsigned int limited_wgt; + +unsigned int get_cond_maxprice(int wgt, struct jewelry *jewelry) +{ + /* Get maximum price based on a specific weight + * following a specific jewelry. + */ + int i; + int rest_wgt = wgt - jewelry->wgt; + int price = jewelry->price + knapsack_list[rest_wgt].maxprice; + + return knapsack_list[wgt].maxprice < price ? + price : knapsack_list[wgt].maxprice; +} + +void pack_knapsack(struct jewelry *jewelry) +{ + /* Case by case pack knapsack following maximum + * price per limited weight. + */ + int wgt; + + if (limited_wgt < jewelry->wgt) + return; + + for (wgt = 0; wgt <= limited_wgt; wgt++) { + if (jewelry->wgt <= wgt) { + unsigned int maxprice = get_cond_maxprice(wgt, jewelry); + + if (knapsack_list[wgt].maxprice < maxprice) + knapsack_list[wgt].maxprice = maxprice; + } + } +} + +bool get_values_from(char *input, unsigned int *val1, unsigned int *val2) +{ + char *arg; + char *ptr = strdup(input); + + if (!ptr) { + printf("%s: strdup failed\n", __func__); + exit(1); + } + + arg = strsep(&ptr, " "); + *val1 = atoi(arg); + if (ptr == NULL) { + printf("Error: Need a whitespace\n"); + return false; + } + + *val2 = atoi(ptr); + + return true; +} + +int main(int argc, const char **argv) +{ + int i; + struct jewelry *jewels; + char input[MAX_INPUT]; + unsigned int nr_jewels; + + fgets(input, sizeof(input), stdin); + if (get_values_from(input, &nr_jewels, &limited_wgt) == false) + return -1; + + jewels = malloc(sizeof(struct jewelry) * nr_jewels); + for (i = 0; i < nr_jewels; i++) { + bool ret; + + fgets(input, sizeof(input), stdin); + ret = get_values_from(input, &jewels[i].wgt, + &jewels[i].price); + if (ret == false) + return -1; + } + + /* from 0 to last limited weight */ + knapsack_list = malloc(sizeof(struct knapsack) * (limited_wgt + 1)); + + for (i = 0; i <= limited_wgt; i++) + knapsack_list[i].maxprice = 0; + + for (i = 0; i < nr_jewels; i++) + pack_knapsack(&jewels[i]); + + printf("%d\n", knapsack_list[limited_wgt].maxprice); + free(jewels); + free(knapsack_list); + return 0; +} diff --git a/pull_reqeust_test/taeung/packing_knapsack/test.sh b/pull_reqeust_test/taeung/packing_knapsack/test.sh new file mode 100755 index 00000000..e54bd882 --- /dev/null +++ b/pull_reqeust_test/taeung/packing_knapsack/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo -e "4 14\n\ +2 40\n\ +5 110\n\ +10 200\n\ +3 50\n" | ./$1 diff --git a/pull_request_test/JangJieun/README.md b/pull_request_test/JangJieun/README.md new file mode 100644 index 00000000..617a08e7 Binary files /dev/null and b/pull_request_test/JangJieun/README.md differ