Hey Guys!

So... I left my PC back home when i went off to college and now that I'm back for summer, it seems that it has missed me because it doesn't work anymore.

First Problem:

When I tried to switch it on, it would start to boot (I'd see the fans try to spring to life) and then it would immediately switch itself off.

What I Tried:

  1. Removed peripherals and reseated all the hardware (RAM sticks, video card, CPU, etc.) -- No luck
  2. Reset BIOS to eliminate overclocks. (removed battery) -- No luck
  3. Took the motherboard, PSU, and video card out, cleaned them thoroughly (with compressed air), connected them outside the case, and applied power. -- This took care of this problem and led to the next.

    13366208298541

Second Problem:

PC powers up, fans would get started, all the relevant lights would work but nothing on the screen and no hard drive activity is heard.

What I Tried:

Nothing. I had exhausted my arsenal of things to try in the first problem.

What now?

First i thought maybe I should buy a new video card... Now I'm thinking it's the motherboard because I did have problems with its DIMMs before. You guys have any suggestions?

Thanks,
Khodeir

[QUOTE=pyTony;1665988]Simply (and looks to me your original one should be same):
[CODE]import itertools
x = [['foo'], ['bar', 'baz'], ['quux'], ("tup_1", "tup_2"), {1:"one", 2:"two"}]
print list(itertools.chain(*x))
print [element for sub in x for element in sub]
[/CODE]
Output:
[CODE]['foo', 'bar', 'baz', 'quux', 'tup_1', 'tup_2', 1, 2]
['foo', 'bar', 'baz', 'quux', 'tup_1', 'tup_2', 1, 2]
[/CODE][/QUOTE]

Thank you, pyTony, that's exactly what i was looking for.

[QUOTE=woooee;1665946]Use itertools. [code]import itertools
x = [['foo'], ['bar', 'baz'], ['quux'], ("tup_1", "tup_2"), {1:"one", 2:"two"}]
print list(itertools.chain(*x)) [/code][/QUOTE]

Perfect. Thanks! Just for my own edification though, is it possible to do it with a list comprehension similar to my example?

Thanks again,
Khodeir

Hello All

I'm not quite sure you can do this but it seems to me like something python is probably able to do. Basically, I need to assert that somewhere in my list of lists i have a '2', and a '1'. Now my lists in the biglist are all the same length. By which i mean that len(BigList[i]) == len(BigList[i+1] for all valid indicies i.

I was just thinking something like this:

[CODE][element for element in SmallList for SmallList in BigList][/CODE]

I understand why this doesn't work, but for some reason, i'm pretty sure that it can be done in python. It just seems to cohere with the python way of doing things.

I may be wrong, but i thought i'd ask. For now i have to settle for this ugly alternative:

[CODE]FlattenedList = []
for SmallList in BigList:
for element in SmallList:
FlattenedList.append(element)
assert FlattenedList.contains('2'), "Does not contain 2."
assert FlattenedList.contains('1'), "Does not contain 1."[/CODE]

I've been writing a piece of code that will use a brute force approach to find 50 exponential equations that fit 5 points (x,y) that i've entered. The code is fine and works without a glitch.. The problem is when i try to make it keep a record of the 50 best equations. This sort routine is the one i've been using.. I've put it in its own test class just to make easier to follow. The current problem is it ends up displaying something completely unwarranted and the array ends up with only two different values.

[CODE]public class sortTest{
public static void main(String [] args)
{
int [][] best = new int[50][3]; //50 best equations. the three placeholders are b,c,euclid in the equation y(t) = 10b^(tc). euclid is the euclidean distance between the equation and the points i've given it. The smaller it is, the better the equation.
int tempcomp [] = new int[3]; //to temporarily store new equations
boolean sorted;
for(int index = 0; index<best.length; index++){
best[index][0] = 100+index;
best[index][1] = 100+index;
best[index][2]= 100+index;
}
for(int c = 0; c<best.length; c++)
{
tempcomp[0] = 100-c;
tempcomp[1] = 100-c;
tempcomp[2]= 100-c;
if(tempcomp[2]<best[49][2])
best[49] = tempcomp;
sorted = false;
while (!sorted) {
sorted = true; // assume this is last pass over array
for (int index=0; index<best.length-1; index++) {
if (best[index][2] > best[index+1][2]) {
// exchange elements
tempcomp = best[index]; best[index] = best[index+1]; best[index+1] = tempcomp;
sorted = false; // after an exchange, must look again
}
}
}
} ...

[QUOTE=JamesCherrill;1379766]Maybe spawn should run in a new Thread each time? (Sorry, I don't have time right now to give this any serious design-type thought)[/QUOTE]
Yea that's a good idea. The problem still remains though, that if i want each bacteria to "reproduce" by itself, then i need to have each Bacteria object initialize its own Bacteria offspring. And if that's the case, there's no way of referring to all the different objects from the outside class. (or is there?)

Alternatively, I could have them all initialized by the class itself and just keep an array of all of them, but that defeats the purpose of the simulation (to show the population as the individual bacteria multiply and populate the medium) because then they dont grow exponentially.

What i could do, is count the number of threads. This should be possible, although i don't remember the code. Would the thread terminate when it reaches then end of the code? If so, this is the best solution. If not, could i refer to variables within these different threads?

I wonder if there's a way to have all the objects pass a "count" back to the original class.I can't think of any other solutions.

Oh actually.. I've just realized the fatal flaw in my program. Once the objects have been initialized, nothing runs because once the first 2 seconds are over, it creates a new object which then waits 2 seconds to create a new object which goes on and on and on. I doubt i can get this program to multi-task... Any ideas?

Yeah I'm thinking something like this:

[CODE]public class Bacteria
{
boolean living;
int population;
static Bacteria [] x;
public void spawn()
{
living = true;
try{
Thread.sleep(2000);
}
catch (InterruptedException e )
{}
Fission();
try{
Thread.sleep(100000);
}
catch (InterruptedException e )
{}
Die();
}
private void Fission()
{
if(x!=null)
x = expand(x);
else x = new Bacteria[1];
x[x.length-1] = new Bacteria();
x[x.length-1].spawn();
}
private void Die(){living = false;}
private boolean Check(){return this.living;}
public void all()
{
population = 0;
for(int count = 0; count<x.length; count++)
if(x[count].Check())
population++;
}
private Bacteria[] expand(Bacteria[] array) {
Bacteria[] temp = new Bacteria[array.length+1];
System.arraycopy(array, 0, temp, 0, array.length);
return temp;
}
}
[/CODE]
and then use another class to run it like:
[CODE]public class Medium
{
public static void main()
{
Bacteria x = new Bacteria();
x.spawn();
try{
Thread.sleep(2001);
}
catch (InterruptedException e )
{}

for(int count = 0; count<500; count++){
try{
Thread.sleep(2001);
}
catch (InterruptedException e )
{}
x.all();
System.out.println('-' * x.population);
}
}
}[/CODE]

Is this what you meant? This should work, correct?

Hello all,

This is a very simplistic simulation but i'm hoping to show bacterial growth using this simple piece of code.
[CODE]public class Bacteria
{
boolean living;
Bacteria x;
int population;
public void spawn()
{
living = true;
try{
Thread.sleep(2000);
}
catch (InterruptedException e )
{}
Fission();
try{
Thread.sleep(100000);
}
catch (InterruptedException e )
{}
Die();
}
private void Fission()
{
x = new Bacteria();
x.spawn();
}
private void Die(){living = false;}
private boolean Check(){return this.living;}
private boolean ping(){return x.Check();}

}
[/CODE]

The idea is that if i initialize one object of the Bacteria class and run the spawn() module then it will just continue to "reproduce". The class that is going to run this code needs to be able to keep count of the population of bacteria. I want to represent the population graphically using dashes to represent individual bacteria. My problem is that i cannot see a way to keep count. I was thinking of using something like the ping() module which basically just checks the "next" bacteria and returns a boolean. My problem is i cannot refer to all of the objects within the initial Bacteria object in any sort of efficient manner.

Does anyone have any ideas? I know this could probably be achieved without objects... But I just think this a very elegant design (aside from not being functional).

Thanks for lookin,
Khodeir

Yea that's exactly what I'm trying to do. Thanks for the speedy response.

So I'm working on a database-type program for the Java course that i'm doing and i seem to have run into a bit of a roadblock. This class compiles and runs alright but where i have a problem with it is when i try to amend the text file using the same class. All it does is overwrite whatever is on the txt file. I've tried to include a method that reads the text file first and then includes the contents in the output but i cant get it to work because the second i use Formatter.format(Scanner(system.in)) (if that makes sense) it just replaces whatever was in the file with the new input. (I hope I'm coherent.. If not, just let me know :P)

This is the code:
[CODE]import java.io.File;
import java.io.FileNotFoundException;
import java.lang.SecurityException;
import java.util.Formatter;
import java.util.FormatterClosedException;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class CreateTextFile
{

private Formatter output;

public void openFile()
{
try
{
output = new Formatter( "clients.txt" );
}
catch ( SecurityException securityException )
{
System.err.println(
"You do not have write access to this file." );
System.exit( 1 );
}
catch ( FileNotFoundException fileNotFoundException )
{
System.err.println( "Error opening or creating file." );
System.exit( 1 );
}
}

public void addRecords()
{

  AccountRecord record = new AccountRecord();
  Scanner input = new Scanner( System.in );

  System.out.printf( "%s\n%s\n%s\n%s\n\n",
     "To terminate input, type the end-of-file indicator ",
     "when you are prompted to enter input.",
     "On UNIX/Linux/Mac OS X type <ctrl> d then press Enter",
     "On Windows type <ctrl> z then ...

Hey Mike,

I just tried your solution. Thanks for clearing up my misconceptions about multidimensional arrays. Your code worked like a charm, you've been an enormous help.

Thanks again,
Khodeir

t

Thanks for replying so quickly, Mike. Let me explain the for loop, first. It looks like count<1 but it's actually count<l (lowercase L). This is instantiated in the first line of the module and represents the length of the command-line argument args.length. The array on the other hand is used so that dimensions[0][0][0] refer to the width, depth and height of a certain product. That's why i didnt need dimensions[0][0][1] or anything like that. Each 'row' refers to a certain product's dimensions. I'm not quite sure what you mean by an index of 2, but i thought i got the gist of it (or maybe i didnt.. im very new to programming).

The illegal start of expression error still doesnt go away though. It's killing me! Am i creating the arrays incorrectly?

So i'm trying to make a module for my program that returns a multidimensional array based on another array in the form of a command-line argument.

Here is the module that's keeping me up at night:
[CODE]public static double[][][] getDimensions(String [] args)
{
final int l = args.length;
double dimensions [][][] = new double[1][l][l];
for(int count = 0; count<l; count++)
{

       if(args[count].equals("NA4"))
       dimensions[count][count][count] = {20.6, 15.7, 12};

       if(args[count].equals("NA5"))
       dimensions[count][count][count] = {17.6, 15.7, 12};

       if(args[count].equals("NA1"))
       dimensions[count][count][count] = {45, 18.5, 15};

       if(args[count].equals("NA2"))
       dimensions[count][count][count] = {32.6, 17, 15};

       else
       dimensions[count][count][count] = {14.5, 9.8, 7.1};
    }
    return dimensions;
}[/CODE]

The error i get is with the consequence of the if statement:
dimensions[count][count][count] = {20.6, 15.7, 12}; - Illegal start of expression
The thing is.. im pretty sure i've forgotten something ridiculously obvious but i'm tired of getting this error.

Hi Everybody,

I'm currently doing a Computer Science IB course in which I'm required to create a java program of my choice. I'm quite new to java but i still chose something i thought would be cool and it turned out to be a little harder than i thought. As part of my program i want to offer the abilit yfor a user to connect to a wifi network but i cannot see any evidence on the web of this even being possible. If anone has some ideas, please let me know.

Thanks in advance!