From 6a26a4026d2327150d559efb616999e9c31911c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Korpesio?= Date: Wed, 19 Jan 2022 23:23:25 +0100 Subject: [PATCH] prvy --- sk1a/main.o | Bin 7496 -> 7496 bytes sk1a/maze.c | 40 ++-------------------------------------- sk1a/maze.o | Bin 9304 -> 7264 bytes sk1a/program | Bin 22312 -> 21864 bytes sk1a/readme.md | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 38 deletions(-) create mode 100644 sk1a/readme.md diff --git a/sk1a/main.o b/sk1a/main.o index 18d8162ed1880c83b104d847134819ae136d4ff8..6366a96a21df6f3018be3711299146a7435f5d0b 100644 GIT binary patch delta 126 zcmX?Mb;4=`Go!RZg+khK*HsD($6ePbC@53_IU7KnO$rK|vHm;3{Hf zU|^m&p int issafe(char* maze, int x, int y, int size) { - if ((x >= 0 && x < size) && (y >= 0 && y < size) && maze[x * size + y] == ' '){ + if ((x >= 0 && x < size) && (y >= 0 && y < size) && (maze[x * size + y] == ' ')){ return 1; } return 0; @@ -37,41 +37,5 @@ int backtracking(char* maze, int x, int y, int size){ } int solve_maze(char* maze, int size) { - if (maze[0] == '*'){ - assert(maze[0] == '*'); - maze[0] = ' '; - } - int x,y = 0; - while(x * size + y <= size*size - 1 ){ - printf("%d\n%d", x * size + y, y); - //issafe(maze, x, y, size); - if (maze[x * size + y + 1] == ' ' /*&& y != 5*/){ - assert(maze[x * size + y + 1] == ' '); - maze[x * size + y + 1] = '*'; - y++; - - } - if (maze[(x + 1) * size + y] == ' ' /*&& x != 5*/){ - assert(maze[(x + 1) * size + y] == ' '); - maze[(x + 1) * size + y] = '*'; - x++; - - } - if (maze[x * size + y - 1] == ' ' && y != 0){ - assert(maze[x * size + y - 1] == ' '); - maze[x * size + y - 1] = '*'; - y--; - - } - if (maze[(x - 1) * size + y] == ' ' /*&& x != 0*/){ - assert(maze[(x - 1) * size + y] == ' '); - maze[(x - 1) * size + y] = '*'; - x--; - - } - else{ - backtracking(maze,x , y, size); - } - } -return 1; + return backtracking(maze, 0, 0, size); } diff --git a/sk1a/maze.o b/sk1a/maze.o index 1f464dfbb19ff650b6bdf61c7c230c619a61376f..2f07d752fe17ffbff9994cd1bb1908352e444997 100644 GIT binary patch delta 2354 zcmZvdZ)hA<5WwH=-QMk8?k?Tk z3Q^Q1BEd5Rt`0~9+lu(5MWit(qN2oNYeDTls0E>zwjc7rqJc__mFmpC*>HViU~k@= z`MsHWZ{N*cEdRc~y3)@!^cncm^a^h* zVaW_*_NdU3MTTtXisdv124kHmazt`Vj)~Z9%Mc;6x9vQYb|A4}+fdj6yg(5BJ z(lw|M*LePzV!z52KcU!7SmfGPv1hkJoQ6V1R==Hdjw!@e7-Hf!XE~%0S7DrqZS46{ zA%2A!CSGCBIfeKb=9&18v;3hD4}+DJm2TonBTNS8{3P@D87#}Ib=dhzmR(Xo+ z_@Ik%PSJ0&$WoY0^zZBqCU$JwpegZTRu`wdOVf9N|(0!m79 zP+1TpIHA~s1VLY-4Hz)h@&#;ey+$p)*IR4-Nc|9{DwVKd-0RZU>DYzslUJ&p z4tfb=EwUOcT26c&@9jbe{_%?a)JOX`P@o>CmWndUW!N}2@S(O&g5MZlHsY@gnq)FX z6}B4GE__F;%&{-~N#U3i9$qf6 zNaG5WplS+C=c)$Yhc>zxK>;}Q7pB`X kjb>7srYSgzgHH;6XzPf5$oHz<-$J5Piao_qz7F2r|IK|C3;+NC literal 9304 zcmb_idu&_P89&#~v7LwW?jy7-F3_eg+ezsoX`2!n+$N>3L9?~A<<_yU6H~_yzW0W- zTL)_fYOtcE65G0|V`WSl+A6^wn!1OkLI7%~Bn2c{LM|^Tv^!a|lguWw$OknGKJ4ut z`&;+e(Wx=}`dII^vF($iN3WBS4Y|nm^^wV=t45DrBO{?)k;q|hC^H1=V4 zLEo<6J|?)8@ga?SQryT4q`=eo(DY4ZKowk0&+JlUGca@10hZ{CYND@>*;l~&Rh*P% zc5A+A-P%3w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(gk6*y`JIi1+}RHcJtpdwF-s$7)d%DmB&zxD+XBIT6d2CsTw@(Q8bUMjWOq%jy{SZDJJk=K3}EMzvo*6MafzaN Ul}O9;jIS+KxVtbpvvktG0pokml>h($ diff --git a/sk1a/readme.md b/sk1a/readme.md new file mode 100644 index 0000000..021a40a --- /dev/null +++ b/sk1a/readme.md @@ -0,0 +1,41 @@ +#include +#include +#include "maze.h" +#include + +int issafe(char* maze, int x, int y, int size) { +if ((x >= 0 && x < size) && (y >= 0 && y < size) && (maze[x * size + y] == ' ')){ +return 1; +} +return 0; +} + +int backtracking(char* maze, int x, int y, int size){ +if(x == size - 1 && y == size - 1 && maze[x * size + y] == ' '){ +maze[x * size + y] = '*'; +return 1; +} + + if(issafe(maze, x, y, size) == 1) { + maze[x * size + y] = '*'; + + if (backtracking(maze, x, y + 1, size) == 1) { + return 1; + } + if (backtracking(maze, x + 1, y, size) == 1) { + return 1; + } + if (backtracking(maze, x - 1, y, size) == 1) { + return 1; + } + if (backtracking(maze, x, y - 1, size) == 1) { + return 1; + } + maze[x * size + y] = ' '; + } + return 0; +} + +int solve_maze(char* maze, int size) { +return backtracking(maze, 0, 0, size); +} \ No newline at end of file