The Grey Labyrinth is a collection of puzzles, riddles, mind games, paradoxes and other intellectually challenging diversions. Related topics: puzzle games, logic puzzles, lateral thinking puzzles, philosophy, mind benders, brain teasers, word problems, conundrums, 3d puzzles, spatial reasoning, intelligence tests, mathematical diversions, paradoxes, physics problems, reasoning, math, science.

   
The Grey Labyrinth Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups    RegisterRegister  
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Here's something for programmers: Spread an infection!

 
Reply to topic    The Grey Labyrinth Forum Index -> Science, Art, and Culture
View previous topic :: View next topic  
Author Message
mathgrant
A very tilted cell member



PostPosted: Sat Dec 14, 2002 8:11 pm    Post subject: 1 Reply with quote

*doesn't know where to post this* Mods, move it if I'm wrong

Here's what I want.

code:


1 2 3 4 5
A o o o o o

B o o o o o
| |
C o o-XXX-o
X |
D o o-X-o o
| | X
E XXXXX-o o



X represents an infection, o means healthy.

First, the program will search for all connections between healthy and infected squares. In this case, 3BC, 4BC, C23, C45, 4CD, D23, D34, 1DE, 2DE, and E34. Then it choose one randomly and spread the virus like that. Example: It chooses D23:

code:


1 2 3 4 5
A o o o o o

B o o o o o
| |
C o o-XXX-o
| X |
D o-X X-o o
| X X
E XXXXX-o o



It keep doing this until only one square is safe. Could this be done?

------------------
GL DPWestley: I had my backspace key removed and a beverage dispenser pur in it's place. See? I can't go back and fix "put."
GLmathgrant: I once was banned from a M:TG tourney for bringing over 50 banned cards! They were Ace of Clubs, Ace of Diamonds, Ace of Hearts, Ace of Spades, 2 of Clubs. . .



[This message has been edited by mathgrant (edited 12-16-2002 06:31 PM).]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Legion
Daedalian Member



PostPosted: Tue Dec 17, 2002 2:32 pm    Post subject: 2 Reply with quote

Yes, I did something similar, what format did you want it in?


in general, set up an 2-D array of zeroes and ones with your ones representing infection, then randomly select any position in the array, if it is surrounded by 1s, then ignore it and select again, otherwise, count the number of adjacent uninfected positions and select a random number to designate on of those to be infected. Stop when the sum of the array is (m*n)-1

Is that what you wanted?


Hope it makes sense
Back to top
View user's profile Send private message
mathgrant
A very tilted cell member



PostPosted: Tue Dec 17, 2002 3:24 pm    Post subject: 3 Reply with quote

Any format, be it Java, Javascript, etc.

No! I want all the connections to be equally likely. In the position:

code:
  1 2 3 4 5

A o o o o o

B o o o o o

C o o o o o

D o o o o o
| |
E XXX-o o o



Your technique means 1DE has a 1/2 chance and 2DE and E23 both have 1/4 chances. I want them each to have an equal chance.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
extropalopakettle
No offense, but....



PostPosted: Tue Dec 17, 2002 6:28 pm    Post subject: 4 Reply with quote

Of course it can be done.

Curious: Why do you have X's between rows C and D, and D and E (column 3) in your first diagram?

