Let's get programmy!

If you have some randomness to share that you can't post elsewhere, this is the place to do it.
Post Reply

Is Assembly the best programming language?

Yes
3
9%
Oh God my eyes
3
9%
Oh God my brain
12
38%
I perform unholy incantations to keep Assembly at bay
4
13%
Real men write binaries by hand
10
31%
 
Total votes: 32
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

except that you're obviously leaving out code from that example, since there's only three printouts there and you're listing 4 lines of output :V
ranger
Community Villain

Posts:
3588

Re: Let's get programmy!

Post by ranger »

^

yeah..assuming the toString method is just returning one line w/o any new line characters, the sample code you're giving is incomplete..
Image
Image
User avatar
Callid
Ratio vincit omnia.

Posts:
1433

Re: Let's get programmy!

Post by Callid »

Ah, yeah, there used to be more lines because I also tested it with these lines twice for different objects, to see if they'd influence each other (that they did not). So, it was like this, with both second lines sometimes commented out and sometimes not. I just copied to much output :P

Code: Select all

        GregorianCalendar greg = new GregorianCalendar(1992,7,12,17,30);
        //System.out.println(greg.getTime().toString());
        greg.setTimeZone(TimeZone.getTimeZone("GMT+1"));
        System.out.println(greg.getTime().toString());
        greg.setTimeZone(TimeZone.getTimeZone("GMT-1"));
        System.out.println(greg.getTime().toString());
        
        GregorianCalendar greg2 = new GregorianCalendar(1992,7,12,17,30);
        System.out.println(greg2.getTime().toString());
        greg2.setTimeZone(TimeZone.getTimeZone("GMT+1"));
        System.out.println(greg2.getTime().toString());
        greg2.setTimeZone(TimeZone.getTimeZone("GMT-1"));
        System.out.println(greg2.getTime().toString());
If  ;), :D, ;D, ::), :P, :-X, :o or >:D are attached, that paragraph may not be 100% serious. Seriously.
This link provides further information.
Callid Conia Pact - Petitions - Archive
User avatar
Kogorou
*drinking beer and playing guitar*

Posts:
1132
Contact:

Re: Let's get programmy!

Post by Kogorou »

I tried that code too and indeed there seems to something wrong.
I have to debug is a little bit more :)
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

ah, that's actually pretty funny then. Although, the problem you posted the second time is the complete opposite of the first problem you posted, and actually makes sense. :P

but rather than just telling you why (because that doesn't make anyone a better programmer :V), I'll just ask the question: given the two lines of code,

Code: Select all

GregorianCalendar greg = new GregorianCalendar(1992,7,12,17,30);
System.out.println(greg.getTime().toString());
what do you actually expect to happen? You're forcing the program to make a certain large assumption when you call getTime() here :V
User avatar
Callid
Ratio vincit omnia.

Posts:
1433

Re: Let's get programmy!

Post by Callid »

Akonyl wrote: ah, that's actually pretty funny then. Although, the problem you posted the second time is the complete opposite of the first problem you posted, and actually makes sense. :P

but rather than just telling you why (because that doesn't make anyone a better programmer :V), I'll just ask the question: given the two lines of code,

Code: Select all

GregorianCalendar greg = new GregorianCalendar(1992,7,12,17,30);
System.out.println(greg.getTime().toString());
what do you actually expect to happen? You're forcing the program to make a certain large assumption when you call getTime() here :V
Yeah, I assumed that was the reason. Still, it's quite funny that getTime() in fact finalizes the time. I would have expected that that'd need a special method, e.g. ".setFix()" or something :P
You wouldn't usually expect getTime to do that :x
If  ;), :D, ;D, ::), :P, :-X, :o or >:D are attached, that paragraph may not be 100% serious. Seriously.
This link provides further information.
Callid Conia Pact - Petitions - Archive
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

It's not finalizing the time, you can still easily add time to the date. :V
c-square
Shounen Tantei Dan, Dai Seikou!

Posts:
1040

Re: Let's get programmy!

Post by c-square »

Looks like GregorianCalendar has a 'time' member that gets set or cleared based on certain actions.  Whether or not this member is set determines if the hour is properly reported after a timezone change.  Very strange...

Code: Select all

	        Calendar greg = new GregorianCalendar(1992,7,12,17,20,10);
	        System.out.println("Scenario 1");
	        System.out.println(greg);
	        System.out.println("-- Setting Time Zone --");
	        greg.setTimeZone(TimeZone.getTimeZone("GMT+1"));
	        System.out.println(greg);
	        System.out.println("1) " + greg.getTime());
	        System.out.println("\n-----\n");
	        
	        GregorianCalendar greg2 = new GregorianCalendar(1992,7,12,17,20,10);
	        System.out.println("Scenario 2");
	        System.out.println(greg2);
	        System.out.println("-- Printing Time --");
	        System.out.println("1) " + greg2.getTime());
	        System.out.println(greg2);
	        System.out.println("-- Setting Time Zone --");
	        greg2.setTimeZone(TimeZone.getTimeZone("GMT+1"));
	        System.out.println(greg2);
	        System.out.println("2) " + greg2.getTime());
	        System.out.println("\n-----\n");
	        
	        GregorianCalendar greg3 = new GregorianCalendar(1992,7,12,17,20,10);
	        System.out.println("Scenario 3");
	        System.out.println(greg3);
	        System.out.println("-- Printing Time --");
	        System.out.println("1)" + greg3.getTime());
	        System.out.println(greg3);
	        System.out.println("-- Adding Year --");
	        greg3.add(Calendar.YEAR, 1);
	        System.out.println(greg3);
	        System.out.println("-- Setting Time Zone --");
	        greg3.setTimeZone(TimeZone.getTimeZone("GMT+1"));
	        System.out.println(greg3);
	        System.out.println("2)" + greg3.getTime());
	        System.out.println("\n-----\n");

