pseudocode

What constitutes as fair use for code?

I was wondering what constitutes as fair use for code. For example, implementing a flood fill from pseudocode from Wiki. Or if a user here gives pseudocode, does your implementation of their pseudocode constitute as fair use or is this copyright infringement. What about a modification of a C algorithm? Where are the boundaries? Thanks ...

Question about pseudocode for HW

I have the following question, and what I'm most confused on, is how to do the logic for determining if a check is one month late or not. Question is: "Write pseudocode for a program that calculates the service charge of a customer owes for writing a bad check. The program accepts a customer's name, the date the check was written (year...

Interview Question - Flipping Bits

I recently saw an interview question asking the following: Given a 32 bit number, write pseudo code to flip the second last bit What is the best/easiest way to do this? ...

An algorithm to solve a simple(?) array problem.

Hello! For this problem speed is pretty crucial. I've drawn a nice image to explain the problem better. The algorithm needs to calculate if edges of a rectangle continue within the confines of the canvas, will the edge intersect another rectangle? We know: The size of the canvas The size of each rectangle The position of each recta...

Determine compass direction from one lat/lon to the other

Does anyone have an algorithm to determine the direction from one lat/lon to another (pseudo-code): CalculateHeading( lat1, lon1, lat2, long2 ) returns string heading Where heading is e.g. NW, SW, E, etc. Basically, I have two points on a map and I want to get a general idea of the direction taking into account that 50 miles East an...

Interleaving sparse sorted arrays

I've got a set of lists of events. The events always happen in a given order, but not every event always happens. Here's an example input: [[ do, re, fa, ti ], [ do, re, mi ], [ do, la, ti, za ], [ mi, fa ], [ re, so, za ]] The input values don't have any inherent order. They're actually messages like "creating symlinks" and "r...

pseudcode for minmax algorithm

I want to get the pseudocode for minmax algorithm. I have to make 2 functions, def maxAgent(gameState, depth) and minAgent. Is there any body who has the right and easy pseudocode for it. ...

Algorithm to find which number in a list sum up to a certain number.

I have a list of numbers. I also have a certain sum. The sum is made from a few numbers from my list (I may/may not know how many numbers it's made from). Is there a fast algorithm to get a list of possible numbers? Written in Python would be great, but pseudo-code's good too. (I can't yet read anything other than Python :P ) Example l...

What does this algorithm do?

I'm trying to find if a rectangle intersects a concave polygon. I found this algorithm: double determinant(Vector2D vec1, Vector2D vec2){ return vec1.x*vec2.y-vec1.y*vec2.x; } //one edge is a-b, the other is c-d Vector2D edgeIntersection(Vector2D a, Vector2D b, Vector2D c, Vector2D d){ double det=determinant(b-a,c-d); doubl...

Common pseudocode questions, puzzles and challenges

Hi, I am looking for examples of pseudocode problems that you may have been asked in an interview or been asked to represent as part of your job or education. I'm not looking for examples from any domain in particular, so it can be related to design patterns, algorithms, data structures, caching strategies, anything to do with Software ...

Hourly Wage Calculation

I have a database table like this: wagetable name lowhours highhours wage Default 0 40 10 Default 40 9999 15 Brian 0 40 15 Brian 40 50 20 Brian 50 9999 22 Chad 0 40 13 Chad 40 9999 17 ...

Does this pseudocode assume a zero based index?

I'm not sure if when they write 1 if this is the first or second element in the array: function DouglasPeucker(PointList[], epsilon) //Find the point with the maximum distance dmax = 0 index = 0 for i = 2 to (length(PointList) - 1) d = OrthogonalDistance(PointList[i], Line(PointList[1], PointList[end])) if d > dmax index = i...

software for mac that can help in design phase (UML?)

Hi All I am looking for a tool/software that can help me in designing my app. Basically i do not need something like a code generator, but a nice software that let me create blocks where i implement actions (like a class, but just with the declaration of the methods and datatypes/returned types; no implementation) and then let me crea...

What would this look like as pseudocode?

I'm trying to implement this: from https://docs.google.com/viewer?url=http://www.tinaja.com/glib/bezdist.pdf&pli=1 The following BASIC program uses the method of finding distance. The program also searches for the minimum squared distance between points and a curve. REM BEZIER.BAS JIM 20DEC92 12:37 DATA 2,3,5,8,8,14,11,17,14,17,16,...

Are .FRM .ARC .4GO .4GI portable p-code?...

Assuming compilers and runners are from same versions, can they be executed on any platform (i.e. UNIX, LINUX, WINDOWS, DOS, etc.) without the need to re-compile the source code? ...

refactor my if statement code

Hello, I've been messing with this bit of code for over an hour trying to rearrange it different ways. Is there any easier way to write it? if x is not Number ;// if x is string { if y is not Number ;// x, y both strings { Eval(x) Eval(y) return } else ...

How does one make a point to point "bolt" of lightning using perlin noise or other algorithm?

Every implementation I've come across of perlin noise generation has been for the generation of 2D terrain, etc. I cannot find a decent example of point to point lightning generation anywhere. Are there many other forms of generating 'lightning'? I was told this is what I want. What algorithms exist for forked lightning, or 2D trees ...

Simple Pseudocode Code Question

I'm a little new to pseudocode. I understand what the code is saying, but having a hard time putting the pieces together. How should I be thinking to understand what this code is doing: Suppose that a1, a2, . . . , ak is an array of k numbers. What does the following code fragment do? Briefly explain why. Assume that all the indented li...

Simply Pseudocode Question

I'm new to psuedocode, and I'm having trouble putting all the pieces together: Here is the definition of a function named foo whose inputs are two integers and an array of integers a[1] ... a[n]. 1 Foo(k,m, a[1],...,a[n]) 2 if (k < 1 or m > n or k > m) return 0 3 else return a[k] + Foo(k+1,m,a[1],...,a[n]) Suppose that the inpu...

select equal sized number groups from a sequence of random numbers

say i have a list of 100 numbers, i want to split them into 5 groups which have the sum within each group closest to the mean of the numbers. the simplest solution is to sort the hundred numbers and take the max number and keep adding the smallest numbers until the sum goes beyond the avg. obviously that is not going to bring the best...