Anyway, the simplest way to do it is make a temporary list of all the connections between an X and o, then select one randomly. There may be more efficient was han generating this list each time - such as by updating the list each time (but you'd need some slightly fancy indexing scheme to actually make that be more efficent).
------------------------
ps: compaq keyboards SUCK! I'm gonna stop correcting the typoes.

[This message has been edited by extropalopakettle (edited 12-17-2002 01:30 PM).]
Back to top
View user's profile Send private message
Termital
Daedalian Member



PostPosted: Thu Dec 19, 2002 6:27 am    Post subject: 5 Reply with quote

How about an AIM trojan instead?

Sure, it can be done. But i'm too lazy to do it. Wait till I get bored enough!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
ML
Table Master



PostPosted: Thu Dec 19, 2002 9:33 pm    Post subject: 6 Reply with quote

Thanks. Now I've wasted another day of my life

Hope it's what you wanted.

[edit] grrrr. Someone else just told me that it doesn't work on their computer. Let me know if the Applet loads for you or not. I'll try and figure out what's wrong.


[This message has been edited by ML (edited 12-19-2002 06:08 PM).]
Back to top
View user's profile Send private message
CrystyB
Misunderstood Guy



PostPosted: Fri Dec 20, 2002 1:49 am    Post subject: 7 Reply with quote

doesn't work - not even saved offline...
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
mathgrant
A very tilted cell member



PostPosted: Fri Dec 20, 2002 2:20 am    Post subject: 8 Reply with quote

CB's right -- it doesn't work!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ML
Table Master



PostPosted: Fri Dec 20, 2002 2:49 am    Post subject: 9 Reply with quote

That's irratating. Compile once run anywhere right? It works on my work computer and a roommate's computer, but not on my home computer (or apparantly CrystyB's or MathGrant's). I used a bunch of Swing package objects, and I suspect that they are not yet standard, even though they've been out for years.

If I have time tommorrow I'll see if I can take out the Swing package objects and maybe that'll work. I leave for Christmas tomorrow night. If I can't get it fixed by then I'll at least post the source.

Any other suggestions are welcome.
Back to top
View user's profile Send private message
ML
Table Master



PostPosted: Fri Dec 20, 2002 3:04 am    Post subject: 10 Reply with quote

If you are downloading it and trying it, you will need these files:
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel.class
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel$FieldDisplay.class
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel$Connection.class
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel$BioCell.class
http://www.morrisonlucas.com/GL/VirusSim/virus_simulation.html

Put them all in the same folder, and the web page file should work.

[edit] One of the class names has changed as debugging progesses [/edit]

[This message has been edited by ML (edited 12-20-2002 09:48 AM).]
Back to top
View user's profile Send private message
CrystyB
Misunderstood Guy



PostPosted: Fri Dec 20, 2002 1:52 pm    Post subject: 11 Reply with quote

That was what i was about to post! :

Originally posted by TAKEN from command mode run of AppletViewer:
java.lang.NoClassDefFoundError: InfectionModel$JFieldDisplay
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:239)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:532)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:468)
at sun.applet.AppletPanel.run(Compiled Code)
at java.lang.Thread.run(Thread.java:479)

You have to upload ALL the classes created by compiling your java...

PS With all those 5 files, appletviewing works, though i have no idea why i can't seem to be able to view it online...

Originally posted by TAKEN from IE Java Console:
java.lang.ClassNotFoundException: javax.swing.JApplet
at com/ms/vm/loader/URLClassLoader.loadClass
at java/lang/ClassLoader.loadClassInternal
at java/lang/ClassLoader.resolveClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/vm/loader/URLClassLoader.loadClass
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.processSentEvent
at com/ms/applet/AppletPanel.run
at java/lang/Thread.run

I guess you have a more advanced version of Java... But i can't understand why appletviewing works... :

[This message has been edited by CrystyB (edited 12-20-2002 09:17 AM).]
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
ML
Table Master



PostPosted: Fri Dec 20, 2002 2:51 pm    Post subject: 12 Reply with quote

Update: I've stripped out all of the Swing package code and uploaded it all again. The graphic update is a lot faster now when it's running on my computer. But on another test computer the graphic update doesn't happen at all. Still working on it.....

[edit 10:AM] this is going to make it look ugly...... or not, it didn't work



[This message has been edited by ML (edited 12-20-2002 09:59 AM).]
Back to top
View user's profile Send private message
mathgrant
A very tilted cell member



PostPosted: Fri Dec 20, 2002 3:34 pm    Post subject: 13 Reply with quote

Not working!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ML
Table Master



PostPosted: Fri Dec 20, 2002 4:16 pm    Post subject: 14 Reply with quote

I know. I think that it's a graphics updating problem. I'll work on it more this afternoon. Right now on some computers the buttons show up, but the main field of cells does not update. It might actually be working, but without the output it does no good.

Source code, if you have want to look at it.
Back to top
View user's profile Send private message
mathgrant
A very tilted cell member



PostPosted: Fri Dec 20, 2002 5:37 pm    Post subject: 15 Reply with quote

Hmm. . . an applet appears, but I can't see a grid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CrystyB
Misunderstood Guy



PostPosted: Fri Dec 20, 2002 5:57 pm    Post subject: 16 Reply with quote

did you select the dimensions of the field and press the 'New Array' button??

ML, here's the output - view it yourself: from the View menu, select the Java Console option...
code:
Exception occurred during event dispatching:

