algorithm

C# equivalent of python slice operation

In python, I can take a list my_list and rotate the contents: >>> my_list = list(range(10)) >>> my_list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> new_list = my_list[1:] + my_list[:1] >>> new_list [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] What's the equivalent way in C# to create a new list that is a made up of two slices of an existing C# list? I know ...

Convert a nested dataset to a flat dataset, while retaining enough data to convert it back to nested set

Say I have a dataset like (1, 2, (3, 4), (5, 6), (7, 8, (9, 0))) I want to convert it to a (semi) flat representation like, ( (1, 2), (1, 2, 3, 4), (1, 2, 5, 6), (1, 2, 7, 8), (1, 2, 7, 8, 9, 0), ) If you use this, (taken from SO) def flatten(iterable): for i, item in enumerate(iterable): if hasattr(item, '__iter__'): ...

Algorithmic Approach to generating all combinations based on a large Truth-Table

I apologize if this has been answered elsewhere, but I have yet to find it using my limited algorithmic terminology. ;) My situation is this - I have a variable number of data elements, each of which has been tested against each other data element to determine compatibility. The compatibilities are stored in the equivalent to a 2-dimens...

Derive integer factors of float value?

I have a difficult mathematical question that is breaking my brain, my whiteboard, and all my pens. I am working with a file that expresses 2 values, a multiplicand and a percentage. Both of those values must be integers. These two values are multiplied together to produce a range. Range is a float value. My users edit the range, and I ...

Optimal Multi-page Navigation

I have encountered many web sites and even desktop applications that have a breadcrumb type control to navigate pages of information. For example, given X pages where the user is currently on page N, SOFU has a bread crumb control that presents page navigation in the form of: (X[N-1])(X[0])...(X[N-2])(X[N-1])(X[N])(X[N+1])(X[N+2])...(...

Guessing an unbounded integer

If I say to you: "I am thinking of a number between 0 and n, and I will tell you if your guess is high or low", then you will immediately reach for binary search. What if I remove the upper bound? i.e. I am thinking of a positive integer, and you need to guess it. One possible method would be for you to guess 2, 4, 8, ..., until you g...

What kind of sorting is this?

Say I have a list of integers, where each element is a number from 1 to 20. (That's not what I'm trying to sort.) Now, I have an array of "operations", where each operation: Removes certain (known) numbers from the list and Adds certain other (known) numbers to the list and Is unable to handle the list if it contains certain (known) n...

Understanding Ukkonen's algorithm for suffix trees

Hello, I'm doing some work with Ukkonen's algorithm for building suffix trees, but I'm not understanding some parts of the author's explanation for it's linear-time complexity. I have learned the algorithm and have coded it, but the paper which I'm using as the main source of information (linked bellow) is kinda confusing at some parts...

Pixel Processing Algorithms

Hi, I am looking for some information on pixel processing. I am interested in the following algorithms: Gamma correction Edge detection Changing overall brightness Converting to grayscale etc. Where can I find articles that have a description of how this can be achieved? Thanks. ...

find minimum number of vertices in unweighted graph

I have got an undirected weighted connected graph. If I select one vertex I automatically select all the vertices connected directly with it. What will be the algorithm so that I am able to select all the vertices of the graph using minimum number of tries? In each try I select one vertex. For example for adjacency matrix a[][]={1,1,0,0,...

Roulette Wheel selection with a SQL query.

I am implementing a roulette wheel selection, and I would like to keep as much code as possible in SQL. My attempt has yielded the query below. $1 is a random variable of the same range as weight I send to the SQL code (it was not clear how to make random() be called only once). Weight is the size of the row's slot on the wheel. rand...

Fixed point on a compression algorithm widely used nowadays

Hello, I was wondering if there is a compression algorithm, in common use today, that contains a fixed point, i.e., an identity file. To explain, let's call C : byte[] -> byte[] a function that represents the compression algorithm. I want to know if there exists (and what it is, if it is possible to determine in reasonable time) a file ...

How can I generate pseudo-random "readable" strings in Java?

Generating a truly random string of a given length is a fairly straightforward (and already-well-covered) task. However; I'd like to generate a "pseudo" random string with the additional constraint that it be relatively easily readable (to a native-English reader.) I think another way to say this is to say that the generated string sho...

Greatest Distance between Equal Numbers in Array

Hello, let's say I have a matrix (array) like this example, but much larger: 0 0 5 0 3 6 6 4 0 3 0 8 0 1 1 9 4 0 6 0 0 0 4 1 0 6 0 7 0 0 3 1 6 1 5 0 8 0 8 0 3 2 6 4 8 1 0 2 2 8 5 8 1 8 7 4 1 0 3 0 6 3 8 1 0 0 4 0 0 3 1 5 2 0 0 0 0 5 0 3 6 6 4 0 3 0 8 0 1 1 9 4 0 6 0 0 0 4 1 0 6 0 7 0 0 3 1 6 1 5 0 8 0 8 0 3 2 6 4 8 1 0 2 2 8 5 8 1 8 7...

How do RAM Test Applications work? C# Example?

Hello, How exactly do RAM test applications work, and is it possible to write such using C# (Example)? ...

What is the simplest way to compute the lowest integer greater or equal than a / b ?

r, a and b are integers. I need the cheapest computation since in a critical part of the code. I found : r = (a / b) + (((a % b) != 0) ? 1 : 0); if b is a power of 2, then a / b can be replaced with a >> log2(b) and a % b with a & (b-1) which should save a lot of computation time. Do you know any better solution ? ...

Dynamic list slicing

Good day code knights, I have a tricky problem that I cannot see a simple solution for. And the history of the humankind states that there is a simple solution for everything (excluding buying presents) Here is the problem: I need an algorithm that takes multidimensional lists and a filter dictionary, processes them and returns lists ...

Algorithm that takes 2 'similar' matrices and 'aligns' one to another

First of all, the title is very bad, due to my lack of a concise vocabulary. I'll try to describe what I'm doing and then ask my question again. Background Info Let's say I have 2 matrices of size n x m, where n is the number of experimental observation vectors, each of length m (the time series over which the observations were collect...

Ulam's Spiral (Prime Number Spiral)

Hello, I'm looking for ideas/code (preferably C#, but other languages work too) to create Ulam's Spiral infinitely large (limited by length of time the program is running, or until stopped). Now the numbers are all primes so the code for those is rather irrelevant. The interesting part is how to code the arrangement in the evergrowi...

Algorithm Question - Team Scheduling - Quiz design

I've got a weird problem to solve - this is to be used in designing a quiz, but it's easiest to explain using teams. There's 16 teams. There's 24 matches. 4 teams play in every match. Each team has to appear once against 12/16 teams and twice against the remaining 3/16, and has to appear exactly 6 times. Any ideas on how to do this? If...