I am writing a code that takes two numbers N and M and finds the greatest result of A mod M for all the numbers of A in the range 1,2,3,...,N-1,N.
1 ≤ N,M ≤ 10^9
My code is:
public static void main(String[] args) throws IOException {
long n=readLong(), m=readLong(), a=Integer.MIN_VALUE;
...
I've been writing a tutorial for neural networks and every time I come across my neural network initialization function, I wonder if my use of nested functions is inappropriate and broader, if nested functions are ever appropriate.
def initialize_network(n, h, o):
"""Neural network initializ...
Python script that can downloads public and private profiles images and videos, like Gallery with photos or videos. It saves the data in the folder.
How it works:
Log in in instragram using selenium and navigate to the profile
Checking the availability of Instagram profile if it's private or e...
Define the is_legitimate_date() function which is passed a string as
a parameter. The function returns a boolean indicating whether the string
denotes a legitimate date.
You are given 2 global variables which you may use in your solution:
MONTH_NAMES is a list of month names, and
DAYS_IN_MONTH ...
I've just finished one of my first projects with a GUI using PyQt5 and I recreated mastermind the board game. The game is played by inputting 4 numbers and getting a return of how many of the numbers are in the code but in the wrong spot and how many numbers are correct (a random 4 digit combo b...
if you reformulate the answer in your post as something like 'I tried the following script, but the problem is that I have to specify the branches every time', it fits in the SO Q&A format. Currently, you are leaving it up to us to determine what needs improvement, making it better suited for codereview.stackexchange.com — TamaMcGlinn11 secs ago
Once you have this running, submit it at codereview.stackexchange.com. There are several things bad in your code. — Ulrich Eckhardt1 min ago
@Peilonrayz @SᴀᴍOnᴇᴌᴀ Pasting code that's hosted elsewhere has legality issues, hence we don't do that. We'd be forcing SE's licensing model on code and most of us don't have the expertise to figure out whether that's a) permissible b) legal c) a good idea. Often enough it's neither.
Turning existing code already included in the question itself into a snippet should be fine since the code is already under SE by then.
But honestly, if that hadn't been accepted by the OP himself, I'd have been tempted to rollback or at least leave a comment stating the possibility if preferred.
What I mean is if the time.Sleep is not so apparently like the code above, and it's hard to find it out by code review. How can I find it by using profiling tool (pprof) or something else. — chanjarster24 secs ago
@Zer0 Absolutely not, since the actual code is missing. This is too much turned into an example. Perhaps if a site like Design Review would exist (and thus, perhaps Programmers would take it), but it's absolutely unsuitable for Code Review. — Mast28 secs ago
Apologies for the day 1 basic question, I'm just trying to build a simple tool that searches the same query across multiple sites.
However some sites have a string that needs to be entered after the query for the URL to be recognised.
if selection =='1':
webbrowser.open('http://goog...
I am following tutorial from GameProgrammingPattern book. I tried to create an object pool using it. I want to know how can I improve it. Its an fixed size pool so there will not be any runtime increase or decrease in pool size.
Coin.h
#pragma once
class Coin
{
public:
Coin();
~Coin();...
@brunodesthuilliers the question is not about proper exception handling and I make no claim about my solution being correct in terms of "proper" exception handling, since that's way off-topic. The OP wants to know why his exception is cancelled away, and I explain this providing an example of how to fix this. Delving into the possible fallacies of the OP's code is for codereview.stackexchange.com, not SO. — GPhilo15 secs ago
@brunodesthuilliers Added a warning for further users. As per "good answers should go past the simple technical answer by mentioning bad and good practices, possible improvements etc.", I disagree. An answer must focus on the posed question, not on all possible fallacies therein. If the OP is interested in a code review, again, there are better-suited places for that. — GPhilo15 secs ago
Not really an issue I am stuck on (the code works) but I just really don't like some code I wrote, if you're bored in lockdown maybe you might like to help.
Context:
I am import some data from a spreadsheet, it contains data about retail stores (grocery stores). As the data comes in from the spr...
For my first solo React exercise project I decided to recreate a quote machine from the example that uses vanilla JS/jQuery. I also used a mix of Bootstrap/plain CSS. I got it to look how I wanted and do what I wanted, but I am not sure if my code follows best practices. All feedback is much appr...
I still don't understand why people teach how to write C code in C++. You won't pass any serious code review. You are learning how to write legacy code. I understand that it makes sense to know about these language elements but you shouldn't start with it. — Thomas Sablik27 secs ago
@Vitaliy Well now we are in 2020 and I currently have IntelliJ IDEA 2019.3.4 (Community Edition) Build #IC-193.6911.18, built on March 17, 2020 Runtime version: 11.0.6+8-b520.43 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.15.4 GC: ParNew, ConcurrentMarkSweep Memory: 1979M Cores: 12 Registry: Non-Bundled Plugins: BashSupport, CheckStyle-IDEA, DBN, codeReview4idea, com.andrey4623.rainbowcsv, com.godwin.json.parser, net.seesharpsoft.intellij.plugins.csv, training — Nitin Ramac32 secs ago
What is the most effective way of implementing the binary exponentiation in python? This is my approach
def quad_pow(base, exponent, modul):
alpha = (bin(exponent).replace('0b', ''))[::-1]
a = 1
b = base
for i in range(0, len(alpha)):
if int(alph...
I tried to programm the extended euclidean algorithm from scratch. Is this a good aproach? Any feedback is welcome.
def ext_ggT(a, b):
x,y, u,v = 0,1, 1,0
while a != 0:
q, r = b//a, b%a
m, n = x-u*q, y-v*q
b,a, x,y, u,v = a,r, u,v, m,n
...
I've been wondering what is the preferred way of injecting dependencies in node.js code.
I've been working on a project where there is no dependency injection. This is why i have 2 ways of providing dependencies in my code:
through constructor/function arguments - this has the disadvantage of...
I've started creating views Programmatically and I am not sure if I am doing it right.
My questions are at the bottom.
I got a working Login View via the following code:
import UIKit
import Moya
import SnapKit
class LoginViewController: UIViewController {
let provider = MoyaProvider<Api>(...
I am modelling a user preference system with the following requirements
a user can have attributes (foods they eat)
a user can have dynamic categories of preferences
users which have all their categories with at least one intersect can match
So far I have used Postgres's arrays to build a sy...
I'm wondering if there is any way to clean up this c# structure. I feel like it is a bit messy...Is it possible to accomplish the same functionality but without all the nested code.
class Display {
private byte option { get; set; }
public void init()
{
while (true)
...
how can I improve this question of mine?
I already edited it, and I already set a bounty to get more attention, but I still don't get many answers.
Is there something significantly wrong with this question?
I would appreciate any suggestions.
@Mast I find what qualifies a great question comes down to the non-code part of the question. I don't think askers realize that it plays a vital role in getting people engaged in the question.
I have implemented the Simpson's rule for numerical integration.
Check this video for the implemented function.
namespace Simpsons_method_of_integration
{
//https://www.youtube.com/watch?v=ns3k-Lz7qWU
using System;
public class Simpson
{
private double Function(double ...
I am developing an application in which the user can use different measurement systems. Currently,
there is support for the metric and imperial measurement systems. To support these systems, I wrote a converter. Could you take a look at its code and tell how can it be improved and what are the p...
@Peilonrayz I think a lot of askers don't realize a lot of things we consider common sense when asking questions or we wouldn't be closing so many questions.
@CaptainObvious Although I'm not sure why that got downvoted. Am I missing something?
Unfriendly comments are an issue in our system because of the effect that their tone has on their recipient’s and future readers’ willingness to contribute to Stack Overflow. The solution to these issues isn’t to argue about circumstance or intent. The only remaining option is to work on the comments themselves.
I tried to generate perfect numbers from 2 up to 500 with some simple "for loops" (which I've learned recently) in Python 3 and I've faced a wrong answer in addition to the 3 correct answers.
input:
lik=[]
lis=[[[]],[[]]]
for n in range(2,500):
lis.append([])
for y in range (1,n):
...
This chunk of code below look for the class name and apply in-view class when it does. I was looking for code improvement suggestion. Most of the time this code fires when scroll event happen. Code works great but i have a doubt that this code is the one that is most expensive in my code base. If...
"what are the problems of this code" is such a common pattern in questions that anyone with 3k should know that it's more likely an IPS problem then a code problem.
My controller is looking something like this.
Is there a better way to generate my html to render coming from different functions:
$html = $renderer->render($clear_form);
$html .= $this->render_preview();
$config = \Drupal::config('amu_import_ldap.settings');
if (null != $config) {
$subm...
we have to reverse char[] using recursion.
Input: ["H","a","n","n","a","h"]
Output: ["h","a","n","n","a","H"]
package codeMonk;
public class RevereseString {
public char[] reverseStr(char[] reversedString, int startIndex , int lastIndex, int midIndex) {
// Base Condition
...
Great, just tried it and so far it is working. Ill write some code up and post it on Code Review, would you mind reviewing? — Jose6 secs ago
i never go to code review, but glad to hear you have it working. with css there typically isnt too much to optimize (for speed) since it's not exactly a compiled language, but you may be able to use fewer lines in the end... — braX28 secs ago
attaching my try on implementing simple naive-bayes classifier for sentiment analysis as part of learning clojure and using functional programming on ML algorithms.
I tried to invest more time in code readability, functional-operations & mindset rather than efficiency (there are clearly parts in...
Then you should try to write a program that reads from your text file and shows it in a system modal dialog box. Once you've attempted to do this, and have some code, you might be able to get more targetted assistance here (Stack Overflow) or in Code Review. — Jeff Zeitlin36 secs ago
In my application we have four inputs radio controls and on the load the value is checked to true. When the user select another radio and then save the form I want to get the new value. I am using the find class but then I need to use checked[0] is there a better way to do this?
JS
$("#form").s...
@DerKommissar The little I've messed with SEDE it seems cool. But after trying to setup SQL in my programmer infancy I've never had a desire to use it again.
I am aiming to implement a calculator in an object-oriented way.
Here is the solution by using the strategy pattern.
Looking forward to some valuable comments.
package oopdesign.calculator;
public class AdditionStrategy implements CalculationStrategy {
@Override
public int calculate(...
Problem: You are given a board containing letters and a word that you have to form. You can only take the letters from the front or the back, hence you have to rotate the board left or right. You have to use the greedy approach and get a list of rotations necessary to get the word.
Code:
...
As part of a classroom exercise, I'm trying to understand the code of a Monty Hall simulation found here: https://openclassrooms.com/fr/courses/4452741-decouvrez-les-librairies-python-pour-la-data-science/4740937-decouvrez-le-probleme-de-monty-hall#/id/r-4770995
(apologies for not providing an E...
Practice proper code indentation. It's an important tool when trying to understand and debug code. Also, on SO, code must be syntactically correct to get help otherwise it's off-topic. Your code appears to have been wrapped, which broke all the embedded commenting and would cause syntax errors. As the code stands, it will be rejected from codereview because it won't run. I unwrapped the comments, but please be more careful. — the Tin Man52 secs ago
I'm relatively new to python and web scraping in general, As such, this is my first major web scraping program in python. My code works nonetheless, I'm just not sure if it's the best OOP design. I have some doubts about how much instance variables I've used Would refactoring this code as a bun...
I've written a function that takes a sequence and check for every item in that sequence whether the current value a selection (obtained with a selection function) is different from the previous computed value and if that's the case, then map the current item and returns a new mapped item along th...
Aside, this would be a good question for Code Review Stack Exchange—and especially since you have working code. Generally, Stack Overflow shies away from opinion-based questions like “what is the best approach?” since they don’t lend themselves to a single, concrete answer. — Jeremy Caney22 secs ago
I am fairly new to AngularJS, and currently, I am learning $http. Every time I make a request and get the response to it, I store that response in a variable and then inject it in the $scope, like below.
$http({
method : "GET",
url : "https://api.covid19api.com/summary"
}...
The code reads in integer array from user input and builds a minimum heap via an iterative scheme.
Are there any edge cases in which this approach would fail?
#include <iostream>
#include <string>
#include <sstream>
#include <stdexcept>
#include <cmath>
int readheap(int* theheap) {
std::str...
I made a pagination algorithm but in my opinion it is too complicated and it is quite difficult to be understood. This algorithm should show 5 pages where in the middle is the current page. It should also show two pages before and two pages after the selected page (if these pages exist).
So,...
To be clear -- we require questions to be about specific problems. Code for which no problem is known belongs on Code Review, but is off-topic here. (Note that there are other criteria required for acceptability on CR; before posting there, read A Guide To Code Review For Stack Overflow Users in full). — Charles Duffy40 secs ago