java.lang.NoSuchMethodError: java/awt/Component: method getWidth()I not found
at InfectionModel$FieldDisplay.paint
at com/ms/awt/WComponentPeer.doClearAndPaint
at com/ms/awt/WComponentPeer.paintNode
at com/ms/ui/windowmanager/PaintRequest.run
at com/ms/ui/windowmanager/RunnableMessage.run
at com/ms/awt/WSystemQueue.getMessage
at com/ms/awt/WEventQueue.getNextEvent
at java/awt/EventDispatchThread.run
Exception occurred during event dispatching:
java.lang.NoSuchMethodError: java/awt/Component: method getWidth()I not found
at InfectionModel$FieldDisplay.paint
at com/ms/awt/WComponentPeer.doClearAndPaint
at com/ms/awt/WComponentPeer.paintNode
at com/ms/ui/windowmanager/PaintRequest.run
at com/ms/ui/windowmanager/RunnableMessage.run
at com/ms/awt/WSystemQueue.getMessage
at com/ms/awt/WEventQueue.getNextEvent
at java/awt/EventDispatchThread.run
Exception occurred during event dispatching:
java.lang.NoSuchMethodError: java/awt/Component: method getWidth()I not found
at InfectionModel$FieldDisplay.paint
at com/ms/awt/WComponentPeer.doClearAndPaint
at com/ms/awt/WComponentPeer.paintNode
at com/ms/ui/windowmanager/PaintRequest.run
at com/ms/ui/windowmanager/RunnableMessage.run
at com/ms/awt/WSystemQueue.getMessage
at com/ms/awt/WEventQueue.getNextEvent
at java/awt/EventDispatchThread.run
Exception occurred during event dispatching:
java.lang.NoSuchMethodError: java/awt/Component: method getWidth()I not found
at InfectionModel$FieldDisplay.paint
at com/ms/awt/WComponentPeer.doClearAndPaint
at com/ms/awt/WComponentPeer.paintNode
at com/ms/ui/windowmanager/PaintRequest.run
at com/ms/ui/windowmanager/RunnableMessage.run
at com/ms/awt/WSystemQueue.getMessage
at com/ms/awt/WEventQueue.getNextEvent
at java/awt/EventDispatchThread.run
Exception occurred during event dispatching:
java.lang.NoSuchMethodError: java/util/Random: method nextInt(I)I not found
at InfectionModel.actionPerformed
at java/awt/Button.processActionEvent
at java/awt/Button.processEvent
at java/awt/Component.dispatchEventImpl
at java/awt/Component.dispatchEvent
at com/ms/awt/WUIPeer.handleEvent
at com/ms/awt/WButtonPeer.handleEvent
at java/awt/Component.postEvent
at com/ms/ui/AwtUIHost.postEvent
at com/ms/awt/WUIPeer.postEvent
at com/ms/ui/UIRoot.postEvent
at com/ms/ui/UIComponent.postEvent
at com/ms/ui/UIStateContainer.postEvent
at com/ms/ui/UIButton.¤
at com/ms/ui/UIButton.keyUp
at com/ms/ui/UIComponent.handleEvent
at com/ms/ui/UIComponent.postEvent
at com/ms/ui/UIStateContainer.postEvent
at com/ms/ui/UIRoot.µ
at com/ms/ui/UIRoot.forwardEvent
at com/ms/ui/AwtUIHost.postEvent
at com/ms/awt/WUIPeer.postEvent
at com/ms/ui/AwtUIHost.processEvent
at java/awt/Component.dispatchEventImpl
at java/awt/Container.dispatchEventImpl
at java/awt/Component.dispatchEvent
at java/awt/EventDispatchThread.run



And what happened to the source file?

[This message has been edited by CrystyB (edited 12-20-2002 01:08 PM).]
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
mathgrant
A very tilted cell member



PostPosted: Fri Dec 20, 2002 6:02 pm    Post subject: 17 Reply with quote

Yes.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ML
Table Master



PostPosted: Fri Dec 20, 2002 7:27 pm    Post subject: 18 Reply with quote

Sorry that the source is gone. I must have been too aggresive duirng one of my debugging steps.

My View menu has no Java console option. Are you talking about IE, or something else.

Googling....

[edit] Found it.
Also, can one of you take this test. On step 5, both computers that the program has worked on run "Java: Sun Microsystems Inc. Version: 1.3.1_02", the one that doesn't runs "Java: Microsoft Corp. Version: 1.1.4"


[edit again] Source code back up. Sorry about that.


[This message has been edited by ML (edited 12-20-2002 02:51 PM).]
Back to top
View user's profile Send private message
ML
Table Master



PostPosted: Fri Dec 20, 2002 9:14 pm    Post subject: 19 Reply with quote

Status:
I hope all the files are back up. It should work on a computer with Sun's java implementation, but doesn't seem to with the MS implementation. I don't know is Sun or MS screwed up, but I'm not happy with one of them.

The version I was working on debugging is also up:
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel2.java
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel2.class
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel2$FieldDisplay.class
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel2$Connection.class
http://www.morrisonlucas.com/GL/VirusSim/InfectionModel2$BioCell.class
http://www.morrisonlucas.com/GL/VirusSim/virus_simulation2.html
http://www.morrisonlucas.com/GL/VirusSim/Random.class
But it's in bad shape (full of debugging hacks and stuff).

The MS Java did not appear to support any of the following methods:
Vector.clear()
awt.Component.getWidth()
awt.Component.getHeight()
Vector.get(int)
I was going through and removing them all, but the next step will be to remove all references to Vector and implement it myself. But I don't have time now.

If you want to run it now without playing with the source, you should download Sun's version of Java. Even then there is no guarantee that it'll work. Otherwise someone will have to rewrite it.

I probably won't be on much for the next week, if it's still unsolved after that I may look at it again.
Back to top
View user's profile Send private message
mathgrant
A very tilted cell member



PostPosted: Fri Dec 20, 2002 10:29 pm    Post subject: 20 Reply with quote

Microsoft Java.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ML
Table Master



PostPosted: Fri Dec 20, 2002 11:12 pm    Post subject: 21 Reply with quote

http://java.sun.com/getjava/download.html
I think that will work *crosses fingers*

Sorry about all this.
Back to top
View user's profile Send private message
mathgrant
A very tilted cell member



PostPosted: Sat Dec 21, 2002 12:53 am    Post subject: 22 Reply with quote

I DLed the Sun Java, and it still won't work.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ML
Table Master



PostPosted: Fri Jan 03, 2003 6:11 pm    Post subject: 23 Reply with quote

One more thing which may make it work. Check your Internet Explorer settings. Tools->Internet Options->Advanced. You should get a screen that looks like this:

Check the Java(Sun) box

Then restart.

By checking that box I can make it work/not-work on my main computer, which should speed up debugging if/when I get around to finding the bugs.

What is this for? Is it still useful, or has a deadline passed?
Back to top
View user's profile Send private message
CrystyB
Misunderstood Guy



PostPosted: Mon Jan 06, 2003 1:50 am    Post subject: 24 Reply with quote

Quote:
Then restart

That means restart the IE program - quit all open windows of it and then open one up again.

Purpose? NONE. Just for fun. No deadline given.

mg, i am sorry to find that as with most of my 'projects' i have it half-way through workability... Maybe after another month passes and i remember i could do this to relax from the exams...
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
mathgrant
A very tilted cell member



PostPosted: Mon Jan 06, 2003 2:03 am    Post subject: 25 Reply with quote

Don't worry, his works. But I can't wait for yours nevertheless.

------------------
GL DPWestley: I had my backspace key removed and a beverage dispenser pur in it's place. See? I can't go back and fix "put."
GLmathgrant: I once was banned from a M:TG tourney for bringing over 50 banned cards! They were Ace of Clubs, Ace of Diamonds, Ace of Hearts, Ace of Spades, 2 of Clubs. . .


Back to top
View user's profile Send private message Send e-mail Visit poster's website
ChienFou
Leader of the pack



PostPosted: Mon Jan 06, 2003 11:10 pm    Post subject: 26 Reply with quote

Many years ago (c. 1971) I had free use of a CDC 6600, which was the biggest m/c in London at the time. I solved an old conundrum which is to find the longest non-crossing knights tour on a 6x6 chessboard. (It's 17 moves btw and is unique. Anyone care to find it?) I rewrote the inner loops in Compass (native assembler) and eventually solved the 8x8 chessboard. To get any sort of performance, I built a number of tables: A list of all possible moves and a list of all moves that would be removed by making a move. By storing the move number I was able to run a full search purely by lookup and it went like s**t off a shovel. btw I could read core dumps like it was Keats or Shelley in those days.

The same approach can be used here. Maintain a list of all potentially infectable links for the current state of the board and select one at "random". Update the list from a table of additional infectable links ... etc.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous: by   
Reply to topic    The Grey Labyrinth Forum Index -> Science, Art, and Culture All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Site Design by Wx3