From 35adb782583a35b0ae54e249d33474a584a00c95 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Thu, 10 Sep 2020 23:28:07 +0200 Subject: 77-2 in Python 3 --- challenge-077/ash/python/ch-2.py | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 challenge-077/ash/python/ch-2.py diff --git a/challenge-077/ash/python/ch-2.py b/challenge-077/ash/python/ch-2.py new file mode 100644 index 0000000000..d5b7b5e506 --- /dev/null +++ b/challenge-077/ash/python/ch-2.py @@ -0,0 +1,42 @@ +# Task 2 from +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-077/ + +# Comments: https://andrewshitov.com/2020/09/08/lonely-x-the-weekly-challenge-77-task-2/ + +# Output for the given example: +# +# $ python3 ch-2.py +# Lonely X at position (0, 0). +# Lonely X at position (2, 1). +# Lonely X at position (0, 2). + +matrix = [ + ['X', 'O', 'O'], + ['O', 'O', 'X'], + ['X', 'O', 'O'], +] + +def is_O_cell(x, y): + if 0 <= x < len(matrix[0]) and 0 <= y < len(matrix): + return matrix[y][x] == 'O' + else: + return True + +x_cells = [ + [col_i, row_i] + for row_i, row in enumerate(matrix) + for col_i, cell in enumerate(row) + if cell == 'X' +] + +for x_cell in x_cells: + x, y = x_cell + if is_O_cell(x , y + 1) and \ + is_O_cell(x , y - 1) and \ + is_O_cell(x + 1, y ) and \ + is_O_cell(x - 1, y ) and \ + is_O_cell(x + 1, y + 1) and \ + is_O_cell(x + 1, y - 1) and \ + is_O_cell(x - 1, y + 1) and \ + is_O_cell(x - 1, y - 1): + print(f"Lonely X at position ({x}, {y}).") -- cgit From b84595a43e09b00411ae617ee297912a14084da7 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Fri, 11 Sep 2020 00:10:16 +0200 Subject: An HTML+JS visual solution for 77-2 --- challenge-077/ash/javascript/ch-2.html | 107 +++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 challenge-077/ash/javascript/ch-2.html diff --git a/challenge-077/ash/javascript/ch-2.html b/challenge-077/ash/javascript/ch-2.html new file mode 100644 index 0000000000..e2cfd19d28 --- /dev/null +++ b/challenge-077/ash/javascript/ch-2.html @@ -0,0 +1,107 @@ + + + + + + + Lonely X + + + +

+ + × + +   + +

+ +
+ +

Note: Lonely X is marked green.

+ + + + -- cgit From c53084b39a60d87ef29009092d54d151f528dfc0 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Fri, 11 Sep 2020 00:15:00 +0200 Subject: 77-2 solution in HTML+JS --- challenge-077/ash/javascript/ch-2.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/challenge-077/ash/javascript/ch-2.html b/challenge-077/ash/javascript/ch-2.html index e2cfd19d28..3b1cd76bb6 100644 --- a/challenge-077/ash/javascript/ch-2.html +++ b/challenge-077/ash/javascript/ch-2.html @@ -19,13 +19,12 @@ margin: auto; /* border-collapse: collapse; */ } - #Shape table tr td input { + /* #Shape table tr td input { width: 50px; height: 50px; - } + } */ #Shape table tr td { - border: 5px solid white; - + border: 5px solid white; } #Shape table tr td.lonely { border: 5px solid green; -- cgit