instruction stringlengths 71 71.9k |
|---|
I was recently asked this in an interview for a front-end position and I came up with something like the code below, which seems to work but is clunky. (Number.toString() was not allowed.)
function convertBinary(number) {
var n = 0;
var binaryArr = [];
var difference = Math.pow(2, n);
//find out how many dig... |
I'm trying to implement the fast median filter developed by T.S.Huang (HUANG, T.S. 1981. Two-Dimensional Signal Processing II: Transforms
and Median Filters. Berlin: Springer-Verlag, pp. 209-211.).
http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=1163188&tag=1
Please review my code. My most important issue here is ... |
This is my very first foray into Clojure (I'm normally a Python-pushing data-type). I'm trying to create a simple term-document matrix as a vector of vectors, out of a vector of strings.
For those who aren't into textmining, the term-document matrix is a dataset in matrix form where the column names represent every wor... |
I would like to create a regex that will validate that a string is an equation made up of a single digits and either the * or + operator and is no longer than 100 characters. So these would be valid:
1+2*3*8+0
9
9*9
And these would not be valid:
1++1
12+1
2*25
1+
47
+
+1
11
I came up with the regex below to accompli... |
I totally suck at recursion. I have a function that works but it also looks horribly wrong. I would love to 1) Know how to write it properly 2) Know about resources to read/study so that I don't get so stuck again.
The function is simple: given something like this:
queryConditions = {
type: 'and',
args: [
... |
I have function that takes all of the attributes passed to a custom tag, and returns a select subset. I am try to convert the current function, which does not use closures
string function passThrough(required struct attr) output="false" {
local.result = "";
for(local.myKey in arguments.attr) {
if (var... |
I am now developing a product, which will use Unity & Repositories when it comes to data management. I will demonstrate on a simple example. What we want to do, is to create an app with calendar control, where user (e.g. manager) will be able to store holidays for his employees.
First define our models:
We have a class... |
How can I reduce the lines I use with this code block?
if ((test.contains("1.jpg") || test.contains("1.png")) && (maxP == false)){
page++;
add = 1;
if (QFile().exists(basepath + spage + ".jpg")){
p_left = basepath + spage + ".jpg";
}
else if(QFile().exists(basepath + ... |
Problem statement (extracted from cracking the coding interview):
Write a method to replace all spaces in a string with'%20'. You may assume that
the string has sufficient space at the end of the string to hold the additional
characters, and that you are given the "true" length of the string. (Note: if implementing
in ... |
I'm developing a C# Poker app and I currently use the modulus and the divide operator % , / and dividing by 4 because there are 4 cards of the same type but with different colors. The deck of cards for playing Poker consists of 52 cards. I start counting them from 0. If we take the cards starting from Ace up to King, w... |
How can I optimize the next function to work faster? The function must prepare a list to put in a CSV file. The list must contain values of average percentage of sleep per minute counted from scores - a list of the form [[stage, time]], where stage could be 'S', 'R' or 'W' and time is in '%d %H:%M:%S' format; it's some... |
This code implements a binary tree for integers. How can I improve it?
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
///////////////////////////////
struct node{
int data;
struct node *left;
struct node *right;
};
///////////////////////////////
struct node *newnode(int value)... |
I have created a DB connector class with PDO.
Do I need to add, delete or edit anything in this code?
<?php
class Config extends model{
// The state of the config
public $configState = array();
// THE only instance of the class
private static $instance;
public function __construct(){}
/**
... |
I wanted to ask your opinion about my code created for acccount.php page for editing the data of each logged-in user.
I wanted to have more of an opinion on your right syntax, though maybe it could be improved.
require('includes/config.php');
//if not logged in redirect to login page
if(!$user->is_logged_in()) { ... |
I'm currently trying to write an app with Cordova and ReactJS. I haven't used ReactJS before, so I'm very confused by the mixed usage of Babel, JavaScript and JSX. I try to use JSX where I can because I like it, but I dislike Babel, which is used in many tutorials as well. I haven't quite understood what Babel is used ... |
Given a string and a non-empty substring sub, compute recursively the largest substring which starts and ends with sub and return its length.
sub_sandwich("catcowcat", "cat") → 9
sub_sandwich("catcowcat", "cow") → 3
sub_sandwich("cccatcowcatxx", "cat") → 9
I'm not very satisfied with my code and I'm not sure how I ... |
Following on from my previous question, I finally got round to actually doing the A* search for the Graph<MapTile>. The changes to the code from the previous question were pretty minor (and no API change) so I won't include the code again.
First, I defined an interface for a hueristic.
internal interface ICartesianHeur... |
Now I have that parallel Quicksort for (primitive) integer arrays.
ParallelIntQuicksort.java:
package net.coderodde.util;
import static net.coderodde.util.Util.median;
import static net.coderodde.util.Util.swap;
/**
* This class implements a parallel Quicksort.
*
* @author Rodion "rodde" Efremov
* @version 1.6 ... |
I recently finished reading Learn you a Haskell for great good!. Even though some topics are a bit over my head (Monads anyone?), I wanted to try my hand at a fairly difficult problem. I chose to write a eval function that correctly handles parenthesis and the order of operations. I think this is pretty good, but I can... |
I'm a beginner and wrote a program that takes a text file and writes a downcased vocabulary list to another text file. I intend to use it mainly to work with text in Spanish, so I added a line to downcase capitalized-accented words. I'm wondering if there is a more efficient way of reading from the original file, as we... |
My console TicTacToe program
This is my first large project attempt and I want to learn how to keep classes as anonymous as reasonable and as protected/secure as reasonable.
The program works as intended and I think it meets the requirements but can you guys share some pointers?
class TicTacToe
WINNING_SCORES ... |
I want to run all the coroutines from the list in a pool of constant size and would like to ask if this is the right way how to achieve it. Is there any built in solution for this problem? I have not found any.
def subprocess_pool(coroutines, pool_size=3):
loop = asyncio.get_event_loop()
event_finished = asynci... |
I'm not that comfortable with properly writing jQuery. On my website I've used a lot of jQuery plugins and basically just dumped all the different initiating scripts between two <script> tags before the closing body tag.
I'm getting a few bugs with the various plugins which I have a feeling is because the code is messy... |
I'm trying to build a Web API using best practices, based on a simple proof-of-concept using students.
My goal is to build the system using:
Onion Architecture to seperate concerns.
Service-Repository for interaction between BLL and DAL.
Autofac for IoC, to control injected dependencies.
NPoco for micro-ORM.
Moq for m... |
Steps:
Get AMOUNT from a call to API endpoint /a, e.g. AMOUNT == 5 (in the code it is set to 2)
Use this AMOUNT to make AMOUNT calls to endpoint /b receiving JSON
Result might be: [{a: 1, b: 2}, {...}, {...}, {...}, {...}]
Use this AMOUNT to make AMOUNT calls to endpoint /c receiving JSON
Result might be: [{c: 3,... |
We have a process that outputs to log files in the format /var/log/xxx/YYYY_MM_DD.log - the file name is chosen programmatically and is not rotated using logrotate or anything like that. We want to automatically tail the latest file and pipe that to slackcat so that we can see the logs in a certain slack channel.
I cam... |
Are there any suggestions about this?
#include <memory>
#include <unordered_map>
#include <vector>
#include <iostream>
using std::cout;
using std::endl;
using std::unordered_map;
using std::shared_ptr;
using std::make_shared;
using std::string;
struct TrieNode {
bool isLeaf = false;
unsigned int child_num = 0... |
I have a tree processing application where some of the nodes are "executed" in parallel and some in series. I managed to do this but I feel that the solution looks a bit "hacked up" and can be improved on.
I have a JobObject class which I am using to build a tree:
[Serializable]
public class JobObject
{
public int ... |
Trying to learn the factory design pattern, came up with some code based on a Shape Factory (found this example here). Is this the right way to implement the factory pattern?
interface Shape{
void draw();
}
class Rectangle implements Shape{
@Override
public void draw() {
System.out.println(" Draw... |
I am currently using this:
Path path = Paths.get("c:\test\test.txt");
byte[] all= Files.readAllBytes(path);
The problem with this is that I have to load the entire file in memory. My requirement is to read the file byte by byte, but in a manner like first 4 bytes mean X, next 16 bytes mean Y and use next 48 bytes for ... |
This is the primary module for my APL interpreter. The general idea is motivated by my two Stack Overflow questions, but the details I fear are easy to get wrong and I suspect there are a few corners that my eyes simply don't observe critically since they have the authority of having lain in the file so long without ch... |
Need a way to test a web crawler.
Threw together this web server that will replay previously saved pages from a real web server.
Headers
#include <stdexcept>
#include <memory>
#include <map>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cst... |
I need your review and suggestions how to make this code better. I'm just learning recursion and sure that this solution is not ideal.
Question:
Write a function that given an input array of integers with a varying length input integers array, and the desired target_sum, returns the number of combinations, of any lengt... |
I recently made a typing game in JavaScript and I would like it to be reviewed so I can become better knowing where I made mistakes and what I should improve on.
CodePen
var temp = document.querySelector('.time');
var button = document.querySelector("button");
var words = document.querySelector(".words");
var t... |
I have recently learnt about RAII and exceptions and I have been trying to implement them into my code, but I have met an impasse.
With this code here what I am trying to do is manage everything that is being created so that there is nothing left over for when the program ends. I have deliberately set it so that media ... |
I am self studying C++ from Robert Lafore's OOP in C++. I am solving the first exercise questions of chapter-3 loop and decisions. I've written three different codes using different approaches. I want to get feedback over my codes like a teacher is supposed to give feedback to his student. I want to get feedback over e... |
How can I improve this code
Please tell proper indentation and usage of camel-case.
#include <iostream>
using std::cout;
struct Node
{
int data;
Node* next;
};
Node* Create(int data){
Node* root=new Node();
root->data=data;
root->next=NULL;
Node* head=root;
return head;
}
void push_back(... |
I found another user asking for an application to be written, it sounded simple enough and a good way to "work out" my C# "muscles" and try to get them into a better "shape". I really liked the idea of learning the difference between people's ages so I decided I would code this, I did enlist the help of Stack Overflow... |
Its my first attempt to unit-test in Js. Not yet TDD.
What I can change?
EventsPersistancyService.js:
var Q = require('q');
var EventsPersistancyService = {
accept: function acceptService(msg) {
var worker_id = WorkerCacheService.get('some login');
var app_category = AppCategoryService.get('some');
var... |
From SICP
Exercise 1.11: A function \$f\$ is defined by the rule that:
\$f(n) = n\$ if \$n < 3\$, and
\$f(n) = f(n-1)+2f(n-2)+3f(n-3)\$ if \$n >= 3\$.
Write a procedure that computes f by means of a recursive process.
Write a procedure that computes f by means of an iterative process.
Please review my code.
I thi... |
The code should ask the user multiple solutions and find the problem with the users phone. The program should be efficient as possible and have a possible of 10 outcomes. I would like some tips on how I can make the code more efficient and meet the task requirements. This is what the task states:
Analyse the requireme... |
I have a Java application that uses a few switch statements to get user information about students and classes.
I have three MySQL tables:
students
student_id | student_name | hometown
classes
class_id | classname | description
student_x_classes
student_id | student_name | class_id | classname
The code works fine, bu... |
I have an interface with two functions. This interface is being inherited by an abstract class which implements just one of those functions. The other one is left to be implemented by the derived classes of the abstract class.
public interface ICombination
{
bool Check(IReadOnlyList<int> hand,UsersProperties user);... |
I just wrote a basic worker class for this person
https://stackoverflow.com/questions/35827459/assigning-a-new-task-to-a-thread-after-the-thread-completes-in-c
and I wanted to ask if the code has been written properly, it's supposed to have multi-thread support.
Any feedback would be nice.
Live Demo
class Worker
{
publ... |
I have wrote code that takes an input file text that can be compressed, and should contain ascii values, and then a new file is created with an appended ".lzw" and that file can then be decompressed. I want to know if I can improve this code, e.g. Simplifying buffer read/write bytes using RandomAccessFile.
Compression... |
Here's a Tic-Tac-Toe program I wrote in Python. How can I improve it (.eg. make it more readable)?
class Gameboard():
def __init__(self):
self.gameboard = {1:' ' , 2: ' ', 3: ' ', 4:' ', 5:' ', 6:' ', 7:' ', 8:' ', 9:' '}
def setPeice(self, user, position, gameboard):
gameboard[position] ... |
I have a Minimum Difference algorithm, and I wanted to expand on it by printing the actual elements that were subtracted. I'm just wanting to know if this is the best way to do it.
public static int findMinimumDifference(int[] arr) {
int minuend = 0; //initialize them here
int subtrahend = 0;
Arrays.sort(... |
I am a beginner in assembly. This program calculates:
(Z+Z)+(X-Y)
DATA_SEG SEGMENT
X DW 2
Y DW 3
Z DW 5
RES1 DW ?
RES2 DW ?
DATA_SEG ENDS
CODE_SEG SEGMENT
ASSUME CS:CODE_SEG, DS:DATA_SEG
;*... |
This code simulates a distributed averaging protocol. There is a network of nodes, and at the clicks of a Poisson process:
A random node wakes up
Transmits it's current average to all the nodes it is connected to
These nodes have a coroutine which waits to accept new values and compute the average.
from numpy.random ... |
I have implemented some sort of the strategy pattern using an abstract class and an interface:
public interface ICombination
{
void Check(int[] hand, UsersProperties user);
void UpdateHand(UsersProperties user, int combinationType, int powerType);
}
public abstract class ICombinationAnalyzer : CardVariables, I... |
So I have written a custom iterator for std::map that allows access to just the "values" of the map and I was wondering if it is the "correct" way to implement std::iterator (acts identically to std::iterator).
Here is the implementation I have written:
template<typename K, typename V>
class MapValueIterator : public s... |
Once upon a time, there was a duck that wanted to know where and how user code was calling into the VBA standard library and Excel object model. To match the rest of its API, the poor little duck had to dig through pages and pages and pages of MSDN documentation, and instantiate a Declaration object for each and every ... |
I decided to try to understand the basic idea behind Dijkstra's algorithm better so I implemented it in JavaScript (the only language I am proficient in as of now) so I could really see what was happening in the Chrome debugger.
I chose not to use a priority queue or a heap in my implementation, but I do return both th... |
EDIT: This code is now public on GitHub with more focused purpose in case anyone is interested. Thanks for the help!
This is only used on Mac machines. I know that there is a Python implementation of youtube-dl and several for ffmpeg, however I chose to use subprocess so that I can see the real-time stdout/stderr of ... |
I wrote a simple Python script that will calculate income for a given month and hourly wage by parsing the contents of a log file. The instructions for how to use it is in my GitHub account here. The script is used in the command line with the following command
python calculate_hours.py MY_LOG.txt MONTH YEAR HOURLY_WAG... |
I'm using TurboPower LockBox for the first time, and using the TwoFish algorithm to first encrypt a password, and later retrieve the password by decrypting the generated hash.
I would like to know if the approach that I'm using is good, and if there are any pitfalls to avoid. Its a simple use case for my application t... |
The following code was written to be a submission to this challenge on PPCG.
It uses this algorithm, the Meissal-Lehmer method. I follow the Wikipedia entry pretty naively, except I tried to memoize the phi function.
Please see @Shepmaster's answer for cleaned up, more idiomatic Rust.
I am looking for ways to improve ... |
I am developing application that goes through 2 websites and gets all the articles, but my code is identical in most parts, is there a way to optimize this code actually :/ (TL and DN are the naming conventions of the news papers)
public class Main {
public static void main(String[] args) {
BlockingQueue<... |
I've implemented a singly linked list in Java as a practice exercise and would appreciate a review.
LinkedList.java
public class LinkedList {
private Node head;
private int size;
public LinkedList() {
}
public void addToEnd(char data) {
addAtIndex(data, size);
}
public void addTo... |
I'm learning to program with PHP, so I ask your help to check if my class user.php is ok.
include('password.php');
class User extends Password{
private $_db;
function __construct($db){
parent::__construct();
$this->_db = $db;
}
private function get_user_hash($username){
try {
... |
The code bellow generates all the permutation(with repetitions) for given character set. Is there any better(simpler, more performant) way to do that?
var assert = require('chai').assert
var _ = require('underscore')
var multStr = function(left, rigth) {
return _.chain(left).map(function(el) {
return _(rigth).ma... |
I've implemented a "remember me" automatic login if no session has been set, but a remember me cookie is on their computer. I'm concerned about security and I'm not the best. I'm relatively new to OOP (just started a learning a week ago).
$database = new db;
if (isset($_SESSION['info'])){
$token = $_SESSION['info'][... |
Basically I am in argument with my colleague, I say this template (view) has to be fully refactored and all instances of duplicate code has to be removed. He disagrees and don't want me to touch it. Can you please do a code review as 3rd party opinion? This is magento phtml template file for checkout review step.
<?php... |
I have to flatten a large number (>300k) dicts to write them to a csv file.
Example:
dict = {
a: b,
c: [
{
d:e
},
{
f:g
}
]
}
becomes:
a, c.0.d, c.1.f
b, e, g
The dicts can be really big with a lot of dicts as values.
My function to flatten them generica... |
We had to write a program that would perform rotation of elements in an array. The array size was entered by user, so it had to be in a sense, dynamic.
Rotation or Circular Shifting
Initial Array: 1 3 7 4 8 6 5 2 9
Shift by: 4
Final Array: 6 5 2 9 1 3 7 4 8
Notice, in rotation, each elements position increased by shi... |
I'm working on a sliding puzzle, one little project as a hobby, and yesterday I thought that instead of working on an algorithm to figure out a solved puzzle, it would be easier to make an algorithm that "shuffles" the tiles from a solved position. I came up with this and it works, but I don't know if it's elegant enou... |
I want to implement code for inserting a new Node in a binary search tree in java so please check if my code is correct ,,, Here is my method :
public class BinarySearchTree {
…
public boolean add(int value) {
if (root == null) {
root = new BSTNode(value);
r... |
I don't want to serialize everything. I created a custom attribute DoNotSerializeAttribute. If some property in info contain that attribute then ignore it and do not serialize it.
Is my code bug-free? Maybe I can improve it or I miss something?
class Program
{
static void Main(string[] args)
{
var s = S... |
Sorry for being a little abstract but I have attempted to concoct something simple but it seems to spiral out of control. So I was thinking maybe I am taking the wrong approach.
Here's what I am trying to do:
When I get a message it gets de-serialized into its own class. I would like to use a strategy pattern to choo... |
Edit: since originally posting this I have: realized that it won't run from irb/pry, and refactored to remove some sleep calls. I've also separated the sections into different code blocks.
I wanted to make a program for running background jobs (ruby scripts).
The goal was to continuously run a background script on an i... |
This is my solution to an assignment on the fractional Knapsack problem. I take as problem input the following pieces of information:
The number of item types
The total weight limit
For each item type, the total available weight of that item type and the value per unit of weight
The output is the amount of weight to ... |
I am working on a MSSQL Database (for a program called Sage 200). There are many tables in the database, however, I want to be notified of changes (new record inserted or existing record updated) via Trigger on a specific table.
I also want to support multiple rows on this table being updated at same time also.
When a ... |
Goal: I am trying to build teams of 5 people. Each person has an integer elo (rank). My goal is to make all the teams as equal/fair as possible, by having the average elo of each team be as close as possible to one another.
Approach: My initial thought was to go through the list of elos and take the highest elo player ... |
I'm quite new to Python and I have been trying to find a way to search a csv for a test string and return the index of that item in the csv.
I am using the code below but find it hard to believe that there is not a function built in to the csv module to do this.
I want to perform the 'lookup' so that I can select the... |
Wrote a small bash-script today that downloads the latest swedish wordpress archive , extracts it and writes wp-config.php
Would appreciate any feedback that could improve it / prettify it.
The script assumes that the database name & the username is always the same.
#!/bin/bash
#Download wordpress tar.gz
echo "Laddar ... |
I have need for a task scheduler determined by a directed graph. The tasks are held in a std::vector<task_type>, while the dependency graph is held in a adjacency_list<vecS, vecS, bidirectionalS> (bidirectionalS so that I have access to the in_degree() function). A single dispatch will start the tasks. Are there obviou... |
Working on a little Sprite Kit game, I had the problem that I wanted a couple of things to wait until a group of sprite nodes had stopped their animation.
I decided to use a GCD dispatch group to monitor the sprites' actions. The nodes that I was concerned about were all instances of the same class, so I gave that cla... |
I have just finished writing a simple Python3 program which converts a custom input file (or multiple files within the same folder) to an XML template.
It works as it is, but I think that I somehow messed up the code as I had to open several files, append to them, close them, loop through their lines and so on.
I thoug... |
I have been using a static class to connect and retrieve information from a MySQL database and also reading about how static works in php. I'm still not sure if the code is bad or not and why (besides the usual static are dangerous). Also, code improvements suggestions will be appreciated.
class Database {
const S... |
I have created a simple application that has grown a little bit. Though most likely it won't grow anymore, I have looked back and I realized that it has become a little monster in terms of how many almost identical properties and methods I have created. Please let me know how this could be made more manageable etc.
Pur... |
I am working on a LargeInteger class to store Integers beyond the size of long long as a dynamic character array. I have overloaded most of the relevant operators to be used with the large integers.
I would like to find a way to further streamline the addition/subtraction. I think it ought to be possible to only use a ... |
In my current project I have objects of the following structure:
CanvasBundle - Object
Some elements...
gridCanvas
axesCanvas
functions[] (contains unknown number of functionCanvases)
overlayCanvas
I'd like to write an iterator which would iterative over all the canvases (grid/axes/func/func1/func2/.../overlay).
I've... |
I have this Subroutine that works, but I have recently started updating the sheet and adding new columns. I'm finding updating the current macro to be a bit of a chore.
Is there a way to use named ranges instead of declaring the cell ranges as in this code?
Private Sub Reset_Rows_Click()
Const USED_RANGE ... |
This is my implementation of MinHeap in Java.
public class MinHeap {
int[] heap;
int pos;
int size;
public MinHeap(){
this.size = 2;
heap = new int[size];
this.pos = 0;
}
private void minHeapify(int index){
int child =... |
Attempting to see whether using 196 as a respectively in my program will have a result or not, I made a simple function to test it. Now the 196-Algorithm requires this:
Take any positive integer with at least two digits, a
Take a and reverse it (for example 23 becomes 32)
Now add the new number to a
Repeat the process... |
I am trying to implement a machine learning algorithm (k-nn for example). But before I attempt to do that I was hoping for some feedback on my current Main class, which essentially builds 8×8-pixel matrices into an array to be manipulated later. (See the data description and sample dataset.)
import java.util.*;
import... |
Similar to this question here, I am trying to implement sort algorithms in Julia, as part of a package.
The code for the implementation is as follows:
"""
The swapping function implementation
"""
function swap!{T}(x::AbstractArray{T}, a::T, b::T)
tmp = x[a]
x[a] = x[b]
x[b] = tmp
return x
end
"""
`insertsor... |
I have a java component that was using a lot of string literals that I need to make comparisons on and return booleans based on these comparisons.
In order to make the code more robust I externalized these strings first as class constants, then after other classes started to use these constants I had to separate them t... |
I am aware of the Python modules galore to do this, but this was partially a learning experience and partially all the functionality I need and no more.
I'm writing a simple interpreter for a Forth-like language, and because my CLIs are of the most high quality,[citation needed] I need to make the entire source (docstr... |
I had a logging function…
@task
def log_request(label, target, request_as_dict):
# Detect flood
# In general this task do not process misuse. But it can send
# an alarm to another celery task if something strange happened.
if incr_with_ttl(INDICATOR_KEY, INDICATOR_TTL) >= INDICATOR_THRESHOLD:
p... |
Yesterday a friend of mine asked on U&L: How to optimize 'grep'-and-save?
I will summarise shortly. The output of the torque pbs queueing system tool qstat should be parsed to contain only the Job ID, Queue, Jobname, and the node it is running on. This should be appended to an existing file, filtering out the duplicate... |
I created a class that I plan on using to autoload my project classes (20-30 classes) maximum. I wonder if there is anything, anything at all, that I can improve on this class to improve it any further.
Please let me know your thoughts below.
<?php
/**
* YodaCMS, content management system.
*
* @info This cl... |
I haven't done any programming in a while, and I'm getting back into it. I made this Snake clone to refresh me a bit, and I would like to get some feedback in the "elegance" and "well-done"-ness of the code.
main.cpp
#include "Game.h"
int main()
{
Game::run();
return 0;
}
Game.h
#ifndef __GAME_H__
#define __G... |
I am a relatively experienced WPF developer who has had good exposure to MVVM. I have been developing legacy WinForms applications for a while and have recently been asked to fully re-write a large one.
To do this I want to use TDD and in order to facilitate this and make the application as extensible as possible goin... |
Here is one of my programs that utilized memoization and array to improve performance and memory usage. The performance seems satisfactory but the memory usage is ridiculous and I can't figure out what's wrong:
{-# LANGUAGE BangPatterns #-}
import Data.Functor
import Data.Array (Array)
import qualified Data.Array as Ar... |
To import the data contained into the file my_file.txt that have the form:
Label[0] = 0.980252
Label[1] = -nan
Label[2] = -nan
Label[3] = -nan
Label[4] = 0.664706
Label[5] = -nan
Label[6] = -nan
Label[7] = -nan
Label[8] = -nan
Label[9] = -nan
Label[10] = -nan
Label[11] = 0.800183
Label[12] = -nan
Label[13] = -nan
Label... |
A little while ago, I had to write a little C# application to recover my HDD data (full context on this question)
To answer my problem I developed a console application which job was to recursively copy the entire folder tree of my HDD.
The code can be seen below :
using System;
using System.Collections.Generic;
using ... |
I'm trying to come up with a general way to correctly round floats with Python, given the known limitation of round():
Note: The behavior of round() for floats can be surprising: for example, round(2.675, 2) gives 2.67 instead of the expected 2.68. This is not a bug: it’s a result of the fact that most decimal fractio... |
I have written a program to display the kth permutation sequence of a string made up of letters 'O' and 'Z' . I tried optimizing it but my code have not passed test cases due to timeout issues.Looking for someone who can guide me in optimizing the code i posted below.
public static void main(String[] args) throws IOExc... |
I've implemented a SortedList which takes in streams of floats and returns a median at any point.
public class SortedList {
float[] list;
int pos;
int capacity;
public SortedList(){
this.pos = 0;
this.capacity = 2;
list = new float[capacity];
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.