pseudocode

Algorithm to calculate the number of divisors of a given number

What would be the most optimal algorithm (performance-wise) to calculate the number of divisors of a given number? It'll be great if you could provide pseudocode or a link to some example. EDIT: All the answers have been very helpful, thank you. I'm implementing the Sieve of Atkin and then I'm going to use something similar to what Jon...

Choosing a pivot for Quicksort?

When implementing Quicksort one of the things you have to do is choose a pivot. But when I look at pseudocode like the one below. It is not clear how is should choose the pivot. First element of list? Something else? function quicksort(array) var list less, greater if length(array) ≤ 1 return array select an...

Pseudocode Programming Process vs. Test Driven Development

For those who haven't read Code Complete 2, the Pseudocode Programming Process is basically a way to design a routine by describing it in plain English first, then gradually revise it to more detailed pseudocode, and finally to code. The main benefit of this is to help you stay at the right level of abstraction by building systems top-do...

Convert calories to weight

The fundamental equation of weight loss/gain is: weight_change = convert_to_weight_diff(calories_consumed - calories_burnt); I'm going on a health kick, and like a good nerd I thought I'd start keeping track of these things and write some software to process my data. I'm not attentive and disciplined enough to count calories in food, ...

Is writing code out still considered an algorithmic representation?

I just lost 50% of my answer on a test because I wrote the code out instead of an algorithm on my midterm, bumping me from an A to a C. Is writing code out still considered an algorithmic representation? Wikipedia: Algorithm Representation (since programming style is pretty much consensus-based) EDIT: Ok, so let me make a few points cl...

What is the best solution for the 'Students and Lockers' problem?

I thought that it would be fun to present some classic CS problems and let people show their algorithm optimization skills. The hope is that we get to see some clever techniques to solve abstract problems that we may be able to implement in practice. Ideally solutions would be presented in pseudo code with a big O classification. Proof ...

Calculating date for a day of the week

Given a week-day (1-7), how can I calculate what that week-day's last date was? Example: Today is Wednesday, 2008/11/12, and I want to know what last Friday's date was. ...

Algorithm for sampling without replacement?

I am trying to test the likelihood that a particular clustering of data has occurred by chance. A robust way to do this is Monte Carlo simulation, in which the associations between data and groups are randomly reassigned a large number of times (e.g. 10,000), and a metric of clustering is used to compare the actual data with the simulat...

Algorithm for generating a random number

I'm looking to generate a random number and issue it to a table in a database for a particular user_id. The catch is, the same number can't be used twice. There's a million ways to do this, but I'm hoping someone very keen on algorithms has a clever way of solving the problem in an elegant solution in that the following criteria is met: ...

How would I approach building a results predictor for a Football Management sim ?

I'm looking for some food-for-thought on how games like Football Manager and Championship Manager achieve a fairly high level of realism when it comes to simulating realistic scorelines. I am conscious that some of these algorithms would probably fill shelves but I'm looking for a more lucid overview. Even some pseudocode which outlines...

survey results in sharepoint

how do i get a list of user that have completed or not completed or not responded to a survey. so i have a survey, lets say "survey A". in this survey i have a list of people or groups that must fill the survey. sharepoint already gives us a list of respondents, but i want to make a list of people that have not responded or not complet...

How do you link two arrays?

I'm in a basic programming class, and everything is done in pseudo code. My question is this: How do you link two arrays? I have a single-dimensional array that lists students names, and I have a two-dimensional array that lists the top eight scores of each student...this is all fine and dandy, but now I need to sort the arrays by th...

runnable pseudocode?

I am attempting to determine prior art for the following idea: 1) user types in some code in a language called (insert_name_here); 2) user chooses a destination language from a list of well-known output candidates (javascript, ruby, perl, python); 3) the processor translates insert_name_here into runnable code in destination language;...

How often do you use pseudocode in the real world?

Back in college, only the use of pseudo code was evangelized more than OOP in my curriculum. Just like commenting (and other preached 'best practices'), I found that in crunch time psuedocode was often neglected. So my question is...who actually uses it a lot of the time? Or do you only use it when an algorithm is really hard to conceptu...

How to find the value of a neuron in a neural network

Since a lot of these sites found on google use mathematical notation and I have no idea what any of it means I want to make a feedforward neural network like this: n1 i1 n3 n2 o1 i2 n4 n3 Now can someone explain to me how to find the value of o1? How is it possible to make a neuron active when none of its...

Base 3 Combinatorics

I've never been much for math and I'm hoping that someone can help me out with the following. I have 5 boxes: 1 2 3 4 5 [ ] [ ] [ ] [ ] [ ] The boxes can either be white, gray, or black (or think of it as 0, 1, 2) How many possible states can the box set be in? What is the pseudocode (or in any language) to generate all t...

c# httpmodule to handle pseudo subdomains

Hi, i'm new to development with .net and working on a personal project. my project will allow users to create their own simple mobile site. I require to write http module that will handle pseudo subdomains. I already setup my dns wildcard to domain so sub.domain.com xxx.domain.com etc points to same application. I want to be able to ex...

Do you pseudo-code?

Do you use pseudo-code to help you program? Does it help you write your programs faster with less bug-prone code or does it simply waste time? Should it be standard practice to declare what you're going to program before being allowed to get your hands dirty writing? (See Literate Programming) Please write your opinions and the benefit...

How is PDL used in real-world programming?

I've been reading code complete, not far in yet but one of the things it talks about is PDL - a higher level design language, which you write each routine in before coding in the language of choice. I wondered if anyone actually did this in real life? Another thing it says is to leave each line of PDL in the code as comments. Surely t...

Path finding in a Java 2d Game?

Essentially its a pacman clone game I'm working on. I have an Enemy class, and 4 instances of this class created which all represent 4 ghosts of the game. All ghosts start up in random areas of the screen and then they have to work their way towards the pacman character. As the player controls the pacman, moving it around, they should f...