由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 把月末周末重合的答案公布一下
相关主题
[合集] First impression on Python问个PYTHON问题
这问题有没有好办法做?Python程序员请进
怎样遍历一个字母的组合 (转载)请教python高手异步编程的问题
问个python的例子Python里面的for i in range(len(enum))[::-1]:到底是什么意思?
Python问题请教Hadoop: the definitive guide出第四版了 (转载)
python弱问题Third-party Node.js Foundation takes over jurisdiction of
Python做计算怎么只用一个核?cocos2D和cocos2D-JS啥区别?
请教python请教一个python OOP 实现的问题
h**********c
2016-05-01 23:12:38
1
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class MonthEndWeekEnd {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
// get the beginning of time, it is the design of modern operating
// system 0 timestamp.
cal.setTimeInMillis(0l);
Date d = cal.getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy
EEE");
String str = dateFormatter.forma
h**********c
2016-05-01 23:15:38
2
unfortunately, only java programmer provided a correct answer.
So probably other languages can be considered great grandparent language
programmers. TBD
probably a job in the reserve or museum suits them. QED

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

h**********c
2016-05-01 23:19:47
3
这个题把面向对象设计的应用发挥到了极至,
and it solves a coldest case in MIT bbs. Java rocks.
it also shows how dangerous it is, while comparing objects with primitive
operators.

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

n******7
2016-05-01 23:40:02
4
说说这个问题有啥特别?
不就把每个月末check一下就好?
搜到一段excel 的vba代码
Public Function IsWeekend(InputDate As Date) As Boolean
Select Case Weekday(InputDate)
Case vbSaturday, vbSunday
IsWeekend = True
Case Else
IsWeekend = False
End Select
End Function
h**********c
2016-05-01 23:49:15
5
那你月末是怎么算的,julian calendar paper你看了吗?

【在 n******7 的大作中提到】
: 说说这个问题有啥特别?
: 不就把每个月末check一下就好?
: 搜到一段excel 的vba代码
: Public Function IsWeekend(InputDate As Date) As Boolean
: Select Case Weekday(InputDate)
: Case vbSaturday, vbSunday
: IsWeekend = True
: Case Else
: IsWeekend = False
: End Select

n******7
2016-05-02 00:20:09
6
哪个paper?给个连接
月末都是固定日期,就是考虑个闰年
这些日期函数的事情,你也是用的日期函数
跟啥语言有啥关系
我感觉直接算也可以,就是算闰年稍微麻烦点

【在 h**********c 的大作中提到】
: 那你月末是怎么算的,julian calendar paper你看了吗?
n******7
2016-05-02 01:02:32
7
随便写了几行python
跟你的结果一样
===
def leapyr(n):
if n % 400 == 0:
return True
if n % 100 == 0:
return False
if n % 4 == 0:
return True
else:
return False
days = [31,28,31,30,31,30,31,31,30,31,30,31]
start_year = 1970
end_year = 2099
weekday = 3 # 12/31/1969 Wed
weekend = 5 # Fri
for year in xrange(start_year,end_year):
for month in xrange(1,13):
n_days = days[month-1]
if leapyr(year) and month == 2:
n_days = 29
weekda
h**********c
2016-05-02 08:58:09
8
i don't understand your rocket science, can you print your out put.
thks

【在 n******7 的大作中提到】
: 随便写了几行python
: 跟你的结果一样
: ===
: def leapyr(n):
: if n % 400 == 0:
: return True
: if n % 100 == 0:
: return False
: if n % 4 == 0:
: return True

c**o
2016-05-02 09:15:36
9
I did run the python code, and the results are the same as given by your
java code:
Here are the last few lines:
11/30/2998
5/31/2999
1/31/3000
2/28/3000
10/31/3000
Total = 1764

【在 h**********c 的大作中提到】
: i don't understand your rocket science, can you print your out put.
: thks

h**********c
2016-05-02 09:22:24
10
How do you handle the seasonal calendar error?
At your customized code?

【在 c**o 的大作中提到】
: I did run the python code, and the results are the same as given by your
: java code:
: Here are the last few lines:
: 11/30/2998
: 5/31/2999
: 1/31/3000
: 2/28/3000
: 10/31/3000
: Total = 1764

h**********c
2016-05-02 09:30:41
11
这样,请算一下从公元0到3000年到每一个周末月末重合的微秒值,
因为java program首先提供的代码(verifiable),而且python的实现基本和java
gregoriancalendar calss 里的代码一样。
所以我们提高一下gorgeousness

【在 c**o 的大作中提到】
: I did run the python code, and the results are the same as given by your
: java code:
: Here are the last few lines:
: 11/30/2998
: 5/31/2999
: 1/31/3000
: 2/28/3000
: 10/31/3000
: Total = 1764

s*i
2016-05-02 12:03:59
12
Once you realize (month-end, friday) === (next day: month-start,
saturday), it becomes
trivial.
Javascrip code example:
var d = new Date(0);
while(d.getFullYear() < 3000) {
if(d.getDate() == 1 && d.getDay() == 6) {
//previous day must be a solution
d.setDate(d.getDate() - 1);
console.log(d);
//set the date back to current
d.setDate(d.getDate() + 1);
}
d.setDate(d.getDate() + 1);
}
b*******s
2016-05-02 18:00:04
13
WTF
n*****t
2016-05-02 21:00:34
14
太无聊了,这种题要用 regexp 才过瘾

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

h**********c
2016-05-02 22:47:06
15
这个是OO的正解
不过看个wiki了解一下背后的故事很难吗,我老就一俗人,不谈科学。

【在 s*i 的大作中提到】
: Once you realize (month-end, friday) === (next day: month-start,
: saturday), it becomes
: trivial.
: Javascrip code example:
: var d = new Date(0);
: while(d.getFullYear() < 3000) {
: if(d.getDate() == 1 && d.getDay() == 6) {
: //previous day must be a solution
: d.setDate(d.getDate() - 1);
: console.log(d);

h**********c
2016-05-02 23:35:02
16
这个地方很有意思
AD 11/30/0008 Fri
AD 08/31/0008 Fri
AD 09/30/0007 Fri
AD 12/31/0006 Fri
AD 04/30/0006 Fri
AD 07/31/0005 Fri
AD 10/31/0004 Fri
AD 02/29/0004 Fri
AD 11/30/0003 Fri
AD 08/31/0003 Fri
AD 06/30/0002 Fri
AD 03/31/0002 Fri
AD 09/30/0001 Fri
BC 12/31/0001 Fri
BC 04/30/0001 Fri
BC 10/31/0002 Fri
BC 02/28/0002 Fri
BC 01/31/0002 Fri
BC 05/31/0003 Fri
BC 11/30/0004 Fri
BC 08/31/0004 Fri
BC 06/30/0005 Fri
BC 03/31/0005 Fri
BC 12/31/0006 Fri
BC 04/30/0006 Fri
BC 07/31/0007 Fri
BC 10/31/0008 Fri

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

h**********c
2016-05-02 00:12:38
17
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class MonthEndWeekEnd {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
// get the beginning of time, it is the design of modern operating
// system 0 timestamp.
cal.setTimeInMillis(0l);
Date d = cal.getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy
EEE");
String str = dateFormatter.forma
h**********c
2016-05-02 00:15:38
18
unfortunately, only java programmer provided a correct answer.
So probably other languages can be considered great grandparent language
programmers. TBD
probably a job in the reserve or museum suits them. QED

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

h**********c
2016-05-02 00:19:47
19
这个题把面向对象设计的应用发挥到了极至,
and it solves a coldest case in MIT bbs. Java rocks.
it also shows how dangerous it is, while comparing objects with primitive
operators.

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

n******7
2016-05-02 00:40:02
20
说说这个问题有啥特别?
不就把每个月末check一下就好?
搜到一段excel 的vba代码
Public Function IsWeekend(InputDate As Date) As Boolean
Select Case Weekday(InputDate)
Case vbSaturday, vbSunday
IsWeekend = True
Case Else
IsWeekend = False
End Select
End Function
h**********c
2016-05-02 00:49:15
21
那你月末是怎么算的,julian calendar paper你看了吗?

【在 n******7 的大作中提到】
: 说说这个问题有啥特别?
: 不就把每个月末check一下就好?
: 搜到一段excel 的vba代码
: Public Function IsWeekend(InputDate As Date) As Boolean
: Select Case Weekday(InputDate)
: Case vbSaturday, vbSunday
: IsWeekend = True
: Case Else
: IsWeekend = False
: End Select

n******7
2016-05-02 01:20:09
22
哪个paper?给个连接
月末都是固定日期,就是考虑个闰年
这些日期函数的事情,你也是用的日期函数
跟啥语言有啥关系
我感觉直接算也可以,就是算闰年稍微麻烦点

【在 h**********c 的大作中提到】
: 那你月末是怎么算的,julian calendar paper你看了吗?
n******7
2016-05-02 02:02:32
23
随便写了几行python
跟你的结果一样
===
def leapyr(n):
if n % 400 == 0:
return True
if n % 100 == 0:
return False
if n % 4 == 0:
return True
else:
return False
days = [31,28,31,30,31,30,31,31,30,31,30,31]
start_year = 1970
end_year = 2099
weekday = 3 # 12/31/1969 Wed
weekend = 5 # Fri
for year in xrange(start_year,end_year):
for month in xrange(1,13):
n_days = days[month-1]
if leapyr(year) and month == 2:
n_days = 29
weekda
h**********c
2016-05-02 09:58:09
24
i don't understand your rocket science, can you print your out put.
thks

【在 n******7 的大作中提到】
: 随便写了几行python
: 跟你的结果一样
: ===
: def leapyr(n):
: if n % 400 == 0:
: return True
: if n % 100 == 0:
: return False
: if n % 4 == 0:
: return True

c**o
2016-05-02 10:15:36
25
I did run the python code, and the results are the same as given by your
java code:
Here are the last few lines:
11/30/2998
5/31/2999
1/31/3000
2/28/3000
10/31/3000
Total = 1764

【在 h**********c 的大作中提到】
: i don't understand your rocket science, can you print your out put.
: thks

h**********c
2016-05-02 10:22:24
26
How do you handle the seasonal calendar error?
At your customized code?

【在 c**o 的大作中提到】
: I did run the python code, and the results are the same as given by your
: java code:
: Here are the last few lines:
: 11/30/2998
: 5/31/2999
: 1/31/3000
: 2/28/3000
: 10/31/3000
: Total = 1764

h**********c
2016-05-02 10:30:41
27
这样,请算一下从公元0到3000年到每一个周末月末重合的微秒值,
因为java program首先提供的代码(verifiable),而且python的实现基本和java
gregoriancalendar calss 里的代码一样。
所以我们提高一下gorgeousness

【在 c**o 的大作中提到】
: I did run the python code, and the results are the same as given by your
: java code:
: Here are the last few lines:
: 11/30/2998
: 5/31/2999
: 1/31/3000
: 2/28/3000
: 10/31/3000
: Total = 1764

s*i
2016-05-02 13:03:59
28
Once you realize (month-end, friday) === (next day: month-start,
saturday), it becomes
trivial.
Javascrip code example:
var d = new Date(0);
while(d.getFullYear() < 3000) {
if(d.getDate() == 1 && d.getDay() == 6) {
//previous day must be a solution
d.setDate(d.getDate() - 1);
console.log(d);
//set the date back to current
d.setDate(d.getDate() + 1);
}
d.setDate(d.getDate() + 1);
}
b*******s
2016-05-02 19:00:04
29
WTF
n*****t
2016-05-02 22:00:34
30
太无聊了,这种题要用 regexp 才过瘾

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

h**********c
2016-05-02 23:47:06
31
这个是OO的正解
不过看个wiki了解一下背后的故事很难吗,我老就一俗人,不谈科学。

【在 s*i 的大作中提到】
: Once you realize (month-end, friday) === (next day: month-start,
: saturday), it becomes
: trivial.
: Javascrip code example:
: var d = new Date(0);
: while(d.getFullYear() < 3000) {
: if(d.getDate() == 1 && d.getDay() == 6) {
: //previous day must be a solution
: d.setDate(d.getDate() - 1);
: console.log(d);

h**********c
2016-05-03 00:35:02
32
这个地方很有意思
AD 11/30/0008 Fri
AD 08/31/0008 Fri
AD 09/30/0007 Fri
AD 12/31/0006 Fri
AD 04/30/0006 Fri
AD 07/31/0005 Fri
AD 10/31/0004 Fri
AD 02/29/0004 Fri
AD 11/30/0003 Fri
AD 08/31/0003 Fri
AD 06/30/0002 Fri
AD 03/31/0002 Fri
AD 09/30/0001 Fri
BC 12/31/0001 Fri
BC 04/30/0001 Fri
BC 10/31/0002 Fri
BC 02/28/0002 Fri
BC 01/31/0002 Fri
BC 05/31/0003 Fri
BC 11/30/0004 Fri
BC 08/31/0004 Fri
BC 06/30/0005 Fri
BC 03/31/0005 Fri
BC 12/31/0006 Fri
BC 04/30/0006 Fri
BC 07/31/0007 Fri
BC 10/31/0008 Fri

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

h**********c
2017-11-12 12:21:42
33
RE

【在 h**********c 的大作中提到】
: unfortunately, only java programmer provided a correct answer.
: So probably other languages can be considered great grandparent language
: programmers. TBD
: probably a job in the reserve or museum suits them. QED

g*********9
2017-11-12 14:02:47
34
原题在哪?

【在 h**********c 的大作中提到】
: import java.text.SimpleDateFormat;
: import java.util.Calendar;
: import java.util.Date;
: public class MonthEndWeekEnd {
: public static void main(String[] args) {
: Calendar cal = Calendar.getInstance();
: // get the beginning of time, it is the design of modern operating
: // system 0 timestamp.
: cal.setTimeInMillis(0l);
: Date d = cal.getTime();

h**********c
2017-11-12 14:04:26
35
原题就是“求周末和月末重合”

【在 g*********9 的大作中提到】
: 原题在哪?