一个办公室(我们称之为“办公室”)将在2019年通过合并办公室生日派对来减少浪费的时间。任何两个人如果在同一周的星期一到星期五(含)过生日,都会在同一周的某个时间举行生日聚会。生日定在星期六或星期天的人根本得不到任何聚会。
有些人不喜欢和那些没有分享他们的生日的人分享生日聚会。他们会非常愤怒的有一个共同的生日聚会。
我们将模拟一个办公室,并发现在第一周,有人非常愤怒,他们的共同生日派对。
挑战
编写一个程序或函数,输出2019年的第一个ISO周号,在该程序或函数中,模拟办公室中的某个人对他们共享的生日聚会感到非常愤怒,但必须遵守以下基本规则:
一些简化的假设:
这是暗号高尔夫。每种语言的最短答案(以字节为单位)获胜。默认漏洞被禁止。
代码解释欢迎。
输入N= 7的示例1。第一列和第二列是规则中描述的随机列(当然这里不是随机列)。
Angry Type
Person? Birthday ISO Week Comment
================================================================================
N 2018-12-31 W01 In the 2019 ISO week date year
Y 2018-12-31 W01 Same birthday, so no anger happens
N 2019-02-05 W06
Y 2019-03-15 W11 No anger happens because other W11 b-day is a Saturday
N 2019-03-16 W11
N 2019-09-08 W36 My birthday!
Y 2019-12-30 - Not in the 2019 ISO week date year所以不会有愤怒发生。程序或函数可以错误输出或输出与ISO周号不混淆的内容。
示例2,N个未指定。
Angry Type
Person? Birthday ISO Week Comment
================================================================================
N 2019-01-19 W03
Y 2019-02-04 W06
N 2019-02-05 W06 No anger because not an angry person
... ... ... (No angry people until...)
Y 2019-03-12 W11 Very Angry Person!
N 2019-03-14 W11
... ... ... ... 输出将是W11或类似的东西。
发布于 2018-07-31 09:31:11
double r(){return Math.random();}
n->{int r=52,a[]=new int[r];for(;n-->0;)if(r()*364>104)++a[(int)(r()*r)];for(;++n<52;)r=r>51&a[n]>1&r()<1-5/Math.pow(5,a[n])&r()<1-Math.pow(2./3,a[n])?n:r;return r;}输出是基于零的(0-51);值52表示没有非常愤怒的人.试一试在线这里。
未高尔夫球:
double r() { return Math.random(); } // shortcut for Math.random(), saves a few bytes
n -> { // lambda taking an intger argument and returning an integer
int r = 52, // this will hold the result; set to the value for "no Very Angry people" for now
a[] = new int[r]; // array counting the people whose birthday lies in each week
for(; n-- > 0; ) // for each person:
if(r() * 364 > 104) // determine whether their birthday is on a weekday that is not the 30th of December ...
++a[(int) (r() * r)]; // ... only if so, increment the counter for a random ISO week
for(; ++n < 52; ) // loop through the weeks; n is -1 before the loop
r = r > 51 // if r is still the default ...
& a[n] > 1 // ... and there is more than one person with a birthday that week ...
& r() < 1 - 5/Math.pow(5, a[n]) // ... and at least two people have a different birthday ...
&r() < 1 - Math.pow(2./3, a[n]) // ... and at least one person has the Very Angry personality type ...
? n // ... set the current week as the result ...
: r; // ... otherwise leave it the same
return r; // return the result
}https://codegolf.stackexchange.com/questions/169260
复制相似问题