{"cells":[{"metadata":{"_uuid":"051d70d956493feee0c6d64651c6a088724dca2a","_execution_state":"idle","trusted":true},"cell_type":"code","source":"library(tidyverse) # metapackage of all tidyverse packages\n\nlist.files(path = \"../input\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train<-read_csv('../input//conways-reverse-game-of-life-2020/train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"head(train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"start_cols<-paste0('start_',0:624)\nstop_cols<-paste0('stop_',0:624)\ntrain_df<-as.data.frame(train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"start_one<-matrix(as.numeric(train_df[1,start_cols]),25,25)\nstop_one<-matrix(as.numeric(train_df[1,stop_cols]),25,25)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x_vals<-1:25\ny_vals<-1:25","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x_start_one<-NULL\ny_start_one<-NULL\nfor(i in x_vals) {\n    for(j in y_vals) {\n        if(start_one[i,j]==1) {\n            x_start_one<-c(x_start_one, i)\n            y_start_one<-c(y_start_one, i)\n        }\n        else {\n            x_start_one<-c(x_start_one, 0)\n            y_start_one<-c(y_start_one, 0)\n        }\n    }\n}\n\nx_stop_one<-NULL\ny_stop_one<-NULL\nfor(i in x_vals) {\n    for(j in y_vals) {\n        if(stop_one[i,j]==1) {\n            x_stop_one<-c(x_stop_one, i)\n            y_stop_one<-c(y_stop_one, i)\n        }\n        else {\n            x_stop_one<-c(x_stop_one, 0)\n            y_stop_one<-c(y_stop_one, 0)\n        }\n    }\n}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plot(x_start_one, y_start_one, xlim = c(0,25), ylim = c(0,25))\nplot(x_stop_one, y_stop_one, xlim = c(0,25), ylim = c(0,25))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"f<-function(r=1){\n    start_one<-matrix(as.numeric(train_df[r,start_cols]),25,25)\n    stop_one<-matrix(as.numeric(train_df[r,stop_cols]),25,25)\n    x_vals<-1:25\n    y_vals<-1:25\n    x_start_one<-NULL\n    y_start_one<-NULL\n    for(i in x_vals) {\n        for(j in y_vals) {\n            if(start_one[i,j]==1) {\n                x_start_one<-c(x_start_one, i)\n                y_start_one<-c(y_start_one, j)\n            }\n            else {\n                x_start_one<-c(x_start_one, 0)\n                y_start_one<-c(y_start_one, 0)\n            }\n        }\n    }\n\n    x_stop_one<-NULL\n    y_stop_one<-NULL\n    for(i in x_vals) {\n        for(j in y_vals) {\n            if(stop_one[i,j]==1) {\n                x_stop_one<-c(x_stop_one, i)\n                y_stop_one<-c(y_stop_one, j)\n            }\n            else {\n                x_stop_one<-c(x_stop_one, 0)\n                y_stop_one<-c(y_stop_one, 0)\n            }\n        }\n    }\n\n    color_for_y_stop<-if_else(x_start_one == y_start_one, 'green','blue')\n    par(mfrow=c(1,2))\n    plot(x_start_one, y_start_one, pch=15, col = 'blue', xlim = c(0,25), ylim = c(0,25), main = paste0('Start Move ', r))\n    plot(x_stop_one, y_stop_one, pch=15, col = color_for_y_stop, xlim = c(0,25), ylim = c(0,25), main = paste0('Stop Move ', r))\n        \n}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"f(2020)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"ir","display_name":"R","language":"R"},"language_info":{"name":"R","codemirror_mode":"r","pygments_lexer":"r","mimetype":"text/x-r-source","file_extension":".r","version":"3.6.3"}},"nbformat":4,"nbformat_minor":4}