homework

Anagram Hash Function

I know something like this has been asked before, but the answer was sort of side tracked. I want to develop a hash function which will take a word and spit out an address of an array. So, for example, if you input god: sort the word, d o g perform some sort of function on this to get an address d o g -> some number insert 'dog' into...

Java Path compression

Hi, I have to create a method find that would use a local Set to collect the objects and the root. Then, I would compress the object e (in the parameter) and have the roost as its parent. Then, I would return the reference to the root. I can use the Graph, Map, and set class since it was imported. But, how can I call the parent of the ro...

fading flash notices with hobo?

Hello I need help in order to create site-wide fading flash notices. I am using hobo. thanks in advance. ...

SIGINT handling and getline

I wrote this simple program: void sig_ha(int signum) { cout<<"received SIGINT\n"; } int main() { string name; struct sigaction newact, old; newact.sa_handler = sig_ha; sigemptyset(&newact.sa_mask); newact.sa_flags = 0; sigaction(SIGINT,&newact,&old); for (int i=0;i<5;i++) { cout<<"Enter text: "; getline(cin,name)...

Algorithm for finding 2 items with given difference in an array

I am given an array of real numbers, A. It has n+1 elements. It is known that there are at least 2 elements of the array, x and y, such that: abs(x-y) <= (max(A)-min(A))/n I need to create an algorithm for finding the 2 items (if there are more, any couple is good) in O(n) time. I've been trying for a few hours and I'm stuck, any c...

Finite State Machine program

I am tasked with creating a small program that can read in the definition of a FSM from input, read some strings from input and determine if those strings are accepted by the FSM based on the definition. I need to write this in either C, C++ or Java. I've scoured the net for ideas on how to get started, but the best I could find was a ...

Describe the three elements that must be included in order for a loop to successfully perform correctly

I have this homework question about loops in general (if it make sense at all), it goes like this: Describe the three elements that must be included in order for a loop to successfully perform correctly. Any idea what they might be? ...

How to cast a pointer to an int in c ( to get its ascii value )

I have a pointer ( *ascii ) which a pointer to a char and I want it is value as an int in order to make it an if statement like if ( ascii == 32 || ((ascii > 96) && (ascii < 123)) { } This is not working, i would appreciate help ...

what does union U look like in the memory?

enum Enums { k1, k2, k3, k4 }; union MYUnion { struct U{ char P; }u; struct U0 { char state; } u0; struct U1 { Enums e; char c; int v1; } u1; struct U2 { Enums e; char c; int v1; int v2; } u2; struct U3 { ...

How to insert an element into an array on malloc?

say we are going to insert an element into an array on malloc. I know where and how to insert, but I'm having trouble shuffling every succeeding element down by 1. What would be the technical approach for this? Thanks | x x x x x x x x x x x | original array | x x x x x 0 x x x x x x | new array Suppose the "memmove" function is not ...

Trying to visualize points on a graph: how can I make C++ output this?

I am trying to create a simple visualization of what my code does. I am making a Poisson-Disk-Distribution class to generate a set of random points in a bounded rectangular region. Basically, what it does is it randomly generates a specified number of points in the bounded region and makes sure that each point is at least a certain dista...

bison YYSTYPE: Trying to use char*

I'm taking a class and trying to do some homework. I need to use flex and bison to parse some code. The default type of YYSTYPE is int, even though I never declared it that way. Is that a default from bison? It would help me a lot to pass strings back. I read this: http://stackoverflow.com/questions/1014619/how-to-solve-bison-warnin...

Common Lisp: Attach x recursively to list

I'm trying to add, say, x to every element of a list. For example: (queue 3 '(1 2 3)) would give ((3 1) (3 2) (3 3)) The code below apparently does not do what I want. Any hints please? (defun queue(x y) (cond ((null y) nil) (t (cons x (queue x (rest y)))))) ...

What are the possible ways to send a feedback e-mail form?

My professor in the uni has asked me to design a simple website with a basic feedback form. the form should NOT use 'mailto' for sending the feedback form e-mail the form should NOT use server-side scripting (PHP, etc) for sending the feedback form e-mail. Is is possible at all to send an e-mail from a website form without using an...

How could I apply a genetic algorithm to a simple game that follows rollercoaster tracks?

I have free-rein over what I do on a final assignment for school, with respect to modifying a simple direct-x game that currently just has the camera follow some rollercoaster rails. I've developed an interest in genetic algorithms and would like to take this opportunity to apply one and learn something about them. However, I can't thi...

Java recursion phone number letters

How do you write a java program using a recursive method that takes in an int like "234" and converts this into the corresponding letters on a phone pad (2 = ABC, 3 = DEF, etc), and prints out the permutations of this? e.g.: input = 234 output = ADG ADH ADI AEG AEH AEI AFG AFH AFI BDG BDH BDI BEG BEH BEI BFG BFH BFI CDG CDH CDI CEG CEH...

Question about file transfer for socket programming

Is there a good method on how to transfer a file from say... a client to a server? Probably just images, but my professor was asking for any type of files. I've looked around and am a little confused as to the general idea. So if we have a large file, we can split that file into segments...? Then send each segment off to the server. S...

How to calculate first n prime numbers?

Assume the availability of a function is_prime. Assume a variable n has been associated with a positive integer. Write the statements needed to compute the sum of the first n prime numbers. The sum should be associated with the variable total. Note: is_prime takes an integer as a parameter and returns True if and only if that integer...

how to let a raw_input repeat until I wanna quit?

Say I use raw_input like this: code = raw_input("Please enter your three-letter code or a blank line to quit: ") under if __name__=="__main__": How can I let it repeat multiple times rather than just once every time I run the program? Another question is to write what code can satisfy the condition "or a blank line to quit (the program)"...

Writing Sudoku Solver wih Python

Here is my Sudoku Solver written in python language, When I run this program there seems to be a problem with in Update function and Solve function. No matter how much time I look over and move the codes around, I seem to have no luck Can anyone Help me? import copy def display (A): if A: for i in range (9): ...