Code: Select all

Scenario 1
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=1992,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
-- Setting Time Zone --
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+01:00",offset=3600000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=1992,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
1) Wed Aug 12 12:20:10 EDT 1992

-----

Scenario 2
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=1992,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
-- Printing Time --
1) Wed Aug 12 17:20:10 EDT 1992
java.util.GregorianCalendar[time=713654410000,areFieldsSet=true,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=1992,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
-- Setting Time Zone --
java.util.GregorianCalendar[time=713654410000,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+01:00",offset=3600000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=1992,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
2) Wed Aug 12 17:20:10 EDT 1992

-----

Scenario 3
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=1992,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
-- Printing Time --
1)Wed Aug 12 17:20:10 EDT 1992
java.util.GregorianCalendar[time=713654410000,areFieldsSet=true,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=1992,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=12,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=?,ZONE_OFFSET=?,DST_OFFSET=?]
-- Adding Year --
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/New_York",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/New_York,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1993,MONTH=7,WEEK_OF_YEAR=33,WEEK_OF_MONTH=3,DAY_OF_MONTH=12,DAY_OF_YEAR=225,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=0,ZONE_OFFSET=-18000000,DST_OFFSET=3600000]
-- Setting Time Zone --
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+01:00",offset=3600000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=1993,MONTH=7,WEEK_OF_YEAR=33,WEEK_OF_MONTH=3,DAY_OF_MONTH=12,DAY_OF_YEAR=225,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=20,SECOND=10,MILLISECOND=0,ZONE_OFFSET=-18000000,DST_OFFSET=3600000]
2)Thu Aug 12 12:20:10 EDT 1993

-----
Image - Get your Detective Conan bobbleheads today! - Image
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

it would be stranger if it didn't have a time member :P

The issue is that when you construct a GregorianCalendar in that way, you're specifying a year/month/day/etc, but that's it. This doesn't actually mean anything to the system though because it doesn't know what timezone this is supposed to be in reference to, so until you call .setTimeZone for the first time, it has no idea what the actual system time is supposed to be (hence time=?, time being the time since the Epoch).

so, if you don't call setTimeZone before getTime, when you call getTime and it tries to make the Date object (which represents a specific point in time regardless of timezone (again, time since Epoch) ) to return, the current time held by the Calendar isn't a set point in time. To fix this (so that it actually can return something), it sets the time held by the calendar to an actual point in time based on your local timezone (which it already knows) and the month/year/day/etc that you passed into the constructor.

Calls after the first call to setTimeZone don't actually change anything, because changing the frame of reference doesn't change the actual true time.

edit: although I guess I should clarify from my previous post that I guess you could say that getTime() "finalizes" the time such that it causes the time to be set, but when I hear "finalize" in reference to java I think of "uneditable forevermore" like the java "final" keyword :P

edit2: actually, after looking at the output of c-square's example, it looks like it behaves a little differently than I thought. When the Calendar is constructed, it assumes your local timezone, which you can then override however often you want with setTimeZone(), as long as time is still undefined. The time is then only actually defined when you call getTime() (or probably, call any function that tries to make use of the actual absolute time). So yeah, it is a little weirder than it probably should be :V
Last edited by Akonyl on May 21st, 2012, 2:09 pm, edited 1 time in total.
User avatar
Callid
Ratio vincit omnia.

Posts:
1433

Re: Let's get programmy!

Post by Callid »

I have solved the problem by using the constructor with the TimeZone, followed by a .set(...) for the time. It's a bit strange there is no constructor for both, TimeZone and time :P

Code: Select all

                TimeZone tz;
                if (msg.length > 6) {
                    tz = TimeZone.getTimeZone("GMT" + msg[6]);
                } else {
                    tz = TimeZone.getTimeZone("GMT");
                }
                int[] date = formatDate(msg[4], sender);
                int[] time = formatTime(msg[5], sender);
                if (time == null || date == null) {
                    return;
                }
                GregorianCalendar greg = new GregorianCalendar(tz);
                greg.set(date[0], date[1], date[2], time[0], time[1], time[2]);
Also, DipBot just managed to, for the first time, create and finish a phase! *is totally proud* :D
Though I suppose it does need a bit of work :x
Spoiler:
A new phase (1901 Spring Retreat) was created in game 002. It's deadline is 21 May 2012 21:18:00 GMT.
Game 002: 2 minutes till deadline!
Game 002: 1 hours till deadline!
Game 002: 2 minutes till deadline!
Game 002: 1 hours till deadline!
Game 002: 2 minutes till deadline!
Game 002: 1 hours till deadline!
Game 002: 2 minutes till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 1 hours till deadline!
Game 002: 61 seconds till deadline!
Game 002: 51 seconds till deadline!
Game 002: 41 seconds till deadline!
Game 002: 31 seconds till deadline!
Game 002: 21 seconds till deadline!
Game 002: 11 seconds till deadline!
Game 002: 1 hours till deadline!
* DipBot has changed the topic to: 002: 1901 Spring Retreat Build PAUSED (one player(vittor) missing)
Game 002: 1 seconds till deadline!
Game 002: 1 minutes till deadline!
Deadline of game 002 reached! Orders are published below.
1901 Spring Retreat:
Great Britain (Callid):
Test
France (Callid):
No orders.
Germany (Callid):
No orders.
Italy (Callid):
No orders.
Russia (Callid):
No orders.
Austria-Hungary (Callid):
No orders.
Ottoman Empire (Callid):
No orders.
Note: All of the timer lines, except for the seconds, are off. The deadline was created 71 seconds before it ended.
If  ;), :D, ;D, ::), :P, :-X, :o or >:D are attached, that paragraph may not be 100% serious. Seriously.
This link provides further information.
Callid Conia Pact - Petitions - Archive
User avatar
Giogio
Why not?

Posts:
152

Re: Let's get programmy!

Post by Giogio »

I was wondering: Is there someone into AI's / neural networks here?

I've had an idea to have actually "life-like" intelligences evolve by (super-short version) putting them into an environment, allowing them to fight & eat each other, cooperate, and so on.
However, I never started it so far since i guess it would need a whole lot of computing time, and I'm not very knowledgeable about how to initialize such neural networks.
Also, maybe it was already done?

So, anyone interested in that stuff? :)
........................................................................................................... Image
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

tbh, you would probably be better off using genetic algorithms than neural networks if you wanted to do something like that. I'm not gonna pretend to be an expert on neural nets, but in general they're better suited to things like pattern recognition for the most part, I imagine using them to actually make complex decisions would require a much more in-depth knowledge of things, unless you split the problem apart, which then sorta defeats the purpose of a net. Not to mention, a neural net of any complexity would be absolute hell to debug if a problem ever rose up.

especially if you're going the competition route, that's a classic example of something people use genetic algorithms for. Not to mention, when something goes wrong you'll actually be able to fix it :P
User avatar
Giogio
Why not?

Posts:
152

Re: Let's get programmy!

Post by Giogio »

Sure. I wanted to combine the two things, to get suiting neural net topologies.
That's the main problem for me right now, how to put the topology into a genetic code in a way that allows reasonable mutations, but differs from the learning process I wanted to have too.

Basically, the genetic algorithm gives the starting point of every brain (and maybe, somehow, the way it learns), and then the individual is thrown into a world where it has to learn and adapt to various situations.
That way,  I hope, you could get nets that aren't limited to one special problem, but evolve to be able to learn fast. Much more like actual life forms. Maybe I'll get ants ^^

Does that make any sense to you? :)
........................................................................................................... Image
Akonyl
Community Hero

Posts:
4200

Re: Let's get programmy!

Post by Akonyl »

well, if you're using a genetic algorithm to set up the topologies, I guess my question is what your question really is in the first place :P

It seemed to me at first that you were wondering how to know how to connect the neurons, initial axon weights, etc, but if a genetic algorithm's going to take care of that then I'm not sure what your question actually is.

you also have to be careful how you train the net though / how large you make it, because you can end up over-training the net for specific problems which ends up making it worse overall. Well, theoretically, I've done so little with neural nets that it was never an issue :P

as for ants, that might also be a bit of a problem since the majority of swarm intelligence (like ants) only work because the entire population works on the same simple set of rules, and if you're running a bunch of different brains around in whatever the world is, the chance of them working together is pretty small, I would think. Besides, it's a lot easier to program an ant from scratch than to hope that a learning program would develop similar behavior (especially since ants use pheremone trails, which your things wouldn't unless they were specifically programmed to)
User avatar
Kogorou
*drinking beer and playing guitar*

Posts:
1132
Contact:

Re: Let's get programmy!

Post by Kogorou »

Well first of all we should define what an AI is.
Unless someone found a PROPER definition for that everyone can say that he or she has build an AI that is programmed to solve on special problem. Those AIs can even evolve and improve the way they solve the problems.

From what I get you want to build a swarm computation program.
you only need to programm one and start a couple of that program. All you need to make sure is that there is some king of connection between them.
For learning purpouse I would recommend to use a database. Just store the information and build an algorithm that can improve they way it's been stored, sort out any redundancy.

Just allow me one question: why?
Post Reply