homework

python strings / match case

I have a CSV file which has the following format: id,case1,case2,case3 123,null,X,Y 342,X,X,Y 456,null,null,null 789,null,null,X above is the sample data that could be in that file. So for each line I need to know which of the case is not null. Is there an easy way to find the which case(s) are not null instead of splitting the st...

What is the fastest way to get a digit after a decimal ( double) ?

example, I have number 345.38 , 2323.805555 , 21.3333 . i want to get the number after the decimal and round it up. 345.38 --> 4 2323.805555 --> 8 21.3333 --> 3 Thanks ...

Efficient data structure for comparing items with most common attributes

I need a suggestion for an efficient data structure for the following problem. I have two lists of students (male and female) with their respective classes (sorted by date) they have already taken. The list is already alphabetized with their last name, first name. A user will give a student name, ie. student X, and what the program nee...

Flaws in algorithm and algorithm performance

char *stringmult(int n) { char *x = "hello "; for (int i=0; i<n; ++i) { char *y = new char[strlen(x) * 2]; strcpy(y,x); strcat(y,x); delete[] x; x=y; } return x; } I'm trying to figure out what the flaws of this segment is. For one, it deletes x and then tries to copy it's values over to y....

Display triangles in 3D using Python

Disclaimer: The context is a project I'm working on as part of my Master's degree. I guess it qualifies as homework. Introduction (feel free to skip to the bottom line) Curved 3D surfaces are commonly displayed as a large set of very small triangles. Each triangle has the following properties: 3 corners uniform color Such tha...

Why doesn't this Prolog rule work?

I'm trying to implement a findall predicate in Prolog (yes I know it's built in, this is for an assignment). It is written as follows: my_findall(N,P,Pred,L) :- Pred, not(new(N,P)), !, assert(new(N,P)), my_findall(N1,P1,Pred,L1), L=[N,P,L1], retract(new(N,P)). my_findall(_,_,_, []). For some reason it only gives me the first solut...

IndexError: list index out of range and python

I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out? ...

Forward "Pre-declaring" a Class in C++

Hi all! I have a situaion in which I want to declare a class member function returning a type that depends on the class itself. Let me give you an example: class Substring { private: string the_substring_; public: // (...) static SubstringTree getAllSubstring(string main_string, int min_size); }; And Su...

for statement and i.find in list

for a in ('90','52.6', '26.5'): if a == '90': z = (' 0',) elif a == '52.6': z = ('0', '5') else: z = ('25') for b in z: cmd = exepath + ' -a ' + str(a) + ' -b ' + str(b) process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE) outputstring = process.communicate()[0] ...

How do I Filter an XML via an XSLT with xml params

Here is my input XML: <Books> <Book> <BookId>1</BookId> <Des>Dumm1</Des> <Comments/> <OrderDateTime>04/06/2009 12:37</OrderDateTime> </Book> <Book> <BookId>2</BookId> <Des>Dummy2</Des> <Comments/> <OrderDateTime>04/07/2009 12:37</OrderDateTime> </Book> <Book> <BookId>3</BookId> <Des>Dumm...

Big O question

If I have the following code: IterateArray(object[] array) { for(int i=0; i<array.length; i++) { Dosomething(array[i]); } } and the Dosomething(object) method's time performance is O(log n), is the overall performance of IterateArray O(n) or O(n log n)? Thanks. ...

How can I construct a family tree with Perl?

I have a programming assignment in Perl that requires me to do the following: Creates a table in a mySQL database, and inserts these records into it: Loads the data from the table into an array of instances of class Son. Using the array, creates HTML code representing a father-son tree, and prints the html code to STDOUT. It's not nece...

Class doesn't support operators

I created a vector out of a struct to store multiple types of values. However, I can't get input to work. #include "std_lib_facilities.h" struct People{ string name; int age; }; int main() { vector<People>nameage; cout << "Enter name then age until done. Press enter, 0, enter to continue.:\n"; People name; ...

Interesting strings algorithm

Given two finite sequences of string, A and B, of length n each, for example: A1: "kk", A2: "ka", A3: "kkk", A4: "a" B1: "ka", B2: "kakk", B3: "ak", B4: "k" Give a finite sequences of indexes so that their concentration for A and B gives the same string. Repetitions allowed. In this example I can't find the solution but for example if...

Stuck in a loop ! :o

Hi. I'm trying to implement my own List system in Java. the List class file : package RoutingDemo.List; /** * A 2-way Linked-List to store generic elements. * */ public class List { /* Instance Variables --------------------------------------------------------------------------- */ /** * Reference to el...

What is the role of stack in a microprocessor?

What is the role of stack in a microprocessor? ...

FFT of an image

Hi. I have an assignment about fftw and I was trying to write a small program to create an fft of an image. I am using CImg to read and write images. But all I get is a dark image with a single white dot :( I'm most likely doing this the wrong way and I would appreciate if someone could explain how this should be done. I don't need the ...

I need to know the Big O time of my binary heap code and how can I make it better

public static void CreateMaxHeap(int[] a) { for (int heapsize = 0; heapsize < a.Length; heapsize++) { int n, p; n = heapsize; while (n > 0) { p = (n - 1) / 2; if(a[n]>a[p]) Swap(a,n,p); n = p; } } } // end of create heap ...

Number guessing game - how to?

how do i make this so once the user inputs a number and presses enter(or something) it runs the if else statements! please help! public static void main(String[] args) { System.out.println("please guess the number between 1 and 100."); boolean run = true; int y = 0; Random ran = new Random(); int x = ran.nextInt(99); while (ru...

How do I read a text file into array of lines and display it using PHP?

I have text file that looks like this: 1 1 1 1 1 2 3 5 4 4 5 5 I want to read this text file into array of lines and display it. Can anyone help me do this? ...