I want to perform a binary search on a continuous unimodal function ƒ(x)=y, where x and y are real numbers. I'm not looking up values in an array, and so I don't have clean integer inputs that I'm stepping along.
My original attempt at a function (written in JavaScript) has the problem that when...
I feel so out of touch everywhere. I'm barely here, and I never hear any news about what is going on with my family until its either happening or over :/
Ha. First time this happened was when I needed to care for my hysterical puppy when we were installing new floors.
She left her mom when she was 8 weeks, or something; just a tiny little thing. She bonded with me and had really bad separation anxiety for a long time.
That was shortly after I got my computer, so I consoled myself by learning programming.
I am a beginner in Python and am trying to make a program that takes the sum of an amount of numbers a user inputs. This is what I have so far. I want to make the program repeat and have added a loop. but the comment "break outside loop" keeps coming up and interferes with it working.... How can ...
I am trying to make a program with a loop that shows the increase of tuition per year (5%), the only issue I am having is with the last line which shows the error:
" tuition = tuition + tuition*0.05
TypeError: can't multiply sequence by non-int of type 'float'"
How can I fix this? I tried puttin...
Some Background
I've been developing an ESLint plugin to catch Protractor/Jasmine
specific code style violations.
In Protractor, there are two important notations: ElementFinder
and ElementArrayFinder.
ElementFinder is a special object that corresponds to a single
element ...
I am beginning to learn Scala and functional programming, and I came across the puzzle defined below
http://www.bbc.co.uk/programmes/articles/5wkxjTtqRvq8Cyrrjxtk7tc/puzzle-for-today
This looked like a good practice and I have got a solution but just want some hints in terms of functional appro...
Given a non-empty array of integers, return the k most frequent elements.
For example,
Given [1,1,1,2,2,3] and k = 2, return [1,2].
Following is my submission to this problem on Leetcode and it is accepted. Can you please provide feedback on any issue that you see in this code? I am looking for...
'''Let d(n) be defined as the sum of proper divisors of n (numbers
less than n which divide evenly into n). If d(a) = b and d(b) = a,
where a ≠ b, then a and b are an amicable pair and each of a and b are
called amicable numbers.
For example, the proper divisors of 220 are 1, 2, 4, ...
I end up with weird looking function signatures like this one
def get_word_alpha_value ( \
word: str, alpha_values: dict = get_alpha_values()) -> int:
'''
Calculates the value of each letter in the word
and returns the sum of the letter values.
'''
word_value = 0
for letter in list(word):
word_value += alpha_values[letter]
return word_value
I'am working on a web-based educational testing system with some of the elements of gamification. Current implementation goes with Java (Spring IoC, SpringMVC, Hibernate, etc.) with the most of the logic running at the back-end*.
Basically, users have a number of tasks in form of multiple-choice...
Here in Korea, we give our students English names, therefore I thought it would be interesting to make an English name generator.
Here is a demo
Here is the index.jsx file. It holds one child component, the actual list for the names. Is this component to big? Is there something more I could ha...
This function is for Python Pandas users. I noticed a lot of RAM can be saved by applying smaller datatypes to columns. The function's input is a Pandas DataFrame. The function output is the compact dataframe and a list of columns that have been altered by filling out NA values with dummy values...
The "Cyraz" encryption algorithm was presented on SOPT community.
This algorithm makes a cypher using a private key given in byte[] format with any arbitrary length. It will then "swap" bytes on the data depedending on the key value. Additionally it will append a byte to end of the cipher, that...
I am working with udacity MAP-REDUCE for course https://classroom.udacity.com/courses/ud617 and solving 2 problem to find most popular file in a common log format file. I am getting displaytitle.php as most popular file with count while the correct answer as per the course and as per https://git...
It's actually an exercise from an Assembly-course I'm doing:
Find closest number.
Add the following into the data section:
nums dd 23h,75h,111h,0abch,443h,1000h,5h,2213h,433a34h,0deadbeafh
This is an array of numbers.
Write a program that receives a number x as input, and finds the dwo...
I've written a script which is able to perform reverse search in the website using the Name and Lid from a predefined CSV file. However, when the search is done then it can put the results containing Address and Phone Number adjacent to those Name and Lid creating a new CSV file. It is working er...
In some solutions I use case-insensitive strings a lot and so far I've been always writing custom collections or using custom comparers to support them. This is usually a lot of work and a lot of testing so I thouhgt what if the string was case-insensitive instead?
The implementation is really ...
Working example: http://dev-site.eu.pn/crak-ajax-es6/
This code grabs data from a fake REST API website, it does so without using of libraries or templating engines and I would like to confine discussion in a similar fashion as I am interested in 'the basics'. I have a function, "processData", t...
My script encodes text and outputs random strings. It is different each time and loads a dictionary that has been pre-set by my dictionary gen.py (included after the main script). I've started my basic Tkinter GUI and this is not the finishing GUI. The main code is as follows:
# -*- coding: utf...
I'm currently working on creating a step by step wizard in Angular and twitter-bootstrap, see code below.
I've actually got it to work as intended but as I'm looking to advance my skills I'd like to hear if you have any feedback on my code. That would be highly appreciated!
How can I avoid usin...
Below you can find my first Python project: a life counter that I am using together with my friends for card games (Magic the Gathering).
For those who know the game, it is actually designed for 1vs1 Commander.
It provides you with the possibility to take notes about life points, commander damag...
Getting close to a release of generic server.
So a couple of reviews will be coming this way over the next few weeks. Stating with the lowest levels and working up to the main server.
Here is part 1 some (boring) utility functions that are used to build error messages.
#ifndef THORSANVIL_SOCKE...
I have to print numbers between two limits n and m, t times.
I created t variable that stores a number of test cases.
Outer for loop iterates for every test cases.
Inner for loop prints primes from m to n.
Code
#include <stdio.h>
#include <stdlib.h>
int is_prime(int);
int main(void) {
...
This is a class from my personal code library, and from a package which deals with integer sequences. It implements an interface
package org.cheddarmonk.math.sequence;
public interface IntegerSequence extends Iterable<java.math.BigInteger> {
public int offset();
public int size();
...
Getting close to a release of generic server.
Nisse Server: Part 1 Helper Functions
Here is the socket layer code.
This has previously been reviewed here. But there have been some changes.
Socket.h
#ifndef THORSANVIL_SOCKET_SOCKET_H
#define THORSANVIL_SOCKET_SOCKET_H
#include <string>
#include
I don't really like the idea of storing 10 iterations of a code review in history. Even for simple code reviews I'd rather just have the full change in 1 record. In our dev cycle feature branches won't generally last longer than a week, so squashing seems the way to go for me. — roim33 secs ago
Getting close to a release of generic server. Nisse Server: Part 1 Helper Functions Nisse Server: Part 2 Socket Layer Here is the stream layer code. This basically provides a std::istream and std::ostream wrapper around a DataSocket. This allowing you to use normal C++ stream operations on a socket. One notable none standard part are the two helper lambdas th…
@apple.py welcome to the wonderful world of Python and welcome to StackOverflow. Trying something new and asking feedback is a great way to learn. Kudo's for that. But if you want your code reviewed, I suggest you post it at our codereview colleagues. Use this site if you have a specific error or problem, and check how and what to ask here on this site. — agtoever15 secs ago
I was given task to build a client server application, using any technology I want.
The task was to build a database(doesn't have to be a real database, it can be mocked). the client side should support more than one user/
I didn't use a real database I just created some shares and created a mec...
Although my code doesn't support a lot of data types(only one), it's enough to see the general design, which concerns me the most.
Range interface -
<?php
namespace Range;
require_once 'vendor/autoload.php';
interface Range {
function __construct(string $range);
IntRange - implementati...
Welcome to your first question on StackOverflow. However, yhis site is not for broad optimization questions. Perhaps you should try Code Review. — Rory Daulton12 secs ago
In my initial problem posted on SO, whenever anyone accessed the Mail.php on the server, it used to send an empty email to the $to. To avoid this I came up with a solution.
require 'PHPMailer/PHPMailerAutoload.php';
$yourName = $_POST['yourName'];
$sender = $_POST['emailID'];
$subj...
This encryption works fine
int len = text.length();
System.out.println("encrypt before len: " + len);
for (int i = 0; i < len; i++) {
num += 1;
int temp = 0;
temp = (int)text.charAt(i);
System.out.println("before: " + temp);
...
I understand my main limitation is my computer's ability to compare millions of combinations but I wondered if there is any way to improve the speed at which the comparisons take place.
My code is as follows:
code = open("C:\\Users\\User\\Desktop\\code.txt").read()
dictionary = open("C:\\Users\...
I'm trying to optimize this code (Given two integers m, n (1 <= m <= n) we want to find all integers between m and n whose sum of squared divisors is itself a square). I'm new to coding and I'm having a hard time with this concept:
def list_squared(m, n):
# your code
import math
...
I'm working on a hobby game and I want to implement a component system similar in usage to what Unity has. I was previously storing type information as a string inside Component, but that seemed like it would be very slow to constantly be doing string comparisons. I'm now storing type_info inside...
Im trying to optimized PI parameters using PSO, codes im using are below, please help. I would like to know why im getting negative values of kp and ki, i need positive values. of 0.945-15 range.
function F = tracklsq(pid)
syms x;
limit_1 = 0;
limit_2 = 10;
...
This is the code so far, I need to be able to encrypt any message using the alphabet given. How would I use the index to print the corresponding letters according the shift represented by the key? Thanks.
Getting close to a release of generic server.
Nisse Server: Part 1 Helper Functions
Nisse Server: Part 2 Socket Layer
Nisse Server: Part 3 Stream Layer
Here is the server. The basic usage should be very simple:
NisseServer server; // declare an object.
server.listenOn<TypeToHandleRequestA...
I am trying to create a 10x10 grid system for a battleship game. I am having trouble initializing a 10x10 grid with only one space per coordinate, instead when I try to initialize my 2D vector I am getting a 10x10 grid with 10 space characters per coordinate. A line to a Coliru Viewer of the issu...
Getting close to a release of generic server.
Nisse Server: Part 1 Helper Functions
Nisse Server: Part 2 Socket Layer
Nisse Server: Part 3 Stream Layer
Nisse Server: Part 4 Server
As I mentioned each connection is handled by a new handler object of specific type. These need to be derived fro...
Getting close to a release of generic server.
Nisse Server: Part 1 Helper Functions
Nisse Server: Part 2 Socket Layer
Nisse Server: Part 3 Stream Layer
Nisse Server: Part 4 Server
Nisse Server: Part 5 Handler
As a demonstration protocol (also for testing). Here is a class that pulls it all toge...
Then I would say that you are doing well. Note that in my above comment I used hashes < rows + 2 instead of hashes < spaces + 2, since at this point in the posted code, spaces == rows is always true; also, loop-scoped means that in my version, spaces only exists inside the for loop where it is declared. IAC, critiquing working code and suggesting improvements is exactly what is done over at Code Review. — David Bowling42 secs ago
@roim Squash merges delete important information that someone months or years down the line can use to figure out why the code was written that way. The more granular the better. If you smash it all together into 500 lines of change, it's hard to know what commit comment refers to what change. Artifacts of code review, like small fixes, can be squashed. Preserve what is useful for future devs trying to puzzle out the code. If you never use it, then it just sits there and doesn't bother anybody. But if you need it and it's not there, there's no recovering that vital information. — Schwern43 secs ago
I'm solving a Hackerrank practice problem of using two stacks to form a queue.
The challenge is as such:
In this challenge, you must first implement a queue using two stacks.
Then process q queries, where each query is one of the following
3 types:
1 x: Enqueue element into the en...
I've written some code using python to scrape names and phone numbers from a webpage which is working nice at this moment. However, The way I've written my class crawler is unconventional. As I've hardly seen any crawler which have been written the way I did here, I'm little dubious as to whether...
I am making a Node Package/Module that uses an API to grab Player Data. It currently looks as follows:
const fetch = require('node-fetch');
const possibleModes = ['quickplay', 'competetive'];
const possibleRegions = ['us', 'eu', 'kr'];
module.exports = {
OWoverallStats: (playerName, mode,...
I was referred here from Stackoverflow.
I'm storing data in a collection for rules. These rules are user defined and can vary, and they will be used to check data from an API. I.e. a user may define that if the field spend (taken from an API) is higher than x do y (i.e. notify Slack).
Each "cam...
I came across a situation where I needed code to run every n invocations of a method. Specifically, I was clearing out massive amounts of data and needed to hint to the VM that it should run garbage collection. My solution was a little more condensed than this, but this class offers reuseabilit...
There are two main ways to keep the size of a pointer.
One as just another variable along side:
size_t length = get_length();
int* stuff = (int*) malloc(length * sizeof(int));
do_stuff(stuff, length);
Another is a struct:
typedef struct ptr_with_length {
void* ptr;
size_t length;
} ...
Is there a way to begin writing to a file at a specific column on the line that the file pointer is currently on without having to use padding? For example, I'm trying to write some pool tournament data to a text file and I want to be able to write dicts containing the players name and place in t...
The problem
Given an arbitrary collection of objects of some kind, count and report the top k most frequent, together with the associated count. For example, if the input array is {'a', b', 'a', 'c', 'b', 'b'} and for k = 2, the template would return { {b, 3}, {'a', 2} }. The idea for the temp...
I've this piece of code that does a request to the server and prints back the response to the console. Before sending the request it's checking if gate is ready. When gate is ready it performs the request and the response is printed to the console.
Now I find the code really complicated and I ha...
if I have a multi-part program that I want reviewed, but it's in way too many parts or too many lines of code to just add to a question, what should I do?