aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacky Anderson <packy@cpan.org>2025-09-03 00:03:13 -0400
committerPacky Anderson <packy@cpan.org>2025-09-03 00:03:13 -0400
commit8381082e05bb2d6c83fb1aed029f9d5d510c8e17 (patch)
tree8f20c5a8980f44398a83dc8b1f6bc24f1b803136
parent1ce1d1c54343aa2eb7e88d6b30b927e598d4d45b (diff)
downloadperlweeklychallenge-club-8381082e05bb2d6c83fb1aed029f9d5d510c8e17.tar.gz
perlweeklychallenge-club-8381082e05bb2d6c83fb1aed029f9d5d510c8e17.tar.bz2
perlweeklychallenge-club-8381082e05bb2d6c83fb1aed029f9d5d510c8e17.zip
PWC337 - make function names match language preferences
-rwxr-xr-xchallenge-337/packy-anderson/elixir/ch-2.exs36
-rwxr-xr-xchallenge-337/packy-anderson/python/ch-2.py36
2 files changed, 36 insertions, 36 deletions
diff --git a/challenge-337/packy-anderson/elixir/ch-2.exs b/challenge-337/packy-anderson/elixir/ch-2.exs
index e5b1ba9eaf..b9e53e75eb 100755
--- a/challenge-337/packy-anderson/elixir/ch-2.exs
+++ b/challenge-337/packy-anderson/elixir/ch-2.exs
@@ -3,7 +3,7 @@
defmodule PWC do
require Integer # because is_odd is a guard
- def displayTwo(display1, display2) do
+ def display_two(display1, display2) do
Enum.zip_with(
String.split(display1, "\n"),
String.split(display2, "\n"),
@@ -12,7 +12,7 @@ defmodule PWC do
|> Enum.join("\n")
end
- def displayMatrix(label, matrix) do
+ def display_matrix(label, matrix) do
rows = for row <- matrix, do:
"[ " <> Enum.join(row, " ") <> " ] "
width = (length(Enum.at(matrix, 0)) + 2) * 2 + 1
@@ -21,24 +21,24 @@ defmodule PWC do
) <> "\n"
end
- def emptyMatrix(row, col) do
+ def empty_matrix(row, col) do
for _r <- 1..row do
for _c <- 1..col, do: 0
end
end
- def incrementRow(row, matrix) do
+ def increment_row(row, matrix) do
List.replace_at(matrix, row,
(for elem <- Enum.at(matrix, row), do: elem + 1)
)
end
- def incrementCol(col, matrix) do
+ def increment_col(col, matrix) do
for row <- matrix, do:
List.replace_at(row, col, Enum.at(row, col) + 1)
end
- def countOdd(matrix) do
+ def count_odd(matrix) do
{_, count} = Enum.map_reduce(matrix, 0, fn row, count ->
{_, count} = Enum.map_reduce(row, count, fn elem, count ->
{
@@ -56,8 +56,8 @@ defmodule PWC do
def odd_matrix([], matrix, display) do
{
- countOdd(matrix),
- display <> "\n" <> displayMatrix("Final:", matrix)
+ count_odd(matrix),
+ display <> "\n" <> display_matrix("Final:", matrix)
}
end
@@ -65,25 +65,25 @@ defmodule PWC do
{row, col} = {List.first(loc), List.last(loc)}
display = display <> "\nApply [#{row},#{col}]:\n"
display = display <> "Increment row #{row}:\n"
- before_var = displayMatrix("Before", matrix)
- matrix = incrementRow(row, matrix)
- after_var = displayMatrix("After", matrix)
- display = display <> displayTwo(before_var, after_var)
+ before_var = display_matrix("Before", matrix)
+ matrix = increment_row(row, matrix)
+ after_var = display_matrix("After", matrix)
+ display = display <> display_two(before_var, after_var)
display = display <> "Increment col #{col}:\n"
- before_var = displayMatrix("Before", matrix)
- matrix = incrementCol(col, matrix)
- after_var = displayMatrix("After", matrix)
- display = display <> displayTwo(before_var, after_var)
+ before_var = display_matrix("Before", matrix)
+ matrix = increment_col(col, matrix)
+ after_var = display_matrix("After", matrix)
+ display = display <> display_two(before_var, after_var)
odd_matrix(locs, matrix, display)
end
def odd_matrix(row, col, locations) do
- matrix = emptyMatrix(row, col)
+ matrix = empty_matrix(row, col)
odd_matrix(
locations, matrix,
- displayMatrix("Initial:", matrix)
+ display_matrix("Initial:", matrix)
)
end
diff --git a/challenge-337/packy-anderson/python/ch-2.py b/challenge-337/packy-anderson/python/ch-2.py
index 929d78930a..c200df6a7d 100755
--- a/challenge-337/packy-anderson/python/ch-2.py
+++ b/challenge-337/packy-anderson/python/ch-2.py
@@ -1,20 +1,20 @@
#!/usr/bin/env python
-def displayTwo(display1, display2):
+def display_two(display1, display2):
display = []
# split the two strings and join each row together
for d1,d2 in zip(display1.split("\n"), display2.split("\n")):
display.append(d1 + d2)
return "\n".join(display)
-def displayMatrix(label, matrix):
+def display_matrix(label, matrix):
width = (len(matrix[0]) + 2) * 2 + 1
display = label.ljust(width) + "\n"
for r in range(len(matrix)):
display += "[ " + int_join(" ",matrix[r]) + " ] \n"
return display
-def emptyMatrix(row, col):
+def empty_matrix(row, col):
matrix = []
for r in range(row):
matrix.append([])
@@ -22,17 +22,17 @@ def emptyMatrix(row, col):
matrix[r].append(0)
return matrix
-def incrementRow(row, matrix):
+def increment_row(row, matrix):
for col in range(len(matrix[0])):
matrix[row][col] += 1
return matrix
-def incrementCol(col, matrix):
+def increment_col(col, matrix):
for row in range(len(matrix)):
matrix[row][col] += 1
return matrix
-def countOdd(matrix):
+def count_odd(matrix):
count = 0
for row in range(len(matrix)):
for col in range(len(matrix[0])):
@@ -40,26 +40,26 @@ def countOdd(matrix):
return count
def odd_matrix(row, col, locations):
- matrix = emptyMatrix(row, col)
- display = displayMatrix("Initial:", matrix)
+ matrix = empty_matrix(row, col)
+ display = display_matrix("Initial:", matrix)
for row,col in locations:
display += f"\nApply [{row},{col}]:\n"
display += f"Increment row {row}:\n"
- before = displayMatrix("Before", matrix)
- matrix = incrementRow(row, matrix)
- after = displayMatrix("After", matrix)
- display += displayTwo(before, after)
+ before = display_matrix("Before", matrix)
+ matrix = increment_row(row, matrix)
+ after = display_matrix("After", matrix)
+ display += display_two(before, after)
display += f"Increment col {col}:\n"
- before = displayMatrix("Before", matrix)
- matrix = incrementCol(col, matrix)
- after = displayMatrix("After", matrix)
- display += displayTwo(before, after)
+ before = display_matrix("Before", matrix)
+ matrix = increment_col(col, matrix)
+ after = display_matrix("After", matrix)
+ display += display_two(before, after)
display += "\n"
return(
- countOdd(matrix),
- display + displayMatrix('Final:', matrix)
+ count_odd(matrix),
+ display + display_matrix('Final:', matrix)
)
def int_join(joiner, arr):