New answers tagged

1

PEP8 nodeDepths should be node_depths in snake_case. Function naming helper is not a helpful name for a function. If I were to guess what this does, it should maybe be called recurse_node_depths. Instance methods As it stands, BinaryTree does not deserve to have an __init__. It would be better-suited as a @dataclass or maybe a named tuple. That said, it ...


0

Python is not designed for recursion. To avoid stack overflows there is a limit In [2]: import sys In [3]: sys.getrecursionlimit() Out[3]: 1000 So we can easily design a test that will fail In [4]: partition(1000, {1}) --------------------------------------------------------------------------- RecursionError Traceback (most ...


5

Why would you do such a thing? I understand that you wrote the Arithmetic Expression Compiler, and perhaps want to show it off. But who would ever want to write a function as simple as a Fibonacci sequence generater using three programming languages (AEC, Intel assembly, and C++) mixed together, and type way more code than it would take in either C++ or even ...


3

Nested max max(max(L, R), X) can be max((L, R, X)) Actual tests Assert what you're expecting: assert 0 == max_subarray_sum([]) assert 6 == max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) assert 1479 == max_subarray_sum([904, 40, 523, 12, -335, -385, -124, 481, -31])


1

Your code is a pain to read, please add early returns. To go with the point above, please follow PSR-12. iterative tables side by side. Your code creates another table within a , so it's no exactly side by side. Here is how I refactored your code: I completed step 1 and 2. I have broken everything up into methods: <?php namespace App; class ...


3

Compilation Error The first problem is to solve the compiling error. Just follow the interface: public Node<Integer> mergeAscend(Node<Integer> a, Node<Integer> b) Warnings and Code convention You should add the type information to the store_next_a_node variable (and store_next_b_node). Additionally, in Java naming conversion, variable ...


0

All of the endpoints are redundant. If anyone can add anything else I'd still appreciate it. #include <stdio.h> void matrix_addition_partition(size_t n, size_t m, int A[m][m], int B[m][m], int C[n][n], size_t start, size_t end) { for(size_t i = 0; i < m; ++i) { for(size_t j = 0; j < m; ++j) { C[i+start][j+end] = A[i][j] + ...


0

As it happens, there is already an implementation of Karatsuba multiplication in the implementation of BigInteger. Of course that's integer multiplication instead of polynomial multiplication, but they're very similar, apart from how they handle carries. You can read the source here, look for multiplyKaratsuba. It's more of a high-level implementation, ...


2

Welcome to Code Review. I run your code and the game works well, probably there is something you have to adjust about strategy, because it does not always choose the best move to win the match or at least tie. In your code there are some repetitions about method to check if the player or the computer wins like your code below: private static boolean ...


1

functions Your script does a few things iterate over the files recursively iterate over the subdirectories parse the files concatenate the results Better would be to separate those in different functions. The extra advantages is that you can test these functions separately, you can document them with a docstring, and add typing information comments You ...


1

Reduce running time Maybe you can use subList to prevent new lists that are basically a copy of a part of the input? This saves a lot of autoboxing (which I assume is the bottle neck, if the algorithm is implemented correctly). You could profile your application to see where most time is spend. For example: ahigh = a.subList(0,n1); You can initialize ...


Top 50 recent answers are included