## How to properly count occurrence in arrays?

I've got an in depth array (arrays of arrays). I'm trying to make a decent function without using any extra methods and JS designs (like closures). This is a working solution (but a bad one because of the global variable) var counter=0; functio...
more »

## Nodejs createCipher vs createCipheriv

I am currently trying to encrypt data at rest with NodeJS, I have read in the Node API docs that createCipher is not recommended. The implementation of crypto.createCipher() derives keys using the OpenSSL function EVP_BytesToKey with the digest...
more »

I am a Haskell newbie. So, I would like to ask a simple question. I have to find with help of backtracking the (unique) number containing 9 numbers with the following characteristics: The numbers 1/9 appear exactly once. The first k numbers...
more »

## PHP - Best Way to Construct Timeline Data From Sets of Beginning and Ending Timestamps

I have a series of array items that looks like: [{ "id": 1, "start": "2017-04-05 16:27:08", "end": "2017-04-05 16:30:45" }, { "id": 2, "start": "2017-04-05 16:15:08", "end": "2017-04-05 16:22:45" }, { "id": 2, "start"...
more »

## Javascript - all lottery combinations generator via recursion

I am trying to write an algorithm that generates all lottery combinations recursively. Here is a none recursive variation that can be used to get C(max,6). e.g. c(7,6) let min = 1; let max = 7; let lotteryNum = 0; let outputString = []; for...
more »

## An algorithm for grouping by trying without feedback

Tagged this as Python because is the most pseudo-y-code language in my opinion I'll explain graphically and the answer can be graphical/theorical too (maybe its the wrong site to post this?) Let's say I want to make an algorithm that solves a simpl...
more »

## Criteria to sort numbers as strings

I know that a similar question exists here Javascript string conversion and array sort , but I need help in my version of the solution. Task: The weight of a number is the sum of its digits. For example 99 will have "weight" 18, 100 will have "weigh...
more »

## Sort Array function in C

I've written this function to sort an integer array, here flag is an indicator whether to sort the array in ascending or descending and size is the size of the array. Can you tell me where I've written something wrong, I've checked the algorithm too....
more »

## How can i measure latency of noisy delay line with attenuation, having transmitted and recieved sample buffers?

I want to write sonar/radar like application. For sake of simplicity (and not to use adruino and specialized RTOS) - I simply used using audio in/out analog ports of a motherboard integrated card as an sample hardware setup + Windows API Steinberg AS...
more »

## How to convert Set containing values into string

public static void main(String[] args) { // TODO Auto-generated method stub String str = "abcdaa"; dups(str); } public static void dups(String str){ HashSet hs = new HashSet(); char[] ch = str.toCharArr...
more »

## Purpose And Workings of `Doc` In Real World Haskell, Ch 5

Chapter 5 of Real World Haskell introduces a pretty-printing library, specifically with an abstract Doc, in the context of pretty-printing JSON: Instead of rendering straight to a string, our Prettify module will use an abstract type that we'll c...
more »

## How to draw an infinite Hexagon Spiral

I'm trying to create a Structure as shown in the Screenshot below. Is there a way to build an Algorithm for this in JavaScript to get the X and Y Coordinates of each red Point in chronological order to generate an infinite Spiral depending on a speci...
more »

## Homework: Sorting Algorithms

I am supposed to create an algorithm that sorts according to these steps: Method 1 Select the lowest number in the list and swap with the first number. Select the lowest number in the list and swap with the second number. Start checki...
more »

## How can a sorting algorithm have a space complexity of O(1)?

I'm learning about different sorting algorithms and their time/space complexities and saw that algorithms such as bubble sort and insertion sort have a space complexity of O(1). This struck me as weird, because surely the lowest space complexity pos...
more »

## Change in order of duplicates after sorting by Quicksort algorithm

I read somewhere(apologies that I do not remember where) that a correct sorting algorithm should sort the duplicate values in the order in which they appear in unsorted sequence. Example: 5(A), 2, 4, 5(B), 6, 5(C), 1, 3 5(A/B/C) : Here A, B &a...
more »

## Designing a cache-optimized N-ary tree

I'm looking for ways on how to best design a N-ary tree that will effectively use the cache. I expect the vast majority of operations on the tree will be node-to-root traversal so thats the usecase I want to target, meaing I'm fine with insertions/de...
more »

## Using the same dataset and algorithms, WEKA application and source code validation results don't match

Using the source code in http://www.programcreek.com/2013/01/a-simple-machine-learning-example-in-java/ , I've run the java application. Then I've installed the WEKA 3-8-1 (http://www.cs.waikato.ac.nz/ml/weka/downloading.html) and run the same algo...
more »

## Efficient algorithm to find 2-step neighbors for all vertices in a directed graph

I have a large directed graph in csv format (~14GB) of edges represented as integers in the following format: node1,node2 3213741,23521361 3213741,6532710 3213741,12340611 3213741,6457392 3213741,9682135 6567133,12956771 6567133,23860123 node1 is ...
more »

## Sort a set of disks in minimum number of moves

So this question is more of an algorithm/approach seeking question where I'm looking for any thoughts/insights on how I can approach this problem. I'm browsing through a set of programming problems and came across one question where I'm required to p...
more »

## How can I make my Quick Sort Algorithm sort the arrays in both Ascending and Descending order?

Currently my Quick Sort algorithm sorts the array in Ascending order in case 1 but I would like to make it so that when the user selects option 2 (case 2) then it sorts the array in Descending order. Do I have to create 2 separate algorithms for each...
more »

I'm working on an assignment in Haskell. The assignment is to give the optimal alignment of two strings given scores for word matches, misses and gap insertions. Here is our code so far. The first step is to make it work using brute force and later ...
more »

## How do I modify my Quick Sort Algorithm so that it can sort Double data type arrays?

I used this Quick Sort algorithm to sort arrays of integers but I also want it to sort arrays of doubles. Which variables do I need to change to make this work? I tried changing many different combinations of data types. Any help is appreciated. ...
more »

## Using class as functions and "global" variables container: bad design?

I spent last months rewriting from scratch a new version of my Python algorithm. One of my goals was to write a perfectly documented code, easy to read and understand for "anyone". In the same project folder I put a lot of different modules and each...
more »

## Modify sorted array or sort the array everytime?

Problem: Given an array of size N, print the sorted sub sets of size K with consecutive elements. N = 10, K = 4 8 4 7 5 1 10 3 9 2 6 Output: 4 5 7 8, 1 4 5 7, 1 5 7 10, 1 3 5 10, ... Approach 1: Sort all the sub sets and print. Complexity Analy...
more »

## Specific element permutation within an array of characters in JAVA?

How can I list all uppercase/lowercase permutations for any letter specified in a character array? So, say I have an array of characters like so: ['h','e','l','l','o'] and I wanted print out possible combinations for say the letter 'l' so it would pr...
more »

## Cannot retrieve all the data from Hashtable

I am trying to code an algorithm in C that reads a huge file ( more than 750.000 lines) , separates each line by some specified delimiters , and saves the data into a structure , which is then saved into a Hashtable. Everything goes fine until I want...
more »

## What is the meaning of "serial thread-confinement" when writing parallel algorithms in java?

When reading documentation of the Java 8 Spliterator I encountered the notion of "Serial thread confinement". Preciselly the documenatation says: Despite their obvious utility in parallel algorithms, spliterators are not expected to be thread-s...
more »

## Function to print out list object members won't work

void Entity::newEntity() const { Entity toAdd; std::cout << "Enter Entity Name : "; std::cin >> toAdd.name; if (entityListIsEmpty()) toAdd.index = 1; else toAdd.index = end->index + 1; EntityList.push_back(toAdd...
more »

## Editing a Merge Sort to sort in Descending Order C#

I am going through a sample piece of coursework that I had been sent by a friend to get myself ready for University coursework in my next year. I have been attempting to create a sorting and searching system to handle assorted data. For this task I h...
more »

## Top-down merge sort algorithm producing mismatched list

I attempted to take the top-down merge sort algorithm from this wikipedia page and make it into C code, but the result doesn't produce correct results. here is the code: #include <stdio.h> int A[10] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; int B[1...
more »

## Segregate Even and Odd numbers, preserve order, O(1) space， O(N) time complexity

Input = {12, 34, 45, 9, 8, 90, 3} Output = {12, 34, 8, 90, 45, 9, 3} Given an array of integer, rearrange all even integer before all odd numbers, but keep their original sequence in array, using O(1) space and O(n) time complexity. Thought: A...
more »

## Algorithm to "synchronize" (side effect) a list with another? (Without using swaps)

I'm trying to write a method to synchronize a list with another under some constraints, and so far I haven't managed to think of a proper algorithm to do that. Here are all the details: After the method call, the target list will have the exact sa...
more »

## How to get all the possible matches of two lists?

For example, I have a list which contains some Lecture instances, each lecture has a certain number of students attending this lecture and another list which contains some Classroom instances, each classroom has a maximum capacity. Now I intend to a...
more »

## Time complexity of this mergesort algorithm for linkedlists

I've run this algorithm and I know that it works but I'm not too sure about its worst case time complexity. I think that the worst case time complexity for this mergesort algorithm is O(n log n). I would be thankful for anyone that can provide a seco...
more »

## Scala : Sorting list of number based on another list

I am implementing an algorithm in scala where I have set of nodes (Integers numbers) and each node has one property associated with it, lets call that property "d" (which is again an integer). I have a list[Int] , this list contains nodes in the de...
more »