From 0e5da5a08105ac626778f40f9e65001106e13696 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 03:42:33 +0530 Subject: [PATCH 1/5] hello World #1 --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index adaa6c2..d695ea1 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Goodbye, Mars!' + return 'Hello, World!' From 95931877024fdd8519820db0b0e83f9b8c16a9e0 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 23:48:39 +0530 Subject: [PATCH 2/5] Revert "hello World #1" This reverts commit 0e5da5a08105ac626778f40f9e65001106e13696. --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index d695ea1..adaa6c2 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Hello, World!' + return 'Goodbye, Mars!' From fee9031bef65fca88399e09adaf8966eb639fc09 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 15 Apr 2024 18:19:17 +0530 Subject: [PATCH 3/5] OCR --- .../__pycache__/ocr_numbers.cpython-39.pyc | Bin 0 -> 1811 bytes ...r_numbers_test.cpython-39-pytest-6.2.4.pyc | Bin 0 -> 5031 bytes practice/ocr-numbers/ocr_numbers.py | 25 +++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 practice/ocr-numbers/__pycache__/ocr_numbers.cpython-39.pyc create mode 100644 practice/ocr-numbers/__pycache__/ocr_numbers_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/ocr-numbers/__pycache__/ocr_numbers.cpython-39.pyc b/practice/ocr-numbers/__pycache__/ocr_numbers.cpython-39.pyc new file mode 100644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Nw^mWFhS zWtahBnq^rI!VJr^0)z%DvIz*Y>=c`XFvm`_DG2lI3_A;9ft_RLAuO^B>>`8{Y?^%n z;VE{BU50RyU13)tJk72#6T&HWo!x-&47&+~xD`!2vBi4B-Qps6#)Hr%K(%*aJO$4K zc!G-nZRK|*Bs(DAA7l^4@m592pdD?!q<1uvnjNiewgD)BX_^r!@2gSX3IfpQ(N7Jl zCQy`p66pc2ZSO0h2+7X68(k-zQ?5m=Hr5YDvcq%=W_K_UuD<^zOt?t60{x+4Q zX!z0!sS{9O2Bke_SdPr7kc6n^QE1*5=b@(nyHm6RxlN{sP73c@bd(`au-E_J&U#0O z&y^{$Ev~`%#Z?4p?%82;+kUO#dPf*Md?`2==kV=I2t%uX<2aLb8$QNpvh`uBnb6N+ zt8FE)+DCT$p5c0#&4f9G~zW>^*~NxxGK^`F+~qhua%ME%$Q1F@uDeLW7uf_&6&KrC~V zSmHX2s0E^|R?4fD)ni1Nm7?re0-ONrJ733xPf8F9$J?Qn;NSx4HOqzy_$^u*sn-2b zY9(rS3>oFe9QP@5i(+Z)hQr7CVgZ!zE|BO-GNsLnl3Ky_{$ zs>n^G5e7Cu^9iWVf0Kaf{5VvlH~$o=N@-(N7ZOli_%;F6g_EHwrH!dBCZM|bGy&Dc zv8hVi4@`ii1XPzc5>Q1YFA`8)8G~x;Dmq$l zO0;eyz*4( zmdh!Pa+JD0YrrX&Mg>ao--@_IoC0!U3gIlm6$BIE2Et8*&k#xoUm)B?xQ9?dm_t}V zSVUMsI5-!`82&XNGyt4;0XA$9Lz8#T$QebrR)hN&QJgV literal 0 HcmV?d00001 diff --git a/practice/ocr-numbers/ocr_numbers.py b/practice/ocr-numbers/ocr_numbers.py index 5e20881..ada0d29 100644 --- a/practice/ocr-numbers/ocr_numbers.py +++ b/practice/ocr-numbers/ocr_numbers.py @@ -1,3 +1,26 @@ +def process_section(section, digits): + chunks = [''.join(row[i:i+3] for row in section) for i in range(0, len(section[0]), 3)] + output = [digits.get(chunk, '?') for chunk in chunks] + return ''.join(output) + def convert(input_grid): - pass + digits = { + " _ | ||_| ": "0", + " | | ": "1", + " _ _||_ ": "2", + " _ _| _| ": "3", + " |_| | ": "4", + " _ |_ _| ": "5", + " _ |_ |_| ": "6", + " _ | | ": "7", + " _ |_||_| ": "8", + " _ |_| _| ": "9", + } + + if len(input_grid) % 4 != 0: + raise ValueError("Number of input lines is not a multiple of four") + if any(len(row) % 3 != 0 for row in input_grid): + raise ValueError("Number of input columns is not a multiple of three") + sections = [input_grid[i:i+4] for i in range(0, len(input_grid), 4)] + return ','.join(process_section(section, digits) for section in sections) \ No newline at end of file From 3551848348a934c61cd51e12da3089c14e23f7eb Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 03:11:01 +0530 Subject: [PATCH 4/5] removed cache files --- .../__pycache__/ocr_numbers.cpython-39.pyc | Bin 1811 -> 0 bytes .../ocr_numbers_test.cpython-39-pytest-6.2.4.pyc | Bin 5031 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 practice/ocr-numbers/__pycache__/ocr_numbers.cpython-39.pyc delete mode 100644 practice/ocr-numbers/__pycache__/ocr_numbers_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/ocr-numbers/__pycache__/ocr_numbers.cpython-39.pyc b/practice/ocr-numbers/__pycache__/ocr_numbers.cpython-39.pyc deleted file mode 100644 index 9fb37d24184033eaf26219502701f92ef6257f19..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1811 zcma)6OK%%D5aw|8vSP(<;<$C128*;ksA$~OdGrCpEztB<=n}w(LWQ6%X=Q6^SK+Rj zL|9)U7g3JA_h29WSNaop?aAi?J^0jbs9jgK5TKOE9dd@l;m7%=+i27UTIPSS_opYs zUp$#_5|eMylQj%VC^{5B3MG|?FR9WK(JTjSQ?wF<3Oam=WCz1*+9O3u9@bK!yp*P- zybUqI-ih}Z-vjwtz@p3+nRF|jsvOD8J0^IqwgQ5eqOn{>zm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5=b@(nyHm6RxlN{sP73c@bd(`au-E_J&U#0O z&y^{$Ev~`%#Z?4p?%82;+kUO#dPf*Md?`2==kV=I2t%uX<2aLb8$QNpvh`uBnb6N+ zt8FE)+DCT$p5c0#&4f9G~zW>^*~NxxGK^`F+~qhua%ME%$Q1F@uDeLW7uf_&6&KrC~V zSmHX2s0E^|R?4fD)ni1Nm7?re0-ONrJ733xPf8F9$J?Qn;NSx4HOqzy_$^u*sn-2b zY9(rS3>oFe9QP@5i(+Z)hQr7CVgZ!zE|BO-GNsLnl3Ky_{$ zs>n^G5e7Cu^9iWVf0Kaf{5VvlH~$o=N@-(N7ZOli_%;F6g_EHwrH!dBCZM|bGy&Dc zv8hVi4@`ii1XPzc5>Q1YFA`8)8G~x;Dmq$l zO0;eyz*4( zmdh!Pa+JD0YrrX&Mg>ao--@_IoC0!U3gIlm6$BIE2Et8*&k#xoUm)B?xQ9?dm_t}V zSVUMsI5-!`82&XNGyt4;0XA$9Lz8#T$QebrR)hN&QJgV From f68531c7056eb378b318ec9c3ce4a480cfab0f44 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 16:03:51 +0530 Subject: [PATCH 5/5] improved the code --- practice/ocr-numbers/ocr_numbers.py | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/practice/ocr-numbers/ocr_numbers.py b/practice/ocr-numbers/ocr_numbers.py index ada0d29..f05a28a 100644 --- a/practice/ocr-numbers/ocr_numbers.py +++ b/practice/ocr-numbers/ocr_numbers.py @@ -1,9 +1,47 @@ def process_section(section, digits): + """ + Process a section of the input grid and convert it to a string of digits. + + Args: + section (list): A list of strings representing a section of the input grid. + digits (dict): A dictionary mapping grid patterns to digits. + + Returns: + str: A string of digits representing the section. + + Examples: + >>> process_section([" _ ", "| |", "|_|", " "], digits) + '0' + """ + # Create chunks by joining every three characters in each row of the section chunks = [''.join(row[i:i+3] for row in section) for i in range(0, len(section[0]), 3)] + + # Convert each chunk to a digit (or '?' if the chunk is not recognized) output = [digits.get(chunk, '?') for chunk in chunks] + + # Join the digits into a string and return it return ''.join(output) + def convert(input_grid): + """ + Convert an OCR number grid to a string of digits. + + Args: + input_grid (list): A list of strings representing the OCR number grid. + + Returns: + str: A string of digits representing the OCR number grid. + + Raises: + ValueError: If the number of input lines is not a multiple of four or + if the number of input columns is not a multiple of three. + + Examples: + >>> convert([" _ ", "| |", "|_|", " ", " ", " |", " |", " "]) + '0,1' + """ + # Define the mapping from grid patterns to digits digits = { " _ | ||_| ": "0", " | | ": "1", @@ -17,10 +55,16 @@ def convert(input_grid): " _ |_| _| ": "9", } + # Check if the number of input lines is a multiple of four if len(input_grid) % 4 != 0: raise ValueError("Number of input lines is not a multiple of four") + + # Check if the number of input columns is a multiple of three if any(len(row) % 3 != 0 for row in input_grid): raise ValueError("Number of input columns is not a multiple of three") + # Split the input grid into sections sections = [input_grid[i:i+4] for i in range(0, len(input_grid), 4)] + + # Process each section and join the results with commas return ','.join(process_section(section, digits) for section in sections) \ No newline at end of file