instruction stringlengths 71 71.9k |
|---|
I've got several UIViewControllers that are trying to do too much so I'm trying to learn how to clean them up so that they only have code that does UI things (ultimately getting things to conform to MVVM).
I know my code needs a lot of improvement so I'm going to start small by focusing on one particular behavior to a... |
Feel free to critique my code and offer suggestions on how to clean it up and make it more presentable. I have been working on this for a few days, and learning as I go.
from __future__ import print_function
import random
import sys
#Global variables
dealerWins = 0
playerWins = 0
dealerCard = [1,2,3,4,5]
playersCard... |
This problem should self explanatory based on namings of variables and functions. In essence I am doing well over 720*720*90 checks/calculations. Hence, this is taking far, far too long. How do I make my code more optimized with regards to time/performance. Space is not an issue. The question is pretty complicated(at l... |
I've implemented my own 'power-mod' procedure which will compute a^b 'mod' n for some large b and even larger n. I think the way I've done it is a common procedure, and it does seem well optimised, but I really need to squeeze the maximum performance out of it as it is currently the bottleneck in my program (~75% of th... |
The next assignment in my class is to create a program that allows the user to input an inventory, and then display the total value of the inventory. We are required to create a class with both private and public member functions. I tried to keep it as streamlined as possible but I know there is always room for impro... |
Newbie here, presenting the code for close public scrutiny.
Couple remarks regarding the context (taken from Princeton's COS 226 course):
In this problem I model a percolation system using an N-by-N grid of sites. Each site could be either open or blocked (all of them are blocked initially). To open the site, client ... |
I have a ScrollPane which allows for wrapping around the screen through some nice code. However, in order to achieve this I have had to use 5 ImageViews with each of them being the size of the screen. This causes the computer to run very slowly when panning around and loading. Is there a way to distribute the weight on... |
Exercise assignment:
Build a calculator with React which can add, subtract, multiply and divide.
See image below for reference
Give it whatever design and colors you want
Each text field should have a placeholder
The result field should be able to be copied but not edited
Make sure your math is correct and calcu... |
I recently created Copy, an esoteric language, and wrote an implementation in Ruby.
The language has only 7 instructions:
copy <a> <b> <c> Copy the code block from a to b at c
remove <a> <b> Remove the code block from a to b
skip <value> Skip the next instruction if value is not 0
add <var> <value> Add value to var
ne... |
I have solved the classic "Merchants Guide to Galaxy" problem:
A merchant buys and sells items in the galaxy. Buying and selling over
the galaxy requires you to convert numbers and units. The numbers
used for intergalactic transactions follows similar convention to the
roman numerals. Roman numerals are base... |
I’m wondering is the following function returns a list of three numbers sorted in ascending order with the minimum possible number of operations, or if there is some more efficient or elegant method (a part from using the primitive function sort!)
(defun order (min mid max)
"sort three numbers in ascending order"
(wh... |
Problem statement:
Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height.
Assumptions:
The array (and therefore BST) will only contain the type int. Other integral types are unsupported.
The problem statement's description is a prec... |
I designed and implemented a custom language. After @LeakyNun refactored it to improve speed, it looks like this. I personally like it right now, but is there any more hyperoptimizations for both readability and performance?
/*
*Feel free to modify and distribute the code and all relevant documentation
* This code is ... |
I'd like to verify that the security of this JavaScript code is correctly doing what I believe it's doing. Its intended purpose is to generate xkcd-style passwords randomly in the visitor's browser.
When the page loads, the full wordlist is loaded into the browser synchronously (>350K words) and then generates a secur... |
I'm a student and this is one of my assignments. My professor basically confirmed that my code is correct but all he grades on is if I finished the assignment correctly but not the coding style. I think I did poorly in terms of code style and implementation. I'm very frustrated and would like some guidance on how to im... |
I'm looking for feedback on my URLEncoder implementation, which is a drop-in replacement for Apache Tomcat's URLEncoder. It was completely ignored by the project committers (and I got no feedback why) and I'm curious if it's just that bad, or I failed to communicate why it's better than the original one.
/*
* Licensed... |
This is a single isomorphic class in ES6, written with the intention of generating a full WAV file given note names and durations in seconds. In JavaScript it can be exported as a Blob and in Node.js it can be exported as a Buffer, to be written to the filesystem.
I have left thorough comments in the code to help docum... |
I haven't yet implemented any sort of graph thus far in C and decided to give it a go by trying to implement an adjacency list in C. Is there anything in my code that you see that I can improve and is there any other sort of basic functionality that is missing in my adjacency list and should be added?
Graph.h
#ifndef G... |
The tests are taken from this answer on an insertion sort in rust question.
The algorithm is taken from Algorithms in a Nutshell (2nd Edition).
I'm not looking at crazy performance, the goal being to learn about basic algorithms and rust, but if there is something shockingly inefficient please let me know.
fn main() {}... |
This is one of my first programs working with APIs and I was hoping to get some input in the form of suggestions, recommendations or corrections. The goal is to register the user location by IP, derive a latitude and longitude from the ip-api public site, pass this to Open Weather’s API for weather details and descrip... |
This is the first program I've ever made in Python, and I never really studied the language (just looked at bits of code online) so I'm sure the performance is less than optimal.
The Objective: At my college, security alerts are occasionally sent to our phones, and sometimes posted to our subreddit for discussion. To a... |
In C++, primitive types are treated differently than user-defined types. If you do not initialize them, their values are undefined in some cases. This is an easy mistake to make.
I wanted to make a class that wraps primitive types, etc. so that the default constructor is always called without adding any other run-time ... |
If you're familiar with std::tuple, you're aware that accessing its elements is slightly unusual. Instead of using a member function, we're provided with the function std::get instead. I was curious as to why this is, so I conducted a brief search. The few websites that I saw all gave the same reason: the code used to ... |
Here is a short program web scraping program written in Node.js. I'm just getting to grips with node and this is the first thing I've written with it. I'm liking it so far though I guess I'm kinda missing the point with the whole asynchronous aspect.
This is supposed to be an extremely basic project. I'm just a beginne... |
My problem is that you have a lot of ifconditions to be checked and inside that if condition you have multiple lines of code. I want to eliminate it and use inheritance instead. For every if statement I will be using a separate class to handle it. This is more like a derivative of the command pattern but not command pa... |
I have the actions and the times in an instructions.js file:
module.exports = {
temperature : {
"00:00" : 100,
"01:00" : 110,
"02:00" : 120,
"03:00" : 130
},
ventilation : {
"00:00" : 0,
"00:30" : 25,
"01:30" : 75,
"02:30" : 100
},
end : "03:30"
}
Then after importing the inst... |
I'm parsing an XML file and searching for a child value.
As I'm familiar with this XML file structure, I know that the final value is a child of a child, and so I wrote the following code section:
/*Parse XML file and find device friendlyName*/
pxUpnp = ezxml_parse_file(XML_FILE_PATH);
pxUpnpChild = ezxml_child(pxUpnp... |
I wrote the following lines of code to compare some strings with contents of columns (string) in SQLite database:
void PaymentTransaction::setAttributesBySqliteStmt(sqlite3_stmt * statement)
{
ZF_LOGD("setAttributesBySqliteStmt\n");
int columnCnt = sqlite3_column_count(statement);
for (int i = 0; i < column... |
package com.unisa.pf.sp52016.assign01;
import com.unisa.pf.sp52016.assign01.Predator.STATUS;
/**
* <strong>Overview</strong><p>
* This code comprises a component of a larger game. You have been asked to implement the structure
* that maintains a group of Predators that could be a Pack of friendlies or enemies. ... |
I want to calculate how similar two objects are according to a database. However the code is very slow; it takes around 2 minutes to analyze just 3 objects. How can I speed it up? I have tried to avoid for loops, and I'm also avoiding recalculating things.
This functions returns the ith comparison of the n elements in... |
(Homework alert)
Working my way through "The Haskell Road...", not sure about my solution to exercise 2.15 on page 48 of the second edition:
A propositional contradiction is a formula that yields false for every combination of truth values for its propositional letters. Write Haskell definitions of contradiction tests... |
I'm developing a mobile app with Cordova, jQuery and jQuery mobile. To synchronise the data saved on a device I make AJAX calls to a server (I'm sending and requesting data). The data is saved in a database on the device with this SQLite plugin for cordova. The server-side connection is handled by a php file.
Everytime... |
The puzzle goes like this: in a rectangular 2D grid there are empty spaces (.), exactly one starting point (S, s) and obstacles (denoted below by X's). The objective of the puzzle is to find a path starting at the starting point and going through each empty space exactly once (a Hamiltonian path). You can't, of course ... |
I solved the Nested List Python challenge on HackerRank.com passing all test cases. Although this problem can likely be solved with a short script with clever one-liners, my approach was instead to solve it in a clean, understandable way in functional style.
Here is a summary of the challenge, see link above for full d... |
I'm working on an important project. We're an IT services provider and we have a project where we have to build a new system to process data from a specific client.
The problem is that usually we process their data, but they send us a pre-processed data that's easy to parse, but this time around, they're trying with a ... |
I'd like to have the code below reviewed on all aspects.
Task: Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
My solution
shared.clj
(ns shared)
(defn prime-seq []
((fn prime-seq-gen [s]
(cons (first s)
(lazy-seq (pri... |
I've done a random quote machine in jQuery. Could you look at the code and propose some improvements (especially jQuery code)?
Here's the working app.
var quotes = [
{
"quote": "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.",
"author": "Albert E... |
I have written an efficient way to control data to be cached/not-cached in HttpCache using JSON and C# controlling it.
The reason for this implementation is to make use of existing application servers to store cache to save network latency and call across processes. another reason was to minimize code change after we f... |
I am reviewing the following code written by a fellow developer. I am not an java expert but IMHO i did not feel this is efficient use of exceptions — the reason I feel so is:
The below code throwing exception — seems like flow control. Since we are just using it add a attribute error attribute to PageErrorRequestAttr... |
I am writing a PHP service which will listen for JSON requests (made using jQuery) and will return the JSON responses.
The whole template for such services (there will be 5) I have shortened into this template:
<?php
// set the headers which are accepted
header("Access-Control-Allow-Origin: *");
header("Access-Control... |
I wanted to get your opinion on this immutable implementation of a Phone Book using recursion to process a stream. I am especially interested in ways to speed up the code execution.
Here is an example of expected input:
8
add 811 Mom1
add 12376213 Mom2
add 1732239 Bob
find 76213
find 910
find 811
del 811
find 811
Now,... |
I have a test where I have to validate the order of items in a List based on a pre-defined hierarchy that is being given to me as part of my assignment. Here it is below.
Cat
Dog
Horse
Elephant
The items in the list would only ever be those four types, but the size of list is not limited. The list will be passed... |
Some days ago, I figured out that I'd like to get a notification every time a new question is asked here. So, I've made a really simple Python script, which uses pync (only OSX compatible) to do that for me.
I'd like to get some feedback regarding anything that comes to your mind, including good practices. That's not a... |
As an assignment for a class, I have made a small Harry Potter family tree in Prolog. It compiles into a self-contained executable that can be run straight from the command line on Linux machines. This is my second ever program in Prolog, so I am still learning. My background is in imperative languages, so I am probabl... |
I have this recursive function that I made which prints a table, but I really think my current solution is really ugly. Does anyone have an idea as to how I can improve my solution?
I'm trying to implement without any variables and with the use of sprintf.
let rec rec n =
if n > 0 then
rec(n-1) + sprintf "\n"+... |
I've been toying around with writing a decentralized, P2P application in REBOL 2, and one of the things I need to do is generate a universally unique identifier for users. I have written a function that generates a Version 4 UUID that is compliant with RFC 4122, as best as I can tell.
I have a few questions ...
Is it ... |
I was doing a simple problem on codingbat and testing out my python. The problem was:
Given two int values, return their sum. Unless the two values are the same, then return double their sum.
sum_double(1, 2) → 3
sum_double(3, 2) → 5
sum_double(2, 2) → 8
My solution was:
def sum_double(a, b):
if a is b:
return... |
I wrote this little Bash function to replace my sudo command.
It checks whether I have an alias for the given command and runs the aliased command instead of the literal one in that case.
As this is going to be used with sudo, I want to be sure there are no critical mistakes in it which generate security or safety issu... |
I am starting to write a CLI using argparse library. This is my first attempt to structure a large project, usually I write single script. The CLI auto is defined in a top directory, helper functions are in a subfolder named project and a main function (where I want to put the logic of my program) in sub-sub-folder nam... |
I'm returning an array containing dates (and other things) from an API, then looping through the array on the front end to convert them into dates
The backend uses Node.Js and queries a mySql database with the mySql module:
pool.getConnection(function(err, conn) {
conn.query('SELECT * FROM myData’, function(err, resu... |
I am trying to create an area graph from the upper and lower limit values.
First I created two line graph from those points as:
Sample data points are:
var line1dataPoints:[CGPoint] = [CGPoint(x: 10, y: 120),CGPoint(x: 20, y: 130),CGPoint(x: 20, y: 120),CGPoint(x: 70, y: 130),CGPoint(x: 70, y: 120),CGPoint(x: 80, y: ... |
I am actually more confused rather than understanding the concept. I have been developing a system and want to know the MVC design pattern. which one is best and the concept and usability of the layers?
In general, I have two approaches:
1.
ViewModel layer (contains viewmodels), Models (contains models and datacontext)... |
I am implementing myself a BigInteger class. It can natively handle very very big digits in very short time.
2 ^ 200000 == Time Elapsed : 12.343
Number of binary digits : 200001
The only problem is, when I do std::cout << foo;, I have to wait for very very long. Because my BigInteger class has to perform a std::string... |
I have created a method which shows log in logcat and also writes into the file. Every time this method is called it appends String in file. There are so many read/write operations on disk/non-volatile storage/SD card happening. I want to batch these operations so that minimum SD card read/write happens and i do not mi... |
I have a PHP bot running on a shared host. My account often get suspended. When I asked to web hosting service, they said that my account suspended because of excessive MySQL usage.
There is an upload.php and db_functions.php files. Upload PHP runs every half hour. I open and close MySQL connections in every function.
... |
I need two icons:
If the email is verified, show an icon without a hyperlink and set an "activated" CSS class for green style and checked.
If the email is not verified, the icon is linked to the verify page, and the default is a gray color style.
Which of these solutions is better and standard?
Solution #1:
<a href="... |
Since I'm new to coding, can you give me some advise on game class interactions? The game does work, but my code looks ugly and I think it can be improved a lot.
What I'm mostly interested in:
class1.setvalue(class2.returnvalue()) is this how it is supposed to be done?
Should I derive my objects from some virtual ba... |
I recently struggled with implementing AI in Tic Tac Toe game. For better understanding of minimax algorithm I've decided to separate AI's logic. When I finished I thought that some may find it useful, so I packed AI in easy-to-use API and described its usage in README file on GitHub.
I am wondering if my code uses an... |
I have a switch statement that references different configurations based on data pulled from a database. Each iteration of configuration has variations in what needs to be enabled/modified.
I've set up a method that takes the varying arguments for each configuration and does relevant logic, generally changing elements ... |
I'm trying to design a mapper that will convert one object type to another shown in the diagram below:
The object has structure as follows (it's not a JSON):
{
"type": "DownloadAppComponent",
"name": "Download App",
"contentId": "download-app",
"properties": {
"iosUrl": "http://apple.com",
"androidUrl": "http:... |
For practice I wrote a function to generate a list of numbers from a start to an end by a step. I couldn't make it- like the built-in range- default start to 0, because all optional parameters must come after required ones, so def range(start=0, end, step=1) won't work.
Here's my script:
def Range(start, end, step=1):
... |
I am using Vba excel to populate a list of all my .wtv files using the .GetDetailsOf method. There are some 3000 files across 4 hard drives filed in a b c... subdirectories.
This sends my memory usage from just over 4 (normal) to nearly the full 8 GB available and halts my computer for a short time.
Is there a better m... |
I wrote a Snake Game in C++ and I have practiced some OOP approaches. I would really appreciate criticism and some advice.
snakeGame.h
#ifndef _SNAKEGAME_H
#define _SNAKEGAME_H
#include<SFML/Graphics.hpp>
#include<map>
#include<memory>
#define maxSnakeLenght 100
class SnakeGame{
public:
SnakeGame(int size... |
I want to optimize code in my simple app that I'm writing to learn C#. I feel it's really badly optimized in terms of good coding practises. Could anyone take a look at it and give me a hint to make it look better?
public void mainMenu(BookList b)
{
bool repeat = false;
Console.WriteLine... |
This is for machine learning. I have 5 matlab files: AWA, REM, S1, S2, SWS.
Each one has 2 arrays: x and y. y are the labels. I want to know the number of instances for each category in each file:
I load the matlab file
I convert from f8 to int32
If I do not use ravel, bincount will not work
I count the instances ... |
My code is a variant on the Visitor Pattern and a "leaky bucket" variant. The goal is pretty straightforward: the "bucket" will collect a specified number of items (say, for example, 500) and then empty the queue, running some CPU-bound operation on ("visiting") each item. (Yes, I'm aware that there's probably existing... |
Even though singletons are bad practice and often unnecessary, I still see many developers using this pattern over and over. Since implementation of this pattern usually requires some common code, I thought we could just make a base class to be extended.
I came up with this so far.
<?php
namespace wl;
/**
* @dosc al... |
I am new to JavaScript and wondered if there is a more streamlined way of writing this code:
var choices = "ABBCD" // A string containing the letters A-D
var total = 0
function calculate() { // Iterate through choices and add to total depending on the letter
for (var i=0; i<choices.length; i++) {
if (choices[i]=... |
I have created a class which wraps pointers and behaves like a pointer would behave, minus a few cases. It is a lock wrapper class which simply locks before usage of the pointer and unlocks once the pointer usage is done.
It must behave exactly like a pointer EXCEPT in the following cases:
It cannot be implicitly conv... |
I have this function that takes a number \$N\$, and \$N\$ C strings, concatenates and returns the result:
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* mystrcat(int count, ...)
{
char** p;
char* result;
char* ptr;
size_t* len_array;
va_list ap;
int j;
... |
I am working on Project Euler Problem 58:
Starting with 1 and spiralling anticlockwise in the following way, a
square spiral with side length 7 is formed.
37 36 35 34 33 32 31
38 17 16 15 14 13 30
39 18 5 4 3 12 29
40 19 6 1 2 11 28
41 20 7 8 9 10 27
42 21 22 23 24 25 26
43 44 45 46 47 48 49
It is interest... |
I have written a function that fills in the values between points and creates one continuous path (essentially walks between the points) and I'd like some feedback on it's implementation.
If two points are provided that are not "in line" with one another then an error is thrown, as I do not want to support diagonal mov... |
As a newbie to Javascript (or coding for that matter), I'm sure I overdid this, but I couldn't get anything else to work. Here's what I'm doing:
allData in createDiv has anywhere from 20-500 elements ["string", "string",...] (created elsewhere)
I need it to create a div.row (I'm using bootstrap) and send to DOM
Appe... |
The following code checks if a string is a pangram or not:
public static class StringExtensions
{
public static IEnumerable<char> EnglishAlphabet
{
get
{
for (char i = 'a'; i <= 'z'; i++)
{
yield return i;
}
yield break;
}
... |
This is the first time I'm parsing an XML file. So I will be grateful for any suggestions on how my code may be improved. Or if you could suggest another approach to solving this problem.
One other question that I have is why attributes 'title' and 'score' have switched in the resulting XML file (xml2.xml)?
I've go... |
This was a simple IRC bot I threw together a long time ago, found recently, and was curious as to if there were any kind of significant improvements that could be made.
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
public class IRCbot
{
// server to connect to (... |
I have written type traits for checking, if given class T has_member, then if it either has_non_static_function_member, has_static_function_member or has_non_function_member. These type traits don't take function arguments of the member nor return type to check signature validity (I will provide other type traits for t... |
Not having found a satisfactory association rules implementation in Python, I set out to code my own. The code below runs reasonably quickly, but the groceries dataset used for testing is peanuts compared to the actual transactions dataset I'll be using in production (think hundreds of thousands of transactions). I'm l... |
The following (stripped) program receives UDP packets on port 5000 and forwards them to port 5001. It may throw socket errors on startup (e.g.: if the port is already in use), but I am not too worried about that.
import socket
RECEIVE_IP = "0.0.0.0"
RECEIVE_PORT = 5000
RECEIVE_BUFFER_SIZE = 4096
SEND_IP = "127.0.0.1"... |
Interest is compounded monthly. Payment doesn't vary from month to month.
Version 1
balance = 999999
annualInterestRate = 0.18
mRate = annualInterestRate/12
high = (((mRate+1)**12)*balance)/12
low = balance/12
guessed = False
def balanceLeft(balance,mRate,minPayment):
monthsLeft = 12
while monthsLeft > 0:
... |
I need to walk through several nested dictionaries in a recursive way and return a value of the type property.
How my code could be improved? Especially, how to do it without a global variable?
field_mapping = {
"logic_index" : {
"mappings" : {
"Patient" : {
"Diagnosis.Diagnosis_Start_Date" : {
... |
Context:
My project has a hand-rolled ORM (... yeah ... I know) ...
built around the MS DataSet objects that represent wrapped collections of rows of DBtables (... yeah ... I know) ...
and which use negative ints to represent identity columns on new Rows which haven't yet been synched with the DB (... yeah ... I know) ... |
I've a class called MassIndexer.java (on GitHub) and it uses chained invocation for building a batch job. Each method assigns a property of this job and finally the job will be started using method MassIndexer#start(). Here's an example for Java EE:
long executionId = new MassIndexer()
.addRootEntities(Company.... |
I've written a mirror folder application in C#. It uses CommandLine for command line parsing. I'm just looking for a general review.
using CommandLine;
using CommandLine.Text;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;... |
So like the title says, if we are close to the end of the month, we can check if a given weekday (or array of weekdays) will fall from the current day, to the end of the month. If any of the given days appear, return true, else return false.
I'm quite inexperienced with JS, and this is my first time using the map func... |
For my training, i've been given an assignment to build a simple, extendable 'grade' String calculator by a given grade.
For now, I had to work by this table:
When the grade was higher then 100, I had to return the String "You must have been cheating".
What I currently came up with is:
public String gradeBy(int grade)... |
Update: This question has a follow-up here
A utility class to handle the ubiquitous "turn off ScreenUpdating, Calculation, Events etc" for executing VBA code, and remembering what those values were before they were changed so they can be restored later on.
Also comes with a module of Unit Tests (courtesy of Rubberduc... |
I've created a vanilla JS function to indent XML strings so they can be more easily read. It uses some pretty nasty regex...yes, I know it's a cardinal sin for XML/HTML, but it works. For instance, this string...
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/enve... |
(See the next iteration.)
Introduction
I was in the mood for some C code and wrote this program for handling a personal telephone record book. One of the goals is strict portability; the code compiles with gcc -ansi -pedantic -Wall ... silently. The second goal is being prepared for dealing with problems (out of memory... |
This is the question:
Write a method that takes in a string and returns the number of letters that appear more than once in the string. You may assume the string contains only lowercase letters. Count the number of letters that repeat, not the number of times they repeat in the string.
How can I make this better?
f... |
How can I make this better?
public int BubbleSortNonEfficient(int[] arr) {
int temp = 0;
int LoopCount = 0;
for(int write = 0; write < arr.Length; write++) {
for(int sort = 0; sort < arr.Length - 1; sort++) {
LoopCount++;
if(arr... |
I'd like to get the code below reviewed on all aspects, specifically I wonder if it's common usage to use let like this, as currently more computations are done in the let statement than in the rest of the code.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square ... |
I'm trying to write a module to dynamically load all the files from my "controllers" folder, and then add them to the main express instance as routers.
The files inside the controllers export an Express router. So the code basically does the next things:
Read the "controllers" dir.
Store what each router exported by t... |
Unrelated to code:
This is my first project in Python using classes and algorithms.
I have spent the last week self teaching myself about queues and stacks, so I am NOT trying to use any Python libraries for this as I would like to know how to implement my own priority queue
About the code:
Dictionary used for prior... |
I was wondering if I can make this better:
public int BinarySearchIterative(int[]inputArray, int Key) {
int min = 0;
Array.Sort(inputArray);
int max = inputArray.Length;
return BinarySearchIterative(inputArray,Key,min,max,0);
}
public int BinarySearchIterative(int[] inputArray, ... |
I want to read only 1 column from file and save it in the list column. I have this code and I don't know how to optimize it. It takes lots of time because I need to call it a lot of times.
column = (sum(1 for line in open(file) if line.strip("\n")))*[0]
counter_row = 0
counter_column = 0
with open(file, 'r') as f:
... |
Inspired by The Beauty and the Strings question, I tried to implement the "Maximum Beauty of String" in a stateless fashion using ES6. Unfortunately, I ran into two places where I had to assign variables.
The questions I have:
How can I remove the state in the reducer for mapLettersByCount?
How can one use generators ... |
I'm playing a bit with extensions for default protocols in Swift 3.0.
I would like to implement rounded(toPlaces places: Int) -> Self for Double, Float.
Both of these structs refer to FloatingType protocol.
I wrote small extension for FloatingType protocol:
extension FloatingPoint {
typealias Exponent = Int // is... |
I'm taking an algorithms class this semester and this homework seemed pretty easy. Easy usually means something is wrong. Not always, though. Through testing, this application successfully answered what was asked for by the professor. What I want to know is if there are any other solutions that fulfill the assignment f... |
I'm trying to learn coding by actually coding my first working and hopefully expandable in future app. Yesterday I asked about optimizing my menu and got some answers about my take on it. Obviously and as expected I got picked bout my casing, code structure and naming. I fully understand and accept criticism as my goal... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.