Friday, November 13, 2009

just for fun

C
----------------------------------------------------------------------------------
# include
# include

extern int now();
extern void out();

int main(int argc, char* argv) {

// time since 1 jan 1970
time_t departing = argv[1];
time_t now = time(NULL);

while(now != departing) {
now++;
}

out();

return 0;
}

void out(){
printf("yay");
}


Python
-------------------------------------------------------------------------------------------
import datetime
import sys

now = datetime.datetime.now()

departing = datetime.datetime(2009,11,27,15,45,00,0000)

while (now != departing):
day = now.day
hour = now.hour
minute = now.minute
second = now.second
second += 1
if second == 60:
second = 0
minute = now.minute
minute += 1
if minute == 60:
minute = 0
hour = now.hour
hour += 1
if hour == 24:
hour = 0
day = now.day
day += 1
now = datetime.datetime(2009,11,day,hour,minute,second,0)

print "yay"
sys.exit()



Java
----------------------------------------------------------------------------------------
import java.util.Calendar;
import java.text.SimpleDateFormat;

public class DateUtils {
public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";

public static String now() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());

}

public static void main(String arg[]) {
String s = DateUtils.now();
int nw = Integer.parseInt(s); // ??
int dep = xxx // ??
while(nw != dep) { nw++; }
System.out.println("yay?");
}
}


Haskell
---------------------------------------------------------------------------------------------
update now =
| depart = put("yay")
| otherwise =update (now + 1)

0 comments: