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 »

2017-05-18 18:05 (4) Answers

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 »

2017-05-17 19:05 (0) Answers

haskell backtracking with integer

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 »

2017-05-16 12:05 (1) Answers

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 »

2017-05-14 20:05 (3) Answers

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 »

2017-05-14 08:05 (1) Answers

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 »

2017-05-11 11:05 (1) Answers

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 »

2017-05-11 02:05 (0) Answers

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 »

2017-05-09 15:05 (1) Answers

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 »

2017-05-07 12:05 (1) Answers

String Alignment in haskell

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 »

2017-05-05 10:05 (0) Answers

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 »

2017-05-04 08:05 (3) Answers

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 »

2017-05-03 23:05 (2) Answers

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 »

2017-04-30 10:04 (6) Answers