instruction stringlengths 71 95.1k |
|---|
Currently I am working on reducing function calls in my tool.
My function is called add_field_and_calc
def add_field_and_calc(
f_class, name_of_new_field,
condition, field):
"""Creates new field, make selection and fills with specific value from selection"""
arcpy.AddField_management(f_c... |
I have a set of parameters, and I need to get the expression:
So I got this parameters:
filters = {
"type": 'human',
"age": [{'min': 4, 'max': 8}, {'min': 15, 'max': 30}],
"size": [{'min': 60}],
}
And my goal is to obtain this string from it:
type == 'human' and ((age >= 4 and age <= 8) or (age >= 15 and age <= ... |
I have implemented a simple HTTP server which can process GET and POST requests from the client. I have written it in Java. For the client part, I just simply type in localhost:8080(file_name_here.file_type_here) in the browser. For the GET request, the server tries to find the requested file in the directory. If it fi... |
I've got here from stackoverflow
I have a table with this data:
I have this code:
Sub HorariosReal()
Dim LastRow As Long, Horario As String, i As Long, arr1 As Variant, Comprueba As Variant, a As Long, arrHechos() As String, _
YaHecho As Variant, arrFichajes() As String, arrFinal() As String
'Insert peo... |
I'm new to hash codes/hash tables, so I'm very unsure of my implementation. I want to create a hash table, but I can only use arrays. Specifically, I want to be able to insert things like a dictionary (a word and its meaning). Here is what I have:
public class HashTable {
String[][] table;
int tableSize;
H... |
So I've been working on a tracklist generator that scrapes from Amazon Music using a url using Python for albums with one artist. I've made uhhh this, I'm really new to this requests and beautifulsoup4 thing. I wonder if I can improve it to make it more efficient.
import requests
from bs4 import BeautifulSoup
Amazon=s... |
Is there any better way how to mix items in list? In my example: I want to sort list items as male, female, male, ... My solution is probably very time and resource demanding. Can I do it somehow with LINQ?
private List<Child> MixGender(List<Child> children)
{
List<Child> male = new List<Child>() { };
... |
Given our spec from Code Golf:
Given two integers, output the two integers, and then the range between them.
The order of the range must be the same as the input.
Examples:
Input Output
0, 5 -> [0, 5, 1, 2, 3, 4]
-3, 8 -> [-3, 8, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7]
4, 4 -> [4, 4]
4, 5 -> [... |
I am pretty knew to the VBA world but I am really eager to improve my skills. I have a case where I would like to match cancellation with new business to see what we get back from our dropped business as new orders.
The matching is as follows: a variable called Fastighet (meaning "real estate" in Swedish) will be speci... |
I am having issue making this code more efficient. The problem to be solved is as follows:
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can
see that the 6th prime is 13.
What is the 10,001st prime number?
I'm looking to complete this in powershell. My code runs well up until about 4.8k primes.... |
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.
pivot = (high + low)/2
The pivot as such is usually a virtual one.
This approach performs a pass on every iteration to determine the high and low values.
My understanding... |
I'm looking for a simpler code that isn't resource hungry that can compare two strings stored in different locations in the extended memory of a classic 8052 (namely the AT89S52 microcontroller) to make sure the characters match exactly.
The error flag can be a bit value, but the only thing that concerns me is that I n... |
The Main program. This program pulls from a .txt document with two separate strings, and outputs a .cs program that will display those two string via console when run. It uses a structure.txt file for the code it inputs the strings into.
using System;
using System.Collections.Generic;
using System.Linq;
using System.T... |
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 (get-digits-fn 1234567) => (1 2 3 4 5 6 7) / [1 2 3 4 5 6 7]
Below are five attempts at the same function:
(defn get-digits-1 [num]
(->> [num '()]
(iterate (fn [[num ... |
I am making a paint program in Python using Pygame. Right now the program is very laggy, and I wanted to get my code reviewed incase the reason is in the way I have written the code.
EDIT:
I was mostly able to fix the performance issue by changing the way layers work. The issue was too much blitting and I fixed it by s... |
This is a very simple web API for a school assignment, as a part of a bigger system. The web API returns a list of courses or a single course as json. I doubt that I will get any feedback on the code since Java is taught in the course so I am posting it here.
I am a beginner in Racket but have experience with C-style ... |
Follow up of Object-oriented student library
Question: How do you refactor this code so that it is pythonic, follows OOP, reads better and is manageable? How can I write name functions and classes better? How do you know which data structure you need to use so as to manage data effectively?
from collections import defa... |
This is an interview question I saw online and thought to give it a try.
The question is about implementing a hash map with a setAll(V value) function. This function assignes a value to all the keys in the map at O(1).
Examples:
HashMapSetAll<Integer,String> map = new HashMapSetAll<Integer,String>();
map.put... |
This is just straight bruteforce with the ability to select multiple charset for one word, being able to mash up the linearity with a modulo. This code is also posted on GitHub.
Generateur.h
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
class Generateur
{
private:
bool two, three;
int length1, le... |
This is my first attempt to do unit test for one of my controllers.
@RunWith(MockitoJUnitRunner.class)
public class AddressControllerUnitTests {
private MockMvc mockMvc;
@Mock
SubmissionService submissionService;
@Mock
MessageSource messageSource;
@InjectMocks
AddressController addressCo... |
In one of my frameworks that I use with many tools I have an ExpressionVisitor whose job is to resolve the exact property, it's declaring type and instance. I later need this information to create keys/names for my settings (to query a database or read the app.config)
Namespace+Type.Member
also other (shorter) combi... |
I use bash scripts to process last names through a Perl program, and I parallelize the execution like this, by name initials:
for alpha in a b c d e f g h i j
do
perl process_names.pl -init $alpha &
done
wait
I've determined that ~10 parallel executions is about optimal, to complete the work quickly but also to le... |
I have a feature in my application that should allow users to select items in a drop down menu and move them up and down. Once they select and click on the button I have to loop over the array of objects and pull only records that were selected in the drop down menu.
Here is an example of my code:
var selectedColumns =... |
I've been away from C++ for some time and I'd like to get back up to speed with modern practices, so I implemented a small random number generator described here.
Any advice on this piece of code?
#include <cstdint>
#include <cstddef>
#include <limits>
#include <random>
// implementation of Bob Jenkin... |
I have implemented two pieces of code as part of an Evolutionary Algorithm study: Particle Swarm Optimisation (PSO) and Genetic Algorithm (GA). Both are designed to find an optimal solution to a problem, in this case finding the global minimum of a mathematical function.
PSO performs very efficiently and quickly requir... |
I have this old code and I want it to be easier to understand. Originally, it loaded using an onload on the opening body tag, so I managed to change that to a window.onload, but now redundant code is getting elements by ID, since it first finds the form and after that the actual select box.
var localidades = new Arra... |
I'm creating my own implementation of the STL, compliant with the C++17 standard. The only purposeful differences are that the namespace is hsl (homebrew standard library) to prevent name conflicts, and the headers end in .hpp, so that syntax highlighting will work in my editor. I started with hsl::array because it see... |
I'm trying to make a simple game for a school project. Do you have any tips on how to simplify and beautify the code?
GitHub
import pygame as py
import os
py.init ()
screen = py.display.set_mode ((800,600))
bg = py.image.load('game-assets-game-background-sidescroller.png')
clock = py.time.Clock ()
idle = [py.ima... |
I am working on a background project that is a little interactive. Now I am using some collision detection to draw some lines and stuff.
The code I have works great but it is very bulky and hard to read.
if (background.allPixels[i].location.x - drawLineBetweenPixelRange < background.allPixels[j].location.x + background... |
I wrote a function to calculate an 8-bit CRC/checksum for unknown data types. The only restriction is the data type must be at most 4bytes/32bits.
uint8_t crc(void* _crc, ssize_t len, uint8_t _crc_seed) {
void* _crc_cpy = malloc(len);
memcpy(_crc_cpy, _crc, len);
uint32_t* _crc_cpy_pointer = static_cast<uin... |
These are the three steps that need to be taken in order to successfully activate Long Mode. Error reporting is sparse as most real hardware for developing an OS is 64 bit but probably still a good idea to implement this verification procedure.
I did a little tweaking of some of the examples that can be found on the we... |
Kindly review this scala code for given problem and suggest improvements.
Problem - Given an array of integers and a target sum, check if array contains a pair which adds up to sum.
Example -
i/p - (1,2,4,5,6) 7
o/p - true
i/p - (1,1,1,5,6) 2
o/p - true
i/p - (1,4,4,5,6) 13
o/p - false
Scala implementation
impor... |
Is there a better way to write this while maintaining its current functionality? (checking balances, updating, subtracting, etc...) If so, where would I begin? I saw a code briefly in class that was for a similar questions and it looked more streamlined.
class Account:
# constructor
def __init__(self, name, ac... |
I created a template trait which finds the common iterator category between a set of given iterator categories. More specifically, it's a class with a member type alias to one of the iterator tags which is the most efficient for the specific requirement set that is implied by both categories given as template arguments... |
I have an inheritance class that mimics the behavior of C style array's brace initialization by using a class template that has a variadic constructor but the template itself is not a variadic template. The base class stores the contents from two flavors of constructors either a Variadic Constructor, or a Variadic Cons... |
As an exercise (scroll to the first set of exercises) for learning Haskell, I have to implement foldl1.
I believe I have implemented it successfully and while there is an answer available, it would be great to have the eye of an expert and more importantly, the thought process of why certain decisions were made.
Below ... |
I'm new to PDO, and I want to make sure I made this in the correct way. This way is working, but I have a feeling it's unclean.
I have this input:
$query = $handler->query('SELECT * FROM content WHERE id=1');
while($r = $query->fetch()) {
?>
<div id="content">
<div class="container">
<form action="<?php echo BA... |
I come to see you to help me improve an express middleware that allows you to control access resources by checking the rights of the user.
The following code is supposed to be as generic as possible so that it can easily be added to another project.
But I have doubts both on its genericity and the clarity of its protot... |
I have an extension that adds values to a class and I was wondering if there was a faster way to do this.
Does a for loop execute faster or would a LINQ query do better?
public static List<T> DataTableToList<T>(this DataTable dt) where T : class, new()
{
List<T> dataTableList = new List<T>();
var rowsCount = dt... |
This is a follow-up answer "implementation" to a question I posted on SO. For the sake of convenience, I will repeat my intent: I want one thread (called sub-thread) to print 10 times under outer-loop with 2 iterations; then another (boss-thread) to print 100 times under outer-loop with 2 iterations provided that sub-t... |
I have to use value type to lock code sections in correspondence to objects identifiers (i.e. Guid, int, long, etc.).
So I've written the following generic class/method, which uses a Dictionary to handle object that is a reference in correspondence to the value type (so this objects can be used with the lock instructio... |
I've written a very simple program using Qt that I intend to continue working on as I continue learning C++ and Qt.
I'm mostly wondering about my general code and comment style, specifically in terms of C++, less so about the actual program (which is boring and featureless at the moment).
I've uploaded the full code t... |
This is the code I wrote in order to find the smallest value in a list using recursion.However I feel like there would be a better way to do this?
def minimum(lst):
"""
parameters : lst of type list
return : the value of the smallest element in the lst
"""
if len(lst) == 1:
return lst[0]
... |
I just wanted to ask how can I make my code a bit shorter. As of now, I have way too much code in the class. The program should display about twenty one spinners. I know it's a lot, but in this layout, users have to create their own training plan for 3 training days. In every training day, user has to select up to thre... |
I had to create a selection menu for a Contact Directory project for school. This is the second time I've had to create a menu for a particular project so I recycled the menu from my previous project to accommodate this Contact Directory and all went well.
But I realized I'm basically just listing the Objects methods f... |
I am creating a .io style game through Unity and it's coming along nicely. This is my first time working with Unity, and my first time using C#; I have been a Java coder. Could you good people tell me what you think, and tell me if you see any major issues? I am hoping to improve the EnemyCode AI script, and if anyone ... |
I just finished implementing a HashMap in Java, with methods:
add(String key, Integer value)
get(String key)
remove(String key)
printHashMap()
Is this the correct way to implement a HashMap? I am implementing a load factor feature that automatically increases the size of the HashMap until the load factor is satisfied... |
I am learning Go and wrote a small application that queries the Skyscanner API as my first attempt at learning. I was hoping someone more expert than me in the language could look over it at broad strokes and let me know if I'm on the right track. I really appreciate any feedback I can get!
Also, I know this is a fair ... |
I converted my .net MVC, Entity Framework and SQL server website into .Net with Storage Table as the cheapest database option in Azure.
I followed a repository pattern same as Entity Framework, Created Base Repository for common CRUD operation and other repositories as per table (entity).
This is my first implementati... |
i am trying to write csv parser so if i have the same name in the name column i will delete the second name's line. For example:
['CSE_MAIN\\LC-CSEWS61', 'DEREGISTERED', '2018-04-18-192446'],
['CSE_MAIN\\IT-Laptop12', 'DEREGISTERED', '2018-03-28-144236'],
['CSE_MAIN\\LC-CSEWS61', 'DEREGISTERED', '2018-03-28-144236']]
... |
This script replaces the red hair in image to black color (replace one color to another)
Three major parts in this script
Not just replace color red to black, I hope the output image looks natural, so I will replace the color close to red to black. This "close" is measured by Euclidean distance.
And not just replace ... |
I have been practicing recursion lately and I came up with this code to solve the water jug problem, given two jugs of volume jug1 and jug2, where jug1 < jug2, obtain a volume t, where t < jug2.
The algorithm below basically always pours from the smaller jug into the bigger jug, how would you improve the solution ?
I t... |
I wrote the following code to merge two sorted lists. Is there a way I can improve it?
Possible ideas (not sure how to implement them):
Remove code duplication (setting the returning list node and moving to the next)
Avoid the use of the infinite loop
Avoid the use of panic!
This is the data structure:
type Link = Op... |
I have created the following view extending the JPanel class, the objective of this view is to allow the user to perform 3 CRUD operations create,delete and modify on the entity "Attribute", this entity belong to an entity User or Client, so when the user wants to perform CRUD operations it has to specify if the operat... |
I wrote a code which prints the following pattern :
5 5 5 5 5 5 5 5 5
5 4 4 4 4 4 4 4 5
5 4 3 3 3 3 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 3 3 3 3 4 5
5 4 4 4 4 4 4 4 5
5 5 5 5 5 5 5 5 5
The code is as follows :
#include <stdio.h>
void main(){
int n,i,k,b,a;
printf("ENTER OUTER NU... |
I have written a function which counts how many unique words are included in a given text.
The source-code:
const computeCountUniqueWords = (strToExamine) => {
let parts = strToExamine.split(" ");
let validWords = parts.filter((word) => {
return /^\w/.test(word);
});
let uniqueWords = new Set(validWords... |
I am trying to find a good, basic way to make selection and insertion sorts so that I can manipulate them for other sorting techniques. How do these look? Is there a simpler way to write them?
package javaapplication59;
public class JavaApplication59 {
public static void main(String[] args) {
selectionSort ss = n... |
While I'm training to get better at C, I tried my hand at making a doubly linked list implementation.
linkedlist.h
#ifndef LINKED_LIST_H_
#define LINKED_LIST_H_
#include <stdlib.h>
typedef struct node {
void* data;
struct node *next;
struct node *prev;
} node;
typedef node* pnode;
typedef struct List {... |
I'm new to handling errors and am not sure how to do it, basically, in a speicific request err.code === 11000 is not actually an error, but expected behaviour. I want to output it but not like another error and I want the code to continue running. I don't think it looks nice.
(async () =>{
let client;
try {
cli... |
Problem Statement:
We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the ith job.
Now we have some workers. worker[i] is the ability of the ith worker, which means that this worker can only complete a job with difficulty at most worker[i].
Every worker can be assigned at most... |
I just finished making a flappy bird type game and would like some feedback on my game loop and state machine. The game loop was based on deWiTTER's article, and the state machine was based off of an answer by Indi on my first game. The code was condensed and re-arranged in order to just have a minimum viable project t... |
I am extracting 10 lat/long points from Google Maps and placing these into a text file. The program should be able to read in the text file, calculate the haversine distance between each point, and store in an adjacency matrix. The adjacency matrix will eventually be fed to a 2-opt algorithm, which is outside the scope... |
I have the following code:
function TSliverHelper.SlowNorth: TSlice;
var
i: integer;
begin
// Add pixels 0,1,2
// This means expanding every bit into a byte
// Or rather every byte into an int64;
for i:= 0 to 7 do begin
Result.Data8[i]:= TSuperSlice.Lookup012[Self.bytes[i]];
end;
end;
This uses a strai... |
I created a simple game of life and I used console prints to debug and visualize it at first. However, when I tried to introduce GUI (using Python tkinter), the game slowed down to a crawl. Everything is working fine, as far as I'm concerned, but I would like to know how to improve performance.
Notes:
I asked somethin... |
My code takes numbers from a large text file, then splits it to organise the spacing and to place it into a 2-dimensional array. The code is used to get data for a job scheduler that I'm building.
#reading in workload data
def getworkload():
work = []
strings = []
with open("workload.txt") as f:
rea... |
Intro
I'm going through the K&R book (2nd edition, ANSI C ver.) and want to get the most from it: learn (outdated) C and practice problem-solving at the same time. I believe that the author's intention was to give the reader a good exercise, to make him think hard about what he can do with the tools introduced, so I'm ... |
I'm a newbie Python programmer and I just made my first script which allows autoclicking into various positions of the screen (3 for now) an X number of times with an Y interval.
I'd like to know what do you think about my code, specifically if there is a more efficient way to do the same task.
No need to extend funct... |
I made a program that converts between Celsius and Fahrenheit. Is there any way that I could make this code more efficient and cleaner?
use std::io;
// C to F: F = C*(9/5) + 32
// F to C: C = (F-32)*(5/9)
/**********Converts between Fahrenheit and Celsius*********/
fn main() -> () {
println!("Do you want to conv... |
Is authentication implemented correctly?
At the entry point to the app, which is App.js, query the Django server, which responds whether the current user is authenticated after checking request.user.isAuthenticated
I am not using redux, just storing authentication state in a local object (this can't be tampered with I... |
I feel like the title is a bit wordy. What I have defined here is a function that takes two parameters:
a list that contains valued sorted from smallest to biggest
a number to insert at the right index so that the returned list print its values from smallest to biggest
NOTE: Recursion is mandatory
def insert(lst, to... |
I have to create a custom table (like a pivot table), where users can find immediately the total of items, and when clicking on data, get the db page correctly filtered.
My code works fine, but continuous improvement pushes me to look for more efficient code.
Thanks for every contributes.
Sub AddTab1(ByVal c As Integer... |
I have used Enum objects before in PHP as shown here.
However, I often find it's a requirement to have further attributes or metadata available on the instances.
I came up with the example solution below:
<?php
class Month {
const January = 1;
const February = 2;
const March = 3;
const April = 4;
c... |
Assumptions
Basically, a Connection class has a "Disconnect" event. Subscribing to this event isn't thread-safe, because the disconnection may fire from another thread right before I subscribe. So checking before the subscription doesn't help.
Checking for the disconnect after subscription doesn't help either because t... |
Story:
I build a kind of labyrinth. This labyrinth is divided in seven steps. You start with the first, then second, and so on to the seventh. You cannot go back to a previous step. Each step contains 3 to 5 rooms. Every room of a step is connected to at least one room of the next step. As well, every room of a step is... |
In my previous post I made rather dull (and, as it turns out, bluntly wrong) attempt at solving the problem:
Generate a maze with \$N\$ nodes, \$K<N\$ of which are border nodes. Each border must have degree of \$m\$, and each non-border node must have degree of \$p>m\$. The generated maze must be a minimally connecte... |
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 (namely a bit extracted from one operand) and the other operand. For a multiplication by a power of two there is no differen... |
I have a simple function that reads character by character from stdin, while resizing the buffer whenever needed. The implementation will only allow 256 characters to be read, but that can easily be modified. Are there an obvious problems with this function? ie. it relies on undefined behaviour. And how can performance... |
I had this idea not to long ago on creating a secure chat for people who need to be not meddled with when talking (like whistleblowers, hackers, etc) talking to one of my friends about it he said I could use the One Time Pad Cipher, so I decided to write my own in Python.
If you don't know what the one time pad is, in... |
I would like make this calculator program more Object Oriented but I'm struggling with how to do it. The calculator works perfectly but I would like to have another class that does the calculations and then sends that information back to the main class to be displayed. Any tips? I'm not sure how to call the methods and... |
I've written an algo to compress a string
eg. aabcbbba to a2bcb3a
I'm pretty new to functional programming, I feel it's easier to debug and learn from functional code if you're good at it already, but total opposite if you're not.
I'm wondering how I can make this code cleaner and more functional.
I feel like there's ... |
First time moving from Bash to Python for scripting and looking for feedback/improvements. I've spent the weekend learning about OOP, and am aware that not fully utilizing it in this script — so any feedback is much appreciated!
Summary: Python script runs every 5 minutes, confirms server creation/deletion via OpenStac... |
I have found the coordinates of the centroid for finding the direction of the normal vectors of the edges of the convex polygons. This method seems to work in the cases I tested. Is this fool proof ? Are there any better alternatives ?
CyrusBeck.cpp
#include<iostream>
#include<cmath>
#include"graphics.hpp"
#define P p... |
A die is rolled n times. Each time, a random value has been inserted into a vector. This vector then is used to generate a sorted map (wrongly called hashmap in the code) that is later used to create an ASCII histogram.
The histogram, for example, looks like this:
10
#
#
7 #
# #
# # 5
# # #... |
I am creating an Ellipsoid class and I then want to instantiate a few constants (pre-defined Ellipsoids).
Below is my current implementation. I am not really satisfied with it except that it works very well but feels a but clumsy and there is probably a much cleaner way to do this.
# -*- coding: utf-8 -*-
from colle... |
The below code works as intended and I'm generally happy with it - the sliders each change an RGB value to modify the color of the circle in circlePanel.
Likewise the diameter slider changes the size.
Could the code be refactored/restructured to make it better/more readable?
The CircleSlider constructor is quite long -... |
I've a code that process buffers of samples/audio data. Here's the code:
#include <iostream>
#include <math.h>
#include <cstring>
#include <algorithm>
#define PI 3.141592653589793238
#define TWOPI 6.283185307179586476
const int blockSize = 256;
const double mSampleRate = 44100.0;
const double mHostPitch = 2.0;
const ... |
I am working on a custom Bootstrap 3 carousel, with vertical, unidirectional, slide transitions.
I want to prevent slide transitions from overlapping when the bullets are clicked in random order and rapid succession.
I came up with this solution that relies on disabling them as long as a slide transition is in progress... |
public static GeneratePassword(minPassLength) {
let small = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(' ');
let big = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split(' ');
let numbers = "0 1 2 3 4 5 6 7 8 9".split(' ');
let special = "! \" # $ % & ( ) * + - . : ; < = > ? ... |
I am learning how to code in Python by myself and have never coded before, I just want to know if there is any way I can upgrade my PasswordGenerator.
#!/usr/bin/env python3
import random
def passwordgenerator():
mypw = ""
count = 0
alphabet_number = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNO... |
I have come up with a recursive function which applies trim() recursively to all string members of an array/object.
I don't have any specific quandaries about my code so I am receptive to all feedback.
My goal is maximum compatibility for all PHP versions: past, present, and future.
<?php
/**
* trim_r
*
* Recursive... |
I would like to receive some feedback on the code I am currently using to display x amount of images on my website per
$success = true;
$page = array_key_exists('page', $_GET) ? $_GET['page'] : 1;
$all_pictures = glob('crossles/*.jpg');
$total_images = 0;
foreach ($all_pictures as $img_total) {
$total_images++;
}... |
When using dependency injection for nearly everything it's good to have some file access abstraction. I find the idea of ASP.NET Core FileProvider nice but not sufficient for my needs so inspired by that I decided to create my own with some more functionality.
Follow-up
Interfaces
I have two interfaces that are called... |
I have working code that compares rental prices and owning costs, given some parameters. It works, but it surely does not look good. I hadn't worked with time-series before and I wonder how I could improve the code. See it below:
""" Credit: khanacademy.org/downloads/buyrent.xls"""
""" This code compares the cost of r... |
I am working on below problem:
Given an integer, how do you find the square root of the number
without using any built-in function?
private static double computeSquareRootBinarySearch(double x, double precision) {
double start = 0;
double end = x / 2 + 1;
double mid = (start + ((end - start) / 2));
... |
This function takes a string from an HTTP POST or GET string, finds the specified variable, and allocates memory for the result and puts it in a string. The destination is given as an address of an empty pointer.
username=johndoe&password=password123
Would produce:
password123
when finding variable password.
void htt... |
This is my version of the possible permutations of a string challenge. Please give me feedback or criticism. There are two vectors here: positions and pointed_to. positions[i] holds the index of the i'th character in the permutation. pointed_to[i] is true if the index of the i'th character in the original string is pre... |
First of all, let me answer the question that a lot of you may have:
The Mandelbrot set is the set of values of c in the complex plane for which the orbit of 0 under iteration of the quadratic map when f(x) = x2 + c.
The fun thing about the Mandelbrot set is that it's a fractal and you can indefinitely zoom into it. ... |
Problem: convert this array of hashes:
cars = [
{ :model=>"Ferrari 458", :speed=>320 },
{ :model=>"Maserati MC12", :speed=>330 },
{ :model=>"Ferrari Enzo", :speed=>350 },
{ :model=>"Lamborghini Huracan", :speed=>325 }
]
to this data structure:
{
above_320: [
{ :model=>"Maserati MC12", :speed=>330 },
... |
I am looking for a way to turn a list of words that may have duplicates into a dictionary/map that counts the number of occurrences of words. After spending some time with the problem, this seems to be one of the better ways, but maybe there are some downsides I am not seeing to this.
const magazine = "asdf ASDF wer w... |
I have been staring at what I have produced for almost 5 hours and I still cannot see how and where to improve my implementation. I am implementing an Orthogonal sampling method according to the description of Orthogonal Sampling.
import numpy as np
from numba import jit
import random
def Orthogonal(n):
assert(np.sq... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.