首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >共享生日派对

共享生日派对
EN

Code Golf用户
提问于 2018-07-25 21:15:42
回答 1查看 343关注 0票数 8

一个办公室(我们称之为“办公室”)将在2019年通过合并办公室生日派对来减少浪费的时间。任何两个人如果在同一周的星期一到星期五(含)过生日,都会在同一周的某个时间举行生日聚会。生日定在星期六或星期天的人根本得不到任何聚会。

有些人不喜欢和那些没有分享他们的生日的人分享生日聚会。他们会非常愤怒的有一个共同的生日聚会。

我们将模拟一个办公室,并发现在第一周,有人非常愤怒,他们的共同生日派对。

挑战

编写一个程序或函数,输出2019年的第一个ISO周号,在该程序或函数中,模拟办公室中的某个人对他们共享的生日聚会感到非常愤怒,但必须遵守以下基本规则:

  • 输入一个整数N> 1,这是办公室的工人人数。
  • 从1月1日到12月31日(忽略2月29日),N个生日本身都是随机分布的。
  • 但为确定共同生日缔约方的目的,工作周为2019年ISO周日期,在2019-W01-1 (2018-12-31)和2019-W52-7 (2019-12-29)之间。新的ISO周每星期一开始。(我认为这是你真正需要知道的关于ISO周的这项挑战)。
  • 对于办公室里的N个人来说,每个人都有1/3的机会拥有一个非常愤怒的生日派对个性类型,所以你也得模拟一下。
  • 但是,如果与生日相同的人分享这个聚会,他们不会生气。
  • 输出ISO周号(这方面的确切格式是灵活的,只要周号是清楚的),第一次出现非常愤怒的人。如果没有愤怒的人,你可以输出任何与ISO周没有混淆的东西,或者程序可能出错等等。

一些简化的假设:

  • 正如我提到的,完全忽略2月29日的问题(一个不必要的复杂问题)。
  • 忽略公共假日(这是一个国际社会,所以我们的假期会有所不同),只需假设办公室在每个工作日都开放。

规则

这是暗号高尔夫。每种语言的最短答案(以字节为单位)获胜。默认漏洞被禁止。

代码解释欢迎。

工作示例

输入N= 7的示例1。第一列和第二列是规则中描述的随机列(当然这里不是随机列)。

代码语言:javascript
复制
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个未指定。

代码语言:javascript
复制
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或类似的东西。

EN

回答 1

Code Golf用户

发布于 2018-07-31 09:31:11

Java 8,198字节

代码语言:javascript
复制
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表示没有非常愤怒的人.试一试在线这里

未高尔夫球:

代码语言:javascript
复制
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
}
票数 1
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/169260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档