Questions tagged [comparative-review]
This tag is used for questions which present a problem and multiple solutions, where the asker wishes to know which solution is best (and why).
1
vote
1answer
13 views
Leetcode 38: The “count-and-say” sequence
38. Count and Say
The count-and-say sequence is the sequence of integers with the first five terms as following:
...
4
votes
1answer
50 views
Object-Oriented Breadth-First Search Implementation
My goal is to write a GUI application where a user can create a maze and select an algorithm. The passage of the algorithm from a selected start and end point should be visualized.
The following ...
1
vote
1answer
32 views
Making EmployeeHistory ViewModel immutable as code analysis suggested
I want to display on a view the EmployeeHistory view model sorted by elements.assignEffDateNext and I want to instantiate and ...
4
votes
3answers
53 views
Uniformly generate a number from 0 to n-1 that isn't on a blacklist
The task:
Given an integer n and a list of integers l, write a function that
randomly generates a number from 0 to n-1 that isn't in l (uniform).
Solution 1:
...
3
votes
0answers
25 views
Export EXIF data from thousands of images to CSV
I have written a script that retrieves specific fields of Exif data from thousands of images in a directory (including subdirectories) and saves the info to a csv file:
...
1
vote
1answer
57 views
Find out whether string A can be shifted to get string B
The task:
Given two strings A and B, return whether or not A can be shifted some
number of times to get B.
For example, if A is abcde and B is cdeab, return true. If A is abc
and B is acb, ...
-3
votes
1answer
44 views
About the problem of seeking matrix inverse
Recently I have solved the inverse matrix in three ways,
found that their work efficiency has obvious differences.
This is the case:
...
3
votes
5answers
464 views
Finding Isogram Word
An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.
The ...
8
votes
4answers
2k views
Reversing a string - two approaches
Test Case:
Input- "I'm hungry!"
Output- "!yrgnuh m'I"
Approach 1: In this approach, I used a empty string and bind it with the input string reversely.
...
3
votes
0answers
32 views
Basic Qt5 UI with button [closed]
I have the following Qt class:
mainwindow.h
class MainWindow : public QWidget {
Q_OBJECT
QPushButton* m_button;
public:
explicit MainWindow();
};
mainwindow....
1
vote
0answers
28 views
Closest 3Sum in Scala
This question is taken from Leet code.
Given an array nums of n integers and an integer target, find three
integers in nums such that the sum is closest to target. Return the
sum of the three ...
5
votes
1answer
36 views
Mouse control of a camera in an OpenGL program
Introduction
I'm doing an OpenGL program in C. As of now I'm working on the 3D camera system and got the control right. Now I'm working on the mouse control.
It works, but I have used two different ...
2
votes
1answer
90 views
Quiz app with Practice and Exam modes
I am building a Quiz app in swift (my first app) to practice a few skills (using CoreData, working with plists, UIKit etc.) and later to work with a server which stores the Exercises.
Here's my ...
4
votes
1answer
85 views
Bubble sort algorithms and unittest in Python
I am quite new in Python and I am starting my journey with sorting algorithms, PEP8 and the Zen of Python. So far i wrote a post BubbleSort and I drew conclusions and followed the advices. I ...
2
votes
2answers
61 views
Project Euler #10 (sum of primes less than two million) in Clojure
I'm new to Clojure and using some Project Euler problems to familiarize myself with the language's capabilities. Problem #10 asks to find the sum of all primes less than two million.
I wanted to ...
0
votes
1answer
52 views
Binary Reflected Gray Code generation recursively
I tried to write BRGC recursively. I've really recognized that intrinsic of recursion helps for some problems in which I think BRGC is included. is the way I wrote it recursively adequate solution? ...
2
votes
1answer
57 views
Squeezing decorators into functional extensions
When you try to use several decorators it can get ugly pretty quickly and you'll end up with:
...
1
vote
1answer
57 views
Replacing words with their abbreviations - Follow up
This is the follow up for a question you can find here: replacing words with their abbreviations
The goal here is to compare two petential way of answering said question that was:
This particular ...
1
vote
1answer
27 views
Navigation bar React component, with a “back” and a “close” variant
I am working on a component for a navigation bar. This navigation bar currently has two variations: a "back" version, and a "close" version.
I have come up with three different implementations but I ...
-2
votes
1answer
54 views
Build up two linked list, then build up a 3rd link list with nodes of duplicate data from both [closed]
A friend of mines needed some help. He wanted to build up two linked list and then compared them to see if they had the same data values. Finally a 3rd link list would contain the nodes with ...
3
votes
1answer
31 views
Two different styles of testing a custom JSON schema generator
I'm a junior programmer, and I've only been in the industry a couple of months.
One of the aspects that I struggle with most is testing my code. I can write tests, and I can ensure that my code ...
0
votes
1answer
26 views
Implementing carryless multiplication using normal multiplication
In carryless multiplication the partial products are XORed (ie addition without carry) together rather than added normally. The partial products themselves are still the product of a power of two (...
0
votes
1answer
48 views
Five functions to get the digits of a number
I'm writing a simple function: given a number, it will return a sequence or a collection of the digits in the number (in the correct order). i.e ...
2
votes
2answers
104 views
Evaluation of a variation of quick-sort (pivot-selection)
Here is a variation of quick-sort where-in the pivot selection is based on calculating the average of the values of the highest and lowest numbers.
...
3
votes
0answers
68 views
Bridge-Pattern or Entity-Component-System
I want to learn how/when/why to use the GoF Design Patterns. These last days are dedicated to the Bridge Pattern, which means:
Decouple an abstraction from its implementation so that the two can ...
5
votes
1answer
82 views
process data with numpy seems rather slow than pure python?
In my opinion, Vectorization operation with numpy should be much faster than use for in pure python. I write two function to get and process data in a csv file, one in numpy and another in pure python,...
3
votes
2answers
332 views
Word ladders program in Python
Background information: Given two different strings of equal length, the spacing between them is the number of other strings you would need to connect them on a word ladder. Alternately, this is 1 ...
1
vote
2answers
38 views
Lowest open space in memory
I am writing a simple compiled programming language. Everything but the bytecode interpreter can run as slow as possible, but I would like the interpreter to fun fast, because that's why I made it ...
4
votes
5answers
99 views
2
votes
3answers
74 views
Speed up weighted average for Leela Chess Zero
Problem: Given a vector of about 40 values m with normal error sd compute the weighted average of the values weighted by the ...
1
vote
3answers
65 views
Printing a table of letter frequencies using Python
What is the recommended (standard, cleaner, more elegant, etc.) method in Python to get a string with all the alphabet letters?
Here's three versions of code to generate a dictionary with keys as ...
0
votes
1answer
40 views
CodingBat warm up: conditionally prepending “not” to a string
I solved this CodingBat problem:
Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged. Note: ...
2
votes
1answer
81 views
2D Matrix with jagged array isn't faster than one with a multidimensional array
I was trying to use Math.Net's dense matrix class. But, it doesn't support int. So, I have to create a wrapper for a jagged 2d array.
I knew that jagged arrays ...
7
votes
3answers
960 views
Reversible tax calculator class
I have a class that contains 2 properties of the same type. decimal NetAmount and decimal GrossAmount
I would like to ...
3
votes
1answer
82 views
Given a list of words, remove the shorter word of every pair
This is not a "please do my homework" question. I solved a problem two ways and would like to know which solution is better; better being defined by better readability, lower complexity and lower ...
2
votes
1answer
35 views
PHP Factory Pattern : Should I use `create()` or `__invoke()`?
I currently had a colleague reviewing my code and he had a comment on a factory class I created. It's very simple:
...
1
vote
1answer
61 views
Longest Collatz sequence in Scala
I am trying to find the longest Collatz Sequence:
Which starting number, ≤ N, produces the longest chain? If many possible such numbers are there print the maximum one. (1 ≤ N ≤ 5×106)
I tried ...
11
votes
1answer
92 views
Counting times a file was committed to Git
A long time ago I implemented some code to walk the git commit graph. I recently updated the accompanying analytics part of the code base to follow file moves/renames in order to get a more accurate ...
1
vote
2answers
68 views
Classic “100 doors” simulation in Clojure
I read this question about the "100 Doors" puzzle, and thought that it would make for a good quick exercise.
I ended up with two implementations. The first is more straightforward and uses a vector ...
3
votes
2answers
254 views
Image resizing in Rust
Are there Rust features I could apply to optimize for simple test of a JPEG or PNG resized from 2000 x 2000 pixels to 150 x 150 pixels?
...
8
votes
3answers
340 views
Processing player's move in an ASCII rogue-like game
I'm making an ASCII roguelike game and while writing the code for processing the player's move I can't decide between these two options. I have defined a class named ...
1
vote
1answer
30 views
JS/Node.js .env loader
I needed an environment values loader for a random node project, and instead of just using dotenv, decided to just make one myself and see how it'll turn out.
To make this meaningful, here's a rough ...
5
votes
2answers
770 views
Remove the first value for a doubly linked list
You need to remove the first element which contains a given value from a doubly linked list.
I created two solutions since I find the edge case of removing the first element to be problematic. So I ...
2
votes
1answer
290 views
n choose k combination in JavaScript
I was asked to solve a problem for \$\binom{n}{k}\$. I did the following implementation and am wondering if there's any feedback.
Input:
n = Integer
...
1
vote
0answers
51 views
Message loop handler functions, using associative array and using switch
I am using the Windows API to register system-wide hotkeys. This requires a message loop to be created, and a handler to handle the hotkey messages. I have written two pieces of functioning code. The ...
3
votes
3answers
89 views
-2
votes
1answer
64 views
Forward call to method depending on runtime type [closed]
I'm currently trying to build a in-memory read model on application startup. Therefor I use an event store that returns the event data as json. In my read model class there are handler methods for ...
7
votes
4answers
1k views
reinterpret_cast vs bit shifts for extracting 32-bit integers from bytes, with either endianness [closed]
I've written some simple helper functions that read data types from a vector of bytes (binary files) and having a tough time deciding which route to go.
Method 1 : reinterpret_cast
...
4
votes
2answers
75 views
Assigning several variables from request URL using regexes
I refactored some of my code:
Summary: This implementation works with PSGI/Plack. It gets the URL from $env->{PATH_INFO} and assigns a different variable ...
-1
votes
1answer
48 views
Check Unique Chars in A String
Two solutions to check if a String contains unique characters.
Wanted to know if these solutions can be optimized further.
The Code:
...