homework

Python - lines from files - all combinations

I have two files - prefix.txt and terms.txt both have about 100 lines. I'd like to write out a third file with the Cartesian product http://en.wikipedia.org/wiki/Join_(SQL)#Cross_join -about 10000 lines. What is the best way to approach this in Python? Secondly, is there a way to write the 10,000 lines to the third file in a rand...

Prolog -- symetrical predicates

I have to simulate family tree in prolog. And i have problem of symetrical predicates. Facts: parent(x,y). male(x). female(y). age(x, number). Rules: blood_relation is giving me headache. this is what i have done: blood_relation(X,Y):-ancestor(X,Y). blood_relation(X,Y):-uncle(X,Y);brother(X,Y);sister(X,Y);(mother(Z,Y),sister(X,Z));...

Find shortest substring

I have written a code to find the substring from a string. It prints all substrings. But I want a substring that ranges from length 2 to 6 and print the substring of minimum length. Please help me Program: import re p=re.compile('S(.+?)N') s='ASDFANSAAAAAFGNDASMPRKYN' s1=p.findall(s) print s1 output: ['DFA', 'AAAAAFG', 'MPRKY'] D...

Program hangs because it has to wait for input that I can never give.

I'm using visual studio to program this small TcpServer. It's really specific. The server listens to port 1234 and is located on IP 127.0.0.1 Our teachers gave us a program that tries to connect to that port on that IP when you click "connect". It's working for everyone else, so it must be a coding error on my part. When I click connec...

Haskell: Replacing element with a given key in an association list

Hi I've got to make a function to which is given a key (as a string), a value (as a string) and a an association list of keys and values (as [(String, String)]). The function is meant to add the key and value pair on to the end of the list, and, if the key is already present in the list with an associated value, delete the old value. I'...

Algorithm for deleting one element in an single linked list with O(1) complexity

I'm a student of computer science in Germany. My professor gave use the following question to think about: 'Given a reference to a node in a single linked list (which is not the last node). Give an algorithm to delete this element from the list which has O(1) complexity while maintaining the integrity'. I thought about this, but I'm pr...

Is it valid to make Ruby Gems an analogy to Java JARs?

I believe I have put the question quite clearly and in a concise manner. Why do I ask? I am to explain Ruby on Rails framework to students and this requires me to make some analogies to the Java world (as the course is quite Java-centric). I have no hands-on experience with Ruby on Rails but I sense the Gem/Jar analogy is a valid one. ...

Java3d Behaviors and movement

I would like to move a sphere in a random direction within a simple universe. How could i achieve this with behaviours by changing the location a small amount frame by frame. The reason I am trying to do this is to produce random movement within the universe and eventually build in simple collision detection between the particles. Any a...

How can I sort a list of user-entered numbers in MIPS?

I'm writing MIPS program that will examine a list of 10 numbers to be input from the terminal. And these numbers will output on the terminal in an ascending order. And below are my MIPS program...please can someone help me look into it, because i m running and isn't working proply.... .data array: .space 40 prompt: .asciiz "En...

A Simulator for a non-deterministic Push-Down Automaton

Well, i need to make simulator for non-deterministic Push-Down Automaton. Everything is okey, i know i need to do recursion or something similar. But i do not know how to make that function which would simulate automaton. I got everything else under control, automaton generator, stack ... I am doing it in java, so this is maybe only is...

How to get CPU usage?

How do I get the cpu usage percentage to display in the label on a form? ...

Conversion: uid_t to string, off_t to string

Hello, I am currently writing a systems programming homework and in one part i need to get some information of a file in a directory. for the stat of file, we have ctime() function which converts time_t type to string and returns a pointer to it. but how about the uid_t and off_t types? I searched through to internet and couldnt find ...

Optimized code for 2 dimensional array

I have a 2-dimensional array i need to convert first diagonal numbers in to zero,,for eg i need to convert first diagonal numbers of arrays[1 2 3 ] 5 9 5 3 2 1 means 1 9 1 in to zero that is the answer is just like [0 2 3] ...

How do I connect to an Access 2007 (accdb) file in Visual Studio 2008

I'm in a college class using the Microsoft visual studio 2008 for visual basic and i have a project where i'm supposed to connect a database but it can't recognize the database file as a database. I followed the book exactly so i don't know what the problem is. ...

(rails) taking from DB and rendering into HTML

Hi. I'm building a website for my Web Dev class, and I'm stuck on rendering HTML. I want to be able to use a simple form (Pretty much all I have right now is a scaffold for this controller, and I attempted sticking a content_type into my controller, but no progress.) to submit text and have it rendered as HTML. The idea is that, since th...

C With OpenGL and GLFW questions (Mainly a C question)

I am trying to build an application to simulate some basic spheres moving around for this assignment I have got. I am relatively new to C but I have been using .NET and java for some time. The problem that i am facing is that it doesn't look like the data is being assigned to the array outside of the init statement when i actually need...

Moving particles in C

I want to be able to move a particle in a straight line within a 3D environment but I can't think how to work out the next location based on two points within a 3D space? I have created a struct which represents a particle which has a location and a next location? Would this be suitable to work out the next location to move too? I know ...

How can I write a MIPS program to determine pass/fail for test grades?

I'm writing a MiPS program that will examine a list of 15 test scores. And it is going to input from the terminal. The passing criterion is the score of 50. The outputs to the terminal will include the scores in each category and the number of students passing and failing. I should use input prompts and output statement. Please I need so...

Intelligent Selection Algorithm

Hi all, I am using VB.NET and I am trying to come up with some algorithm or some pseudo-code, or some VB.NET code that will let me do the following (hopefully I can explain this well): I have 2 collection objects, Cob1 and Cob2. These collection objects store objects that implement an interface called ICob. ICob has 3 properties. A boo...

MIPS program need help

I'm writing a MiPS program that will examine a list of 15 test scores. And it is going to input from the terminal. The passing criterion is the score of 50. The outputs to the terminal will include the scores in each category and the number of students passing and failing. I should use input prompts and output statement. Below is C progr...