模拟宇宙!


103

图灵完备语言的一个不错的特性是,它可以用来编写任何程序,甚至可以模拟整个宇宙。

您的工作就是做到这一点:编写一个模拟Universe的程序


注意:尽管我毫不怀疑您将能够完成此任务,但如今我没有足够的业余时间来验证模拟中的所有10 90个粒子是否都按其实际应做的工作。因此,仅是为了简化测试和评估,如果您的Universe模拟器仅适用于单个起始粒子就足够了。为了使事情有趣,让我们假设这个粒子是最近发现的希格斯玻色子。

您的宇宙仅以一个中间约120 GeV的希格斯玻色子开始。为了不使输出太长,让我们使该Universe仅在10 -25秒处滴答,而不是其“常规时钟频率”为5.4×10 -44秒。

希格斯玻色子的衰变半衰期为1.6×10 -22秒,因此迟早会衰变,因此在模拟的每个滴答声中,衰变的可能性为0.0433%。您可以在此处检查它会衰减成什么。为了有一个集中的简化需求,我列出了您应该使用的分支比率:

运行模拟

在每次模拟时,希格斯玻色子都有0.0433%的衰减机会。如果发生这种情况,它将分解为具有列出的概率的以下粒子(您应该在输出中使用这些名称):

  • 底夸克+底夸克(64.8%)
  • 2 W玻色子(14.1%)
  • 2加仑(8.82%)
  • 头蛋白轻蛋白+头蛋白轻蛋白(7.04%)
  • 夸克+夸克(3.27%)
  • 2个玻色子(1.59%)
  • 2个光子(0.223%)
  • 1 Z玻色子+ 1光子(0.111%)
  • 介子+反介子(0.0244%)
  • 顶夸克+顶抗夸克(0.0216%)

总计为100%。

这些粒子中的一些会进一步衰减。

W玻色子:半衰期为10 -25秒,这意味着每个滴答声都有50%的机会分解为下列概率相等的下列之一:

  • 正电子+中微子
  • 反介子+中微子
  • Antitau Lepton +中微子

Z玻色子:半衰期为10 -25秒,这意味着在每个刻度上都有50%的机会分解为下列其中之一:

  • 中微子+抗中微子(20.6%)
  • 电子+正电子(3.4%)
  • 介子+反介子(3.4%)
  • 牛头顿+牛头顿(3.4%)
  • 下夸克+下夸克(15.2%)
  • 夸克+夸克(15.2%)
  • 底夸克+底夸克(15.2%)
  • 夸克+反夸克(11.8%)
  • 夸克+夸克(11.8%)

顶夸克:半衰期为5×10 -25秒,这意味着在每个刻度上有12.95%的机会衰减为以下几率,并且概率相同:

  • 玻色子+夸克
  • 玻色子+夸克
  • W玻色子+底夸克

当然,W玻色子也会很快衰减...

顶夸克的行为类似于顶夸克:它衰变为A,带玻色子和广告/ S / B夸克。

所有其他粒子(除了Z和W玻色子和顶夸克之外的所有粒子)的半衰期更长许多个数量级,因此为了不干扰输出,在我们的模拟中它们都被认为是稳定的

由于宇宙基本上是空的,所以所有粒子将为自己留有足够的空间,并且不会互相影响。因此,所有单个粒子在各个方面都彼此独立,包括分裂的可能性。

输出:

模拟的每一步都必须将模拟Universe的内容打印到新行中。例如:

The universe contains 1 Higgs boson.
The universe contains 1 Higgs boson.
The universe contains 1 Higgs boson.
The universe contains 1 Higgs boson.
The universe contains 2 W bosons.
The universe contains 2 W bosons.
The universe contains 1 W boson, 1 positron and 1 neutrino.
The universe contains 1 positron, 1 antitau lepton and 2 neutrinos.
Simulation ended after 0.8 yoctoseconds.

生产线上的颗粒顺序并不重要。但是,格式必须与上面的示例完全相同,包括标点和复数形式。如果您模拟整个(微型)宇宙,它应该看起来不错(我想消除对不够严格的输出要求的滥用)

每行对应于0.1 yoctoseconds,但是如果您花费比程序输出输出更长的时间,您将被原谅。

当仅保留“稳定”的粒子时,模拟结束。

计分

适用标准代码高尔夫规则。

随机数生成器可以是伪随机数,但是如果语言默认情况下不将其作为种子,则必须将其作为种子。您的RNG的概率分布必须均匀。

  • 如果程序采用整数作为输入,并以那么多希格斯玻色子开始,则您将获得代码大小的-10%的奖励。

图灵机爱好者的例外。

对于那些敢于尝试使用实际 Turing机器或类似语言(例如Brainfuck)的用户,通过以下规则更改,他们的任务会变得更加容易(仅当语言是Brainfuck衍生语言或其他非常简化的Turing-机器,无法分配,缺少ALU,并且磁带上的值只能递增和递减1)

  • 对于夸克,粒子名称简化为d,s,b,t,u,c,对于中微子,v表示tau lepton,t表示mu,m表示胶子,g表示胶子,p表示光子,Z,W和H表示玻色子,-表示电子,+表示正电子。在每个滴答处,从标准输入中提供值为0或1的输入,指示列表中的第一个不稳定粒子是否衰减。

因此,示例输出将变为

H
H
H
H
W W
W W
W + n
+ !T n n

76
Mathematica是否具有SimulateUniverse内置功能?
Digital Trauma 2015年

14
所以...这个宇宙没有大爆炸...-只是一个小爆炸?
级圣河

3
如果顶夸克衰变,顶夸克也不应衰变吗?我想没关系,规则就是规则。但是物理学是物理学(我的粒子物理学不是很好,但似乎很奇怪。)
Level River St

23
我们的整个宇宙可能是一场高尔夫挑战赛。
coredump 2015年

18
我想我会最好地应对这一挑战...;)
Beta Decay

Answers:


1

Pyth,572 * 0.9 = 514.8字节

Jm?tld,hd,-1^.5c1shced\ sm*]<k2s>k2tced\ dcR\,cu:GhHtHc"A76 !B17 !C1 v!D_top !E00 !F bosR!GmuR_!Ineutrino_!Jtau leptR_!KQ_charm !LQ_strange !MQ_down !NQ_up !OQ_bottom !Panti!Qquark!Ron"\!"HiggsF,16Efg3240Ebb705Epp441Eqr352ER16350 cc7950 ss1115 cs555 tu122 de108_WF,CxCuCr1_ZF,Cw103 yxBtuBqrBjkAlmAfgAhi59 R59DQ,5 bj1 bl1 bf1DPOOPNNPMMPLLPKKPQ_gluR_JPJphotR_GPGIPIpositrR_electrR"\_L%"The universe contains %s.":j", "fT.e?bs[b\ h@Jk?tb\s"")0b",(?!.*,)"" and"K+Q*]Z24Ws<K4yK=+Z1Vs.em?>O1.0he@JkY,kOee@Jkb<K4IN XhNK_1 XRK1xLGeN;yK%"Simulation ended after %s yoctoseconds."cZT

有资格获得-10%的奖金。在线试用这里,或者尝试一下与希格斯玻色子半衰期降低到1ys 这里(使得在输出较少的重复和更精彩的宇宙!)。

我坚信这远非最佳,尤其是字典压缩,但是我已经在此上浪费了足够的时间,因此欢迎提出改进建议。

该程序分为三个部分-字典准备,输出函数定义和模拟执行。

字典准备

Jm?tld,hd,-1^.5c1shced\ sm*]<k2s>k2tced\ dcR\,cu:GhHtHc"A76 !B17 !C1 v!D_top !E00 !F bosR!GmuR_!Ineutrino_!Jtau leptR_!KQ_charm !LQ_strange !MQ_down !NQ_up !OQ_bottom !Panti!Qquark!Ron"\!"HiggsF,16Efg3240Ebb705Epp441Eqr352ER16350 cc7950 ss1115 cs555 tu122 de108_WF,CxCuCr1_ZF,Cw103 yxBtuBqrBjkAlmAfgAhi59 R59DQ,5 bj1 bl1 bf1DPOOPNNPMMPLLPKKPQ_gluR_JPJphotR_GPGIPIpositrR_electrR"\_

这是完成的代码的最大部分,占用381个字节。该字典是使用以下字符串构建的:

Higgs boson,1600 fg324000 bb70500 pp44100 qr35200 on16350 cc7950 ss1115 cs555 tu122 de108_W boson,1 vx1 vu1 vr1_Z boson,1 vw103 yx17 tu17 qr17 jk76 lm76 fg76 hi59 on59_top quark,5 bj1 bl1 bf1_top antiquark_bottom quark_bottom antiquark_up quark_up antiquark_down quark_down antiquark_strange quark_strange antiquark_charm quark_charm antiquark_gluon_tau lepton_antitau lepton_photon_muon_antimuon_neutrino_antineutrino_positron_electron

该字符串是一个由下划线分隔的粒子列表,如果粒子是不稳定的,则表示其行为-一个由空格分隔的列表,包括其在模拟滴答声中的半衰期,其衰减后的值以及每个残差的概率。每个粒子都有一个与之关联的单字母代码,由它们在列表中的位置(以小写字母索引)给出,因此希格斯玻色子为aW玻色子b,一直到电子为y

而不是存储衰减概率,而是存储半衰期,并在处理字典时计算出概率。所使用的公式是P=1-(1/2)^(1/h)哪里P是每跳的衰减概率,是以跳为h单位测量的粒子的半衰期。

不稳定粒子是列表中的前四个。由于这些粒子的数量决定了仿真何时结束,因此将这些粒子放在列表的开头可以使它们易于稍后检查。

问题在于此字符串很大-436个字节!-并且使用Pyth的内置字符串压缩实际上会增加字节数,因为它使用了很多多字节字符。我已经确定了一个相对简单的迭代字典压缩方案。片段u:GhHtHc"xxx"\!"yyy"将其解压缩,如下所示:

u:GhHtHc"xxx"\!"yyy"   xxx -> dictionary, yyy -> encoded string
       c"xxx"\!        Chop the dictionary on !
u              "yyy"   Reduce the above, with initial state as encoded string, using:
 :G                      In the current string, replace...
   hH                    ... the first character of the dictionary entry...
     tH                  ... with the remainder of the dictionary entry

我选择的词典条目仅基于我的直觉和一些尝试和错误,因此,我确定有很大的改进空间。

然后,解压缩的字典字符串将按以下说明进行解释和存储:

Jm?tld,hd,-1^.5c1shced\ sm*]<k2s>k2tced\ dcR\,cxxx\_   xxx -> decompressed dictionary
                                              cxxx\_   Split the string on underscores
                                          cR\,         Split each part on commas
 m                                                     Map each element (particle), d, using:
  ?tld                                   d               Is the element length >1? If not, no change, otherwise...
      ,hd                                                  Create a pair consisting of the particle's name and...
                   ced\                                      Split the decay data on spaces
                 sh                                          Parse 1st element (half life) as int
          -1^.5c1                                            Calculate per-tick decay probability
         ,                                                   Pair the above with...
                         m         tced\                       Map the rest of the decay data, k, using:
                           ]<k2                                  Take the 1st two characters
                               s>k2                              Parse the rest of the characters as a string
                          *                                      Repeat the characters that many times
                        s                                      Flatten the list
J                                                      Store the processed dictionary in J

结果是J包含粒子名称的有序列表。如果它们衰变,则将名称与它的衰变概率以及可能会衰变的一组粒子配对,并按其相对概率进行加权。

输出功能定义

L%"The universe contains %s.":j", "fT.e?bs[b\ h@Jk?tb\s"")0b",(?!.*,)"" and"

这定义了一个函数y(b),该函数接受Universe的当前状态作为其输入。这只是粒子数量的列表,按上一节中描述的字典字符串中定义的类型排序。

L%"x":j", "fT.e?bs[b\ h@Jk?tb\s"")0b",(?!.*,)"" and"   "x" -> format string, omitted for brevity
L                                                      Define a function, y(b)
             .e                     b                  Map each element of b with its index, k, using:
               ?b                 0                     Is b non zero? If not, 0, otherwise...
                   b                                      Particle count
                    \                                     Space
                      h@Jk                                Particle name (lookup in dictionary, then take 1st element)
                          ?tb\s""                        Trailing s if more than 1
                 s[              )                       Concatenate the above 4
           fT                                          Filter out the 0s
      j", "                                            Join on comma + space
     :                                                 Replace in the above...
                                    ",(?!.*,)"         ... the last comma...
                                              " and"   ... with "and"
 %"x"                                                  Insert the above into the format string

模拟执行

K+Q*]Z24Ws<K4yK=+Z1Vs.em?>O1.0he@JkY,kOee@Jkb<K4IN XhNK_1 XRK1xLGeN;yK%"Simulation ended after %s yoctoseconds."cZT

完成准备工作后,即可执行仿真。这包括几个步骤:

宇宙初始化

由于宇宙状态下索引为0的粒子是希格斯玻色子,因此宇宙的初始状态是输入数字的数组,后跟24个零。

K+Q*]Z24   implicit: Q=eval(input())
  Q        Input number
   *]Z24   0 repeated 24 times
 +         Concatenate
K          Assign to K

仿真循环

在模拟的每个滴答声中,需要显示宇宙的当前状态,增加一个计数器,并且每个挥发性粒子需要检查它是否应该衰减,一旦对每个粒子进行评估,就将结果应用于宇宙状态。

Ws<H4yK=+Z1Vs.em?>O1.0he@JkY,kOee@Jkb<K4IN XhNK_1 XRK1xLGeN;   
 s<K4                                                          Take the sum of the first 4 particle counts
W                                                          ;   Loop until the above is 0
     yK                                                        Output the current universe state
       =+Z1                                                    Increment variable Z (initially 0)
             .e                      <K4                       Map each particle count, b, with its index, k, using:
               m                    b                            Map over the particle count using:
                        @JK                                        Look up the particle data
                      he                                           Get the decay probability
                  O1.0                                             Generate random float between 0 and 1
                ?>         Y                                       Has particle failed to decay? Empty array if so, otherwise...
                               ee@Jk                                 Get the particle decay choices
                              O                                      Choose one of them at random
                            ,k                                       Create a pair with the current particle index and the above
            s                                                  Combine into single nested list
           V                                                   For N in the above:
                                        IN                       If N is not empty:
                                           X  K                    Add to element in K...
                                            hN                     ... at the correct particle's index...
                                               _1                  ... -1
                                                      xLGeN        Get the index of each particle to be added to the universe
                                                                     (lookup using index in G, lowercase alphabet)
                                                  XRK1             Add 1 to the element in K at each of the indexes

最终输出

当没有不稳定的粒子时,模拟结束。剩下的就是输出宇宙的最终状态,以及模拟花费了多长时间(多少滴答声)。

yK%"Simulation ended after %s yoctoseconds."cZT   
yK                                                Output final universe state
                                            cZT   Float divide ticks count by 10
  %"Simulation ended after %s yoctoseconds."      Format string, implicit print

23

C ++(2420224323531860,1822 * 0.9 = 1639.8)

好的,这可能是有史以来最糟糕的高尔夫代码提交,但这是我的第一次,我很开心。我认为它甚至有效。:)

#include <iostream>
#include <list>
#include <string>
#include <time.h>
#define D r=rand();d=((double)r/RAND_MAX)
using namespace std;class P{int n[25];public:int S;P(int N){for(S=0;S<24;S++)n[S]=0;n[24]=N;S=1;}void C(){string s[25]={"down quark","down antiquark","up quark","up antiquark","bottom quark","bottom antiquark","tau lepton","antitau lepton","charm quark","charm antiquark","strange quark","strange antiquark","neutrino","antineutrino","muon","antimuon","gluon","photon","electron","positron","top quark","top antiquark","Z boson","W boson","Higgs boson"};int r,i,j,w,f,F,x,y;double d;S=0;F=0;for(i=0;i<25;i++){w=0;for(j=0;j<n[i];j++){D;x=-1;y=-1;if(i==24){if(d<.000433){D;if(d<.648){x=4;y=5;}else if(d<.789){x=23;y=23;}else if(d<.8772){x=16;y=16;}else if(d<.9476){x=6;y=7;}else if(d<.9803){x=8;y=9;}else if(d<.9962){x=22;y=22;}else if(d<.99843){x=17;y=17;}else if(d<.99954){x=22;y=17;}else if(d<.999784){x=14;y=16;}else{x=21;y=20;}}}else if(i==23){if(d<.5){D;if(d<.33){x=19;y=12;}else if(d<.67){x=16;y=12;}else{x=17;y=12;}}}else if(i==22){if(d<.5){D;if(d<.206){x=12;y=13;}else if(d<.24){x=18;y=19;}else if(d<.274){x=14;y=16;}else if(d<.308){x=16;y=17;}else if(d<.46){x=0;y=1;}else if(d<.612){x=10;y=11;}else if(d<.764){x=4;y=5;}else if(d<.882){x=2;y=3;}else{x=8;y=9;}}}else if(i==21||i==20){if(d<.1295){D;x=23;if(d<.33){y=0;}else if(d<.67){y=10;}else{y=4;}if(i==21)y-=32;}}if(x>=0){++n[x];++n[y];w++;}if(x>19||y>19)S=1;}n[i]-=w;if(n[i]>0){F=i;if(i>19)S=1;}}cout<<"The universe contains";f=0;for(i=0;i<25;i++){if(n[i]>0){cout<<(f>0?(i<F?", ":" and "):" ")<<n[i]<<' '<<s[i]<<(n[i]>1?"s":"");f=1;}}cout<<'.'<<endl;}};int main(int c,char* v[]){int w=1,y=0;if(c>1){w=atoi(v[1]);}srand(time(0));rand();P p=P(w);int Time=time(0);while(p.S){p.C();y++;}cout<<"Simulation ended after "<<(double)y/10<<" yoctoseconds.";}

快速版本

这个人是不是短(9个额外的字节),但它运行的方式来测试庞大的数字快。由于还不够短,所以我还添加了一些代码来记录实际执行时间,并在模拟时间后立即打印出来。我的原始版本在大约8分钟内完成了n = 100k。上面的版本大约需要2分钟。快速版本可以在9秒内完成。n = 1百万耗时53秒。

#include <iostream>
#include <list>
#include <string>
#include <time.h>
#define D r=rand();d=((double)r/RAND_MAX)
using namespace std;class P{int n[25];public:int S;P(int N){for(S=0;S<24;S++)n[S]=0;n[24]=N;S=1;}void C(){string s[25]={"down quark","down antiquark","up quark","up antiquark","bottom quark","bottom antiquark","tau lepton","antitau lepton","charm quark","charm antiquark","strange quark","strange antiquark","neutrino","antineutrino","muon","antimuon","gluon","photon","electron","positron","top quark","top antiquark","Z boson","W boson","Higgs boson"};int r,i,j,w,f,F,x,y;double d;S=0;F=0;for(i=20;i<25;i++){w=0;for(j=0;j<n[i];j++){D;x=-1;y=-1;if(i==24){if(d<.000433){D;if(d<.648){x=4;y=5;}else if(d<.789){x=23;y=23;}else if(d<.8772){x=16;y=16;}else if(d<.9476){x=6;y=7;}else if(d<.9803){x=8;y=9;}else if(d<.9962){x=22;y=22;}else if(d<.99843){x=17;y=17;}else if(d<.99954){x=22;y=17;}else if(d<.999784){x=14;y=16;}else{x=21;y=20;}}}else if(i==23){if(d<.5){D;if(d<.33){x=19;y=12;}else if(d<.67){x=16;y=12;}else{x=17;y=12;}}}else if(i==22){if(d<.5){D;if(d<.206){x=12;y=13;}else if(d<.24){x=18;y=19;}else if(d<.274){x=14;y=16;}else if(d<.308){x=16;y=17;}else if(d<.46){x=0;y=1;}else if(d<.612){x=10;y=11;}else if(d<.764){x=4;y=5;}else if(d<.882){x=2;y=3;}else{x=8;y=9;}}}else if(i==21||i==20){if(d<.1295){D;x=23;if(d<.33){y=0;}else if(d<.67){y=10;}else{y=4;}if(i==21)y-=32;}}if(x>=0){++n[x];++n[y];w++;}if(x>19||y>19)S=1;}n[i]-=w;if(n[i]>0&&i>19)S=1;}for(i=0;i<25;i++){if(n[i]>0)F=i;}cout<<"The universe contains";f=0;for(i=0;i<25;i++){if(n[i]>0){cout<<(f>0?(i<F?", ":" and "):" ")<<n[i]<<' '<<s[i]<<(n[i]>1?"s":"");f=1;}}cout<<'.'<<endl;}};int main(int c,char* v[]){int w=1,y=0;if(c>1){w=atoi(v[1]);}srand(time(0));rand();P p=P(w);int Time=time(0);while(p.S){p.C();y++;}cout<<"Simulation ended after "<<(double)y/10<<" yoctoseconds.";cout<<endl<<"Time Taken: "<<(time(0)-Time)<<" seconds."<<endl;}

样本输出(无参数)

The universe contains 1 Higgs boson.
... (many lines later)
The universe contains 1 Higgs boson.
The universe contains 1 bottom quark and 1 bottom antiquark.
Simulation ended after 339.4 yoctoseconds.

样本输出(universe.exe 10):

The universe contains 10 Higgs bosons.
The universe contains 1 bottom quark, 1 bottom antiquark and 9 Higgs bosons.
The universe contains 2 bottom quarks, 2 bottom antiquarks and 8 Higgs bosons.
The universe contains 3 bottom quarks, 3 bottom antiquarks and 7 Higgs bosons.
The universe contains 4 bottom quarks, 4 bottom antiquarks and 6 Higgs bosons.
The universe contains 4 bottom quarks, 4 bottom antiquarks, 1 charm quark, 1 charm antiquark and 5 Higgs bosons.
The universe contains 5 bottom quarks, 5 bottom antiquarks, 1 charm quark, 1 charm antiquark and 4 Higgs bosons.
The universe contains 5 bottom quarks, 5 bottom antiquarks, 1 charm quark, 1 charm antiquark, 2 Z bosons and 3 Higgs bosons.
The universe contains 5 bottom quarks, 5 bottom antiquarks, 1 charm quark, 1 charm antiquark, 1 neutrino, 1 antineutrino, 1 Z boson and 3 Higgs bosons.
The universe contains 5 bottom quarks, 5 bottom antiquarks, 1 charm quark, 1 charm antiquark, 2 neutrinos, 2 antineutrinos and 3 Higgs bosons.
The universe contains 6 bottom quarks, 6 bottom antiquarks, 1 charm quark, 1 charm antiquark, 2 neutrinos, 2 antineutrinos and 2 Higgs bosons.
The universe contains 7 bottom quarks, 7 bottom antiquarks, 1 charm quark, 1 charm antiquark, 2 neutrinos, 2 antineutrinos and 1 Higgs boson.
The universe contains 7 bottom quarks, 7 bottom antiquarks, 1 charm quark, 1 charm antiquark, 2 neutrinos, 2 antineutrinos and 2 W bosons.
The universe contains 7 bottom quarks, 7 bottom antiquarks, 1 charm quark, 1 charm antiquark, 2 neutrinos, 2 antineutrinos and 2 W bosons.
The universe contains 7 bottom quarks, 7 bottom antiquarks, 1 charm quark, 1 charm antiquark, 3 neutrinos, 2 antineutrinos, 1 photon and 1 W boson.
The universe contains 7 bottom quarks, 7 bottom antiquarks, 1 charm quark, 1 charm antiquark, 4 neutrinos, 2 antineutrinos, 1 gluon and 1 photon.
Simulation ended after 1160.5 yoctoseconds.

样本输出(universe.exe 1000000)

(不是10 ^ 90,但是我们到了那里)

(about a minute, 14 MB and 33000 lines of output later)
The universe contains 5006 down quarks, 4945 down antiquarks, 3858 up quarks, 3858 up antiquarks, 653289 bottom quarks, 653190 bottom antiquarks, 70388 tau leptons, 70388 antitau leptons, 36449 charm quarks, 36449 charm antiquarks, 4956 strange quarks, 4873 strange antiquarks, 289364 neutrinos, 6764 antineutrinos, 1401 muons, 275514 gluons, 99433 photons, 1065 electrons and 94219 positrons.
Simulation ended after 3299.9 yoctoseconds.

更大的输出

如果您使用的命令行控制台输出,我建议像universe.exe 100 > temp.txt这样它会快。使用Notepad ++,您可以打开temp.txt,点击ctrl+H,进入^(.*?)$\s+?^(?=.*^\1$)查找内容”字段,在“ 替换为” 字段中不输入任何内容,将“ 搜索模式”设置Regular Expression在“选择中”。匹配换行符 OFF,然后点击Replace All。现在,您只看到更改发生的位置,而不是8000行的输出(尽管我确实确实发现bug一次执行2000-3000行以上)。

修复/调整

v4 - complete overhaul, removed list, one character array, moved almost everything into the class functions. Fixed output error, was using "," instead of "and" for last item. Sped up execution a *lot* as an added bonus. :)
v3 - more fixes
v2 - more shorter
v1 - fixed numerous little issues, bug fixes
v0 - baseline

1
在您的第一个示例中,您似乎将tau lepton与上夸克混淆了。tau轻子的半衰期约为10 ^ -13秒,因此在此模拟中被认为是稳定的,否则我们将有数十亿条线直到其衰减。在我们的模拟中唯一会衰减的是玻色子和顶夸克/反夸克。
vsz 2015年

2
你能缩短char t[N]={'d','D','u','U','b','B','l','L','c','C','s','S','n','N','m','M','g','G','p','e','E','T','t','Z','W','H'char t[]="dDuUbBlLcCsSnNmMgGpeETtZWH"吗?应该可以在c中工作,不确定c ++
Digital Trauma 2015年

12

的Python 3,1,247 * 0.9 = 1,122.3

好吧,这是我长期以来最长的条目,但至少我比C ++矮。

现在增加奖金!必须使用数字作为第一个参数来调用它。

除希格斯·玻色子外,我的宇宙没有与衰变粒子一起工作,但现在可以了。另外,我没有正确的复数形式或标点符号,但实际上我现在这样做了。

我已经接近1k了!

import random,sys,numpy as h
H,M,G,N,P,K,L,n,s='photon,muon,gluon,neutrino,positron, quark,tau lepton, boson,The universe '.split(',')
c=random.choice
Z=' anti'+K[1:]
B='bottom'+K
A=B[:6]+Z
U='anti '+M
T=U[:4]+L
Q='charm'+K
C=Q[:5]+Z
S='strange'+K
R=S[:7]+Z
D='down'+K
O=D[:4]+Z
def w(c):v,t=zip(*c);t=h.array(t);return v[h.random.choice(len(v),p=t/t.sum())]
y=M,U
f=lambda p:{z:w([(c([('up'+K,'up'+Z),(Q,C)]),11.8),((N,U[:5]+N),20.6),(c([('electron',P),y,(L,T)]),3.4),(c([(S,R),(B,B),(D,O)]),15.2)]),E:(I,c([D,S,B])),F:(I,c([O,R,A])),I:c([(P,N),(U,N),(T,N)]),J:w([((B,A),64.8),((I,I),14.1),((G,G),8.82),((L,T),7.04),((Q,C),3.27),((z,z),1.59),((H,H),0.223),((z,H),0.111),(y,0.0244),((E,F),0.0246)])}[p]
z='Z'+n,50
E='top'+K,12.95
F='top'+Z,E[1]
I='W'+n,50
J='Higgs'+n,.0433
u=[J]*int(sys.argv[1])
b={z,E,F,I,J}
k=isinstance
d=lambda p:p if k(p,str)else w([(p,100-p[1]),(f(p),p[1])])
a=0
g=lambda x:[x[0],x][k(x,str)]
while b&set(u):
 n=[]
 for p in u:q=d(p);n+=([q],(q,[q])[q in b])[p in b]
 e=list(map(g,n));e=[(x,x+'s')[e.count(x)>1]for x in e];print(s+'contains %s'%', '.join(('%s %s'%(e.count(x),g(x))for x in set(e[:-1])))+('.',' and %s %s.'%(e.count(e[-1]),e[-1]))[len(set(e))>1]);a+=.1;u=n
print(s+'ended after %s yoctoseconds.'%round(a,1))

11
我认为,一个模拟宇宙的程序以开头很有趣import random。确定性就这么多。
agtoever,

这是python3对吗?我猜您可以在最终打印中使用F字符串,这可能为您节省1或2个字节:-)。
Chromium

1
@Chromium是的,我可能可以。当我编写此答案时,它们并不存在,但是我可以肯定地回去添加它们。
Morgan Thrapp

11

Perl 6(707字节-10%)得分636.3

通过一些不需要的换行符,可以提高可读性:

{
 my%p;
 %p=<H H2309.469bB64.8WW14.1gg8.82lL7.04cC3.27ZZ1.59pp0.223Zp0.111mM0.0244tT0.0216 W W3pn1Mn1Ln1 Z Z100nN20.6ep3.4mM3.4lL3.4dD15.2sS15.2bB15.2uU11.8cC11.8 t t7.722Wd1Ws1Wb1 T T7.722WD1WS1WB1>;
 my&f=*.comb[0];

 my%h;
 %h{.&f}="$_ boson" for <Higgs W Z>;
 {
  %h{.&f}="$_ quark";
  %h{.&f.uc}="$_ antiquark"
 } for <bottom top charm up down strange>;
 %h{.&f}=$_~"on" for <glu phot electr positr>;
 %h{.&f.uc}="anti"~(%h{.&f}=$_) for <muon neutrino>;
 %h<L>="anti"~(%h<l>="tau lepton");

 my$t;
 ("H"x$^a),{
   $t+=.1;
   S:g/./{%((%p{$/}||$/~1).comb(/(\D+|<:!L>+)/)).Mix.roll}/
 }...{
   say "The universe contains {
      .comb.Bag.map({
         "{.value,%h{.key}~'s'x(.value>1)}"
      }).join(', ')
   }.";
   !/<[HWZtT]>/
 };
 say "Simulation ended after $t yoctoseconds."
}

在线尝试!

The universe contains 4 Higgs bosons.
The universe contains 4 Higgs bosons.
The universe contains 4 Higgs bosons.
The universe contains 4 Higgs bosons.
The universe contains 3 Higgs bosons, 2 gluons.
The universe contains 3 Higgs bosons, 2 gluons.
The universe contains 3 Higgs bosons, 2 gluons.
The universe contains 3 Higgs bosons, 2 gluons.
The universe contains 3 Higgs bosons, 2 gluons.
The universe contains 3 Higgs bosons, 2 gluons.
The universe contains 3 Higgs bosons, 2 gluons.
The universe contains 3 Higgs bosons, 2 gluons.
The universe contains 1 tau lepton, 2 Higgs bosons, 2 gluons, 1 antitau lepton.
The universe contains 1 tau lepton, 2 Higgs bosons, 2 gluons, 1 antitau lepton.
The universe contains 1 tau lepton, 2 Higgs bosons, 2 gluons, 1 antitau lepton.
The universe contains 1 tau lepton, 2 Higgs bosons, 2 gluons, 1 antitau lepton.
The universe contains 1 tau lepton, 1 Higgs boson, 4 gluons, 1 antitau lepton.
The universe contains 1 tau lepton, 6 gluons, 1 antitau lepton.
Simulation ended after 1.7 yoctoseconds.

一些解释:神与人

有2个数据结构包含物理%p和命名%h; 神和人。物理哈希提供了一组由原始不稳定粒子字母索引的字符串,这些字符串可以拆分,哈希并转换为Mix:

say %((%p<H>).comb(/(\D+|<:!L>+)/)).Mix;
> Mix(H(2309.469), WW(14.1), ZZ(1.59), Zp(0.111), bB(64.8), cC(3.27), gg(8.82), lL(7.04), mM(0.0244), pp(0.223), tT(0.0216))

每个粒子都会得到一个字母,因此这些混合中的每一个都指定了粒子衰减的集合。H衰减为WW,概率加权为14.1。粒子-反粒子对用小写和大写字母编码,例如c和,C用于夸克和魅力反夸克。

男人思考了一下,并命名为antitau lepton

命名全部在中设置%h,它仅将每个字母映射到一个粒子名称。它打了一定程度的球,但是考虑到重复的次数,我怀疑还有改进的空间。

p => positron
g => gluon
Z => Z boson
B => bottom antiquark
e => electron
s => strange quark
d => down quark
W => W boson
m => muon
U => up antiquark
c => charm quark
H => Higgs boson
L => antitau lepton
N => antineutrino
n => neutrino
S => strange antiquark
D => down antiquark
T => top antiquark
u => up quark
t => top quark
b => bottom quark
M => antimuon
C => charm antiquark
l => tau lepton

原始字串

有了这两个结构,当然可以通过字符串操作来模拟宇宙。里面"H"只有一个希格斯玻色子的宇宙也是如此。生成器结构_,_..._用于创建循环,并将正在演化的Universe字符串(保留在中$_)的状态与打印出来分开。打印是通过将宇宙中的字母装在袋中并映射结果计数(带有复数!)来完成的。

打喷嚏成为存在

不断发展的粒子涉及将它们映射到从“混合”中为该粒子选取的值。因此t,顶夸克演化为

t=>7.722
Wd=>1
Ws=>1
Wb=>1

Perl6允许我们通过简单的地板随机选择具有给定权重的那些键之一.roll。因此,我们寻求t并说出Wb并将其代入我们的宇宙“ HtT”->“ HWbT”。每个不稳定的粒子都有可能滚动,这使我们可以简化结构,而不必检查其是否衰减。在大多数情况下,您为“ H”滚动时,只会再次获得“ H”。

实验弦理论

您可以通过此修改版观看Universe字符串的演变。

 HHH
 HHH
 HHbB
 HHbB
 HHbB
 HHbB
 HHbB
 HHbB
 lLHbB
 lLHbB
 lLHbB
 lLHbB
 lLHbB
 lLbBbB

性能

我已经在TIO上将其扩展到100 H,不可避免地,如果您想进一步走下去,最好进行一些更改,这毕竟是Grand Unified String Theory。


是什么让这个人给了这个名字,菲尔?
Manoj Kumar

1
@ManojKumar:根据维基百科:“符号τ源自希腊语τρίτον(triton,在英语中的意思是“第三”),因为它是发现的第三条带电轻子。(en.wikipedia.org/wiki/Tau_(particle)
菲尔ħ

7

Groovy,1506 1454-10%= 1309字节

假定起始希格斯玻色子粒子的数量作为命令行上的第一个参数给出:

A='anti'
B='bottom '
C='charmed '
D='downward'
E='tau '
F='top '
L='lepton'
M='muon'
N='nutrino'
O=' boson'
P='upward '
Q='quark'
T='strange '
a=[n:'gluon']
b=[n:B+Q]
c=[n:B+A+Q]
d=[n:D+Q]
e=[n:D+A+Q]
f=[n:P+Q]
g=[n:P+A+Q]
h=[n:T+Q]
i=[n:T+A+Q]
j=[n:C+Q]
k=[n:C+A+Q]
l=[n:'positron']
m=[n:'electron']
n=[n:N]
o=[n:A+N]
p=[n:'photon']
q=[n:M]
r=[n:A+M]
s=[n:E+L]
t=[n:A+E+L]
u=[n:'W'+O,c:50,s:[[c:33,p:[l,n]],[c:33,p:[l,n]],[c:33,p:[l,n]]]]
v=[n:F+Q,c:12.95,s:[[c:33,p:[u,d]],[c:33,p:[u,h]],[c:33,p:[u,b]]]]
w=[n:F+A+Q]
x=[n:'Z'+O,c:50,s:[[c:20.6,p:[n,o]],[c:3.4,p:[m,l]],[c:3.4,p:[q,r]],[c:3.4,p:[s,t]],[c:15.2,p:[d,e]],[c:15.2,p:[h,i]],[c:15.2,p:[b,c]],[c:11.8,p:[f,g]],[c:11.8,p:[j,k]]]]
y=[n:'Higgs'+O,c:0.0433,s:[[c:64.8,p:[b,c]],[c:14.1,p:[u,u]],[c:8.82,p:[a,a]],[c:7.04,p:[s,t]],[c:3.27,p:[j,k]],[c:1.59,p:[x,x]],[c:0.223,p:[p,p]],[c:0.111,p:[x,l]],[c:0.0244,p:[q,r]],[c:0.0216,p:[v,w]]]]
O={new Random().nextInt(1000001)/10000}
S={s,c->for(Map p:s){c-=p.c;if(c<=0){return p.p}};S(s,O())}
P={r=[];it.collect{it.n}.groupBy{it}.each{k,v->c=v.count{it};r<<"${c} ${c>1?k+'s':k}"};r.join(', ').reverse().replaceFirst(',', 'dna ').reverse()}
U=[]
args[0].times{U<=O()){I.remove();S(J.s,O()).each{I.add(it)}}}
if(!Z){println "Simulation ended after $Y yoctoseconds.";break}}


1454的10%是145.4
geokavel 2015年

有了这样的数学,模拟就完全可以了:-)感谢您指出这一点!
K. Klassen,2015年

7

PHP,989-10%= 890.1字节

子1K宝贝!感谢vsz,这是一个非常有趣的挑战。有很多解决方法,很难验证您的输出是否正确。

该程序可以使用命令行参数来指定希格斯玻色子的起始数目,例如 php universe_simulator.php 5

<?eval(gzinflate(base64_decode('bVNdb9Q6EH3nV4TVSEm0ozRpt/uBcRGlQLlw4QIFWqxQuYm7mza1s4mzdEH73+84WUqFyINzjn1mfMaaAcmltgWDC35hrDU3DDKeLWRN4JC2GqMZLPmylfU1g4Y3tpZ6rhhY7lvZeqWqrNE+A821am1daMMuTa1ktgjUbVWaXAU++jiAn3Jz0xqNIKFbLMKFR/9l96c127LMsdx81z3v0RJVqTJbU4J56dIcF/N548Eh9kk1VgtDTrAyTdHJoNnma7rsFq2p+p0OLLHd0rZjX1yur7QMQtnAKoRKZIs6GA6hGI5HYcphxSDn4g0/EFEcx6O9PRQiGo+mKI7weZqiiCbTGYpTPO3IdDLZRfEaX3dsNpqMUTzDjz2bxhT9Al/2bDYm5Rmebdl0RIfv8N2WzvZHjv46nU2mxJ/iv44nKE7wU0ofnjpj++Qp2aHwt/ifO991+Cm+3WqfOUT47Jc22o3J1mEviPb2qZhjfNWRfdK/xw8dHjuDv6tE8Rm/9EXOpvfq2CPVP/3F0Ww8vu+yq5zwJ3dzsju7M/qqf67O6Icek/y5Q4RP/pQf35O/v5Mf9fKUQctlXcv1+WVRlkFMfVbPVyJJnzxK8E3IYM1j9n1RlCp4CLfhT7jlCYMrLtK7pu3DM9Nqe76SZauaAFrXEtf8wLXFlUj5AFYe9Qdcp4MogNVB8sRv/Ee+HzKVLYxX1Wp+XquqlBk1/w4G4humwxB2aBA8qXNIaB5OFsprdbFSdaO8zGgrC914g+jKFJomxvMRrsJoED0YhHfeoPXISEFGbFhcBpALsGlXRcyI02TmQbgzV25G8xt5G4SPeS8SsdP94H+R/M7eK5OU7si6/D8oPOtC+1ep2saZwCiKaD9JQ3ZBodds0+pGWToRUNDmZgPrIY8StnHPMfhY3LSltIXRntK5yj15aVXtwdpbm8yaRlH1eUOFsv8B')));

这是换行符的原因,嗯...“可读性” ...

<?eval(gzinflate(base64_decode('bVNdb9Q6EH3nV4TVSEm0ozRpt/uBcRGlQLlw4QIFWqxQuYm7
mza1s4mzdEH73+84WUqFyINzjn1mfMaaAcmltgWDC35hrDU3DDKeLWRN4JC2GqMZLPmylfU1g4Y3tpZ6
rhhY7lvZeqWqrNE+A821am1daMMuTa1ktgjUbVWaXAU++jiAn3Jz0xqNIKFbLMKFR/9l96c127LMsdx8
1z3v0RJVqTJbU4J56dIcF/N548Eh9kk1VgtDTrAyTdHJoNnma7rsFq2p+p0OLLHd0rZjX1yur7QMQtnA
KoRKZIs6GA6hGI5HYcphxSDn4g0/EFEcx6O9PRQiGo+mKI7weZqiiCbTGYpTPO3IdDLZRfEaX3dsNpqM
UTzDjz2bxhT9Al/2bDYm5Rmebdl0RIfv8N2WzvZHjv46nU2mxJ/iv44nKE7wU0ofnjpj++Qp2aHwt/if
O991+Cm+3WqfOUT47Jc22o3J1mEviPb2qZhjfNWRfdK/xw8dHjuDv6tE8Rm/9EXOpvfq2CPVP/3F0Ww8
vu+yq5zwJ3dzsju7M/qqf67O6Icek/y5Q4RP/pQf35O/v5Mf9fKUQctlXcv1+WVRlkFMfVbPVyJJnzxK
8E3IYM1j9n1RlCp4CLfhT7jlCYMrLtK7pu3DM9Nqe76SZauaAFrXEtf8wLXFlUj5AFYe9Qdcp4MogNVB
8sRv/Ee+HzKVLYxX1Wp+XquqlBk1/w4G4humwxB2aBA8qXNIaB5OFsprdbFSdaO8zGgrC914g+jKFJom
xvMRrsJoED0YhHfeoPXISEFGbFhcBpALsGlXRcyI02TmQbgzV25G8xt5G4SPeS8SsdP94H+R/M7eK5OU
7si6/D8oPOtC+1ep2saZwCiKaD9JQ3ZBodds0+pGWToRUNDmZgPrIY8StnHPMfhY3LSltIXRntK5yj15
aVXtwdpbm8yaRlH1eUOFsv8B')));

一些输出:

The universe contains 2 Higgs bosons.
[...]
The universe contains 1 Higgs boson, 2 neutrinos, 1 positron and 1 antimuon.
The universe contains 1 Higgs boson, 2 neutrinos, 1 positron and 1 antimuon.
The universe contains 1 Higgs boson, 2 neutrinos, 1 positron and 1 antimuon.
The universe contains 1 Higgs boson, 2 neutrinos, 1 positron and 1 antimuon.
The universe contains 1 Higgs boson, 2 neutrinos, 1 positron and 1 antimuon.
The universe contains 2 neutrinos, 1 positron, 1 antimuon, 1 bottom antiquark and 1 bottom quark.
Simulation ended after 153.2 yoctoseconds.

5
您还可以将未压缩的版本添加到答案中吗?

是“可读性!” 解压缩的版本?
Manoj Kumar

7

QBasic 2161 * .9 = 1945 2028 * .9 = 1825 1854 * .9 = 1669字节

既然QBasic是LOTM,我想我将永远修改关于PPCG的第一个答案。设法敲掉140个字节,还不错!

根据@TaylorScott和@DLosc的反馈,我进行了完整的重新设计:

  • 计时改变
  • 现在格式化符合规范
  • 通过将数组变成索引字符串节省了很多字节

编码

SUB f(p$,c)
DIM e$(25)
q$=" quark
a$=" antiquark
e$(1)="HHiggs boson
e$(2)="bbottom"+q$
e$(3)="1bottom"+a$
e$(4)="WW boson
e$(5)="gGluon
e$(6)="TTau lepton
e$(7)="2Tau antilepton
e$(8)="ccharm"+q$
e$(9)="3charm"+a$
e$(10)="ZZ boson
e$(11)="pphoton
e$(12)="mmuon
e$(13)="4antimuon
e$(14)="0top"+q$
e$(15)="5top"+a$
e$(16)="+positron
e$(17)="nneutrino
e$(18)="6antineutrino
e$(19)="-electron
e$(20)="ddown"+q$
e$(21)="7down"+a$
e$(22)="sstrange"+q$
e$(23)="8strange"+a$
e$(24)="uup"+q$
e$(25)="9up"+a$
FOR i=1TO 25
IF LEFT$(e$(i),1)=p$THEN ?str$(c)" "MID$(e$(i),2);
NEXT
IF c>1THEN?"s";
END SUB
RANDOMIZE TIMER
z=100
INPUT x
p$=string$(x,"H")
1:b=0
REDIM m$(LEN(p$))
FOR i=1TO LEN(p$)
m$(i)=MID$(p$,i,1)
NEXT
p$=s$(m$())
t=t+1
?"The universe contains";
FOR i=1TO LEN(p$)
y$=MID$(p$,i,1)
z$=MID$(p$,i+1,1)
c=c+1
IF(y$=z$ AND i<LEN(p$))=0THEN f y$,c:c=0
NEXT
?
r$="
FOR i=1TO LEN(p$)
d&=(RND*z)*z
e&=(RND*z)*(z^2)
q$=MID$(p$,i,1)
IF INSTR("HWZ02",q$) THEN b=1
r$=r$+g$(d&,e&,q$)
NEXT
p$=r$
IF b GOTO 1
?"Simulation ended after"t/10"yoctoseconds.
FUNCTION g$(d&,p&,q$)
DIM e$(28)
FOR i=1TO 28
x$=Mid$("H00433099979405H004330999550m4H004330998440ZpH004330996210ppH004330980310ZZH004330947610c3H004330877210T2H004330789010ggH004330648010WWH004330000000b12012950666670W12012950333340W82012950000000W70012950666670Wb0012950333340Ws0012950000000WdW0500006666702nW0500003333404nW050000000000+nZ050000882010c3Z050000764010u9Z050000612010b1Z050000460010s8Z050000308010d7Z050000274010T2Z050000240010m4Z050000206010-+Z050000000000n6",15*i+1,15)
a&=VAL(MID$(x$,8,7))
g$=q$
IF LEFT$(x$,1)=q$ THEN
IF d&<VAL(MID$(x$,2,5)) THEN
IF(p&>a& OR a&=0) THEN
g$=RIGHT$(x$,2)
EXIT FUNCTION
ENDIF
ENDIF
ENDIF
NEXT
END FUNCTION
FUNCTION s$(n$())
x=UBOUND(n$)
FOR i=1TO x:FOR J=1TO x
IF n$(i)<n$(J)THEN SWAP n$(i),n$(J)
NEXT j,i
FOR i=1TO UBOUND(n$)
a$=a$+n$(i)
NEXT
s$=a$
END FUNCTION

样品输出

? 3
The universe contains 3 Higgs bosons
The universe contains 3 Higgs bosons
The universe contains 3 Higgs bosons
The universe contains 3 Higgs bosons
The universe contains 1 bottom antiquark 2 Higgs bosons 1 bottom quark
The universe contains 1 bottom antiquark 2 Higgs bosons 1 bottom quark
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 2 bottom antiquarks 1 Higgs boson 2 bottom quarks
The universe contains 3 bottom antiquarks 3 bottom quarks
Simulation ended after 2.3 yoctoseconds.

是的,后来打了几年高尔夫球……但是输出格式与问题中的严格要求不符。??
DLosc '18年

1
对于-〜200字节,请在数组函数中使用For i=0To 28 x$=Mid$("H00433099979405H004330999550m4H004330998440ZpH004330996210ppH004330980310ZZH004330947610c3H004330877210T2H004330789010ggH004330648010WWH004330000000b12012950666670W12012950333340W82012950000000W70012950666670Wb0012950333340Ws0012950000000WdW0500006666702nW0500003333404nW050000000000+nZ050000882010c3Z050000764010u9Z050000612010b1Z050000460010s8Z050000308010d7Z050000274010T2Z050000240010m4Z050000206010-+Z050000000000n6",15*i+1,15)...- Nextf$()e$()
泰勒·斯科特

在function中s$()Next:Next可以为Next j,i,并且应该检查?语句是否需要所有这些;。但是,这也似乎是你的输出目前不符合规范
泰勒·斯科特

@DLosc和Taylor我将在下周末查看您的两个建议;在那之前我有点忙...谢谢。
steenbergh

6

C#6,3619 3617 3611 3586 - 10(%)= 3227.4字节

程序使用两个可选参数作为起始希格斯玻色子的数量和用于Random类的种子。

using System;using System.Collections.Generic;class a{List<P>L;List<Q>S;double Y;static void Main(string[]a){a b;b=a.Length<1?new a():a.Length<2?new a(int.Parse(a[0])):new a(int.Parse(a[0]),int.Parse(a[1]));}a(int j=1,int e=1){Random r=new Random(e);L=new List<P>();S=new List<Q>();for(int i=0;i<j;i++)L.Add(new H());while(L.Count>0){List<P>l=new List<P>();foreach(P p in L){List<P>d=p.C(r);if(d!=null)foreach(P y in d){if(y.GetType()==typeof(Q))S.Add((Q)y);else l.Add((P)y);}else l.Add(p);}L=l;Y+=.1;W();}var s=$"Simulation ended after {Y} yoctosecond";if(Y!=1d)s+="s";Console.WriteLine(s+".");}void W(){var t="";Dictionary<string,int>N=new Dictionary<string,int>();int M=0;foreach(P x in L){t=x+"";if(N.ContainsKey(t))N[t]++;else{N.Add(t,1);M++;}}foreach(Q x in S){t=x+"";if(N.ContainsKey(t))N[t]++;else{N.Add(t,1);M++;}}var o="The universe contains ";int i=N.Keys.Count;foreach(var x in N.Keys){i--;if(M==1){o+=$"{N[x]} {x}";if(N[x]!=1)o+="s";}else if(M==2){o+=$"{N[x]} {x}";if(N[x]!=1)o+="s";if(i!=0)o+=" and ";}else{if(i<1){o+=$"and {N[x]} {x}";if(N[x]!=1)o+="s";}else{o+=$"{N[x]} {x}";if(N[x]!=1)o+="s";o+=", ";}}}Console.WriteLine(o+".");}}abstract class P{public static string[]Z=new string[]{"photon","gluon","positron","electron","quark","lepton","muon","neutrino"};public double l;public abstract List<P>D(Random r);public List<P>C(Random r){List<P>d=null;if(r.NextDouble()<l)d=D(r);return d;}}class H:P{public H(){l=.000433;}public override List<P>D(Random r){var d=new List<P>();Action<P>U=d.Add;var n=r.NextDouble();if(n<.648){U(new Q("bottom "+Z[4]));U(new Q("bottom anti"+Z[4]));}else if(n<.789){U(new W());U(new W());}else if(n<.8772){U(new Q(Z[1]));U(new Q(Z[1]));}else if(n<.9476){U(new Q("tau "+Z[5]));U(new Q("antitau "+Z[5]));}else if(n<.9803){U(new Q("charm "+Z[4]));U(new Q("charm anti"+Z[4]));}else if(n<.9962){U(new Z());U(new Z());}else if(n<.99843){U(new Q(Z[0]));U(new Q(Z[0]));}else if(n<.99954){U(new Z());U(new Q(Z[0]));}else if(n<.999784){U(new Q(Z[6]));U(new Q("anti"+Z[6]));}else{U(new T(0>1));U(new T(1>0));}return d;}public override string ToString(){return"Higgs Boson";}}class W:P{public W(){l=.5;}public override List<P> D(Random r){var d=new List<P>();var n=r.NextDouble();d.Add(new Q(Z[7]));if(n<1/3d)d.Add(new Q(Z[2]));else if(n<2/3d)d.Add(new Q("anti"+Z[6]));else d.Add(new Q("antitau "+Z[5]));return d;}public override string ToString(){return"W Boson";}}class Z:P{public Z(){l=.5;}public override List<P>D(Random r){var d=new List<P>();var n=r.NextDouble();Action<P>U=d.Add;var t=Z[4];if(n<.206){U(new Q(Z[7]));U(new Q("anti"+Z[7]));}else if(n<.24){U(new Q(Z[3]));U(new Q(Z[2]));}else if(n<.274){U(new Q(Z[6]));U(new Q("anti"+Z[6]));}else if(n<.308){U(new Q("tau "+Z[5]));U(new Q("antitau "+Z[5]));}else if(n<.46){U(new Q("down "+t));U(new Q("down anti"+t));}else if(n<.612){U(new Q("strange "+t));U(new Q("strange anti"+t));}else if(n<.764){U(new Q("bottom "+t));U(new Q("bottom anti"+t));}else if(n<.882){U(new Q("up "+t));U(new Q("up anti"+t));}else{U(new Q("charm "+t));U(new Q("charm anti"+t));}return d;}public override string ToString(){return"Z Boson";}}class T:P{bool A;public T(bool a){A=a;l=.1295;}public override List<P>D(Random r){var d=new List<P>();var n=r.NextDouble();d.Add(new W());if(n<1/3d)d.Add(new Q("down "+Z[4]));else if(n <2/3.0)d.Add(new Q("strange "+Z[4]));else d.Add(new Q("bottom "+Z[4]));return d;}public override string ToString(){var r=A?"top anti":"top ";return r+Z[4];}}class Q:P{string N;public Q(string n){N=n;}public override List<P>D(Random r){return null;}public override string ToString(){return N;}}

我不应该为此使用对象,我可能会尝试使用数组来做第二个解决方案,但是它可能类似于已经发布的C ++解决方案。我可以处理的希格斯玻色子的数量也受到严格限制,我认为H = 1,000,000至少需要一个小时。不过,较小的数字运行得很好。

样本输出:

$ b
// Default h=1,seed=1
The universe contains 1 Higgs Boson.
...
The universe contains 1 bottom quark and 1 bottom antiquark.
Simulation ended after 65.5000000000006 yoctosecond.

$ b 10 12345
The universe contains 10 Higgs Bosons.
The universe contains 9 Higgs Bosons, 1 bottom quark, and 1 bottom antiquark.
The universe contains 8 Higgs Bosons, 2 W Bosons, 1 bottom quark, and 1 bottom antiquark.
The universe contains 8 Higgs Bosons, 1 bottom quark, 1 bottom antiquark, 2 neutrinos, and 2 antitau leptons.
The universe contains 7 Higgs Bosons, 2 bottom quarks, 2 bottom antiquarks, 2 neutrinos, and 2 antitau leptons.
The universe contains 6 Higgs Bosons, 3 bottom quarks, 3 bottom antiquarks, 2 neutrinos, and 2 antitau leptons.
The universe contains 5 Higgs Bosons, 4 bottom quarks, 4 bottom antiquarks, 2 neutrinos, and 2 antitau leptons.
The universe contains 2 W Bosons, 4 Higgs Bosons, 4 bottom quarks, 4 bottom antiquarks, 2 neutrinos, and 2 antitau leptons.
The universe contains 1 W Boson, 4 Higgs Bosons, 4 bottom quarks, 4 bottom antiquarks, 3 neutrinos, 2 antitau leptons, and 1 antimuon.
The universe contains 4 Higgs Bosons, 4 bottom quarks, 4 bottom antiquarks, 4 neutrinos, 2 antitau leptons, and 2 antimuons.
The universe contains 3 Higgs Bosons, 5 bottom quarks, 5 bottom antiquarks, 4 neutrinos, 2 antitau leptons, and 2 antimuons.
The universe contains 2 Higgs Bosons, 6 bottom quarks, 6 bottom antiquarks, 4 neutrinos, 2 antitau leptons, and 2 antimuons.
The universe contains 1 Higgs Boson, 2 W Bosons, 6 bottom quarks, 6 bottom antiquarks, 4 neutrinos, 2 antitau leptons, and 2 antimuons.
The universe contains 1 Higgs Boson, 1 W Boson, 6 bottom quarks, 6 bottom antiquarks, 5 neutrinos, 2 antitau leptons, and 3 antimuons.
The universe contains 1 Higgs Boson, 6 bottom quarks, 6 bottom antiquarks, 6 neutrinos, 2 antitau leptons, 3 antimuons, and 1 positron.
The universe contains 7 bottom quarks, 7 bottom antiquarks, 6 neutrinos, 2 antitau leptons, 3 antimuons, and 1 positron.
Simulation ended after 540.500000000054 yoctoseconds.

我将在h = 1000000运行结束时(可能在今天晚些时候)发布最后两行。按照承诺:

$ b 1000000
(a few hours, 35K lines, and 15MB later)
The universe contains 653391 bottom quarks, 653271 bottom antiquarks, 36336 charm quarks, 36336 charm antiquarks, 176724 gluons, 71397 tau leptons, 165604 antitau leptons, 5626 photons, 288869 neutrinos, 95047 positrons, 95556 antimuons, 5254 strange quarks, 5130 strange antiquarks, 1389 muons, 1081 electrons, 5240 down quarks, 5104 down antiquarks, 6529 antineutrinos, 3862 up quarks, and 3862 up antiquarks.
Simulation ended after 3599.29999999782 yoctoseconds.

快速浏览一下,在处有一个无用的空格,在处有else {U(new T(0>1))多个n < 2 / 3.0,而在处有一个n <2/3.0
Yytsi

@TuukkaX谢谢,错过了那些。通过用3d替换3.0来节省了另一个字节,必须在更改第一个字节后添加该行。
Yodle

一个在if (a.Length另一个在if (N[x]!=1第三个在o+= $。另外,a[0]当结果可以保存为整数时,您将两次解析为整数。我认为Y==1.0可以Y==1.,但是我不确定。i!=0可能是i。我不知道您的变量是否实际上可以取反,但是如果不能,则可以将替换==0<1。标题应为C#6,因为您使用的是字符串插值。
Yytsi

@TuukkaX不幸的是,除非我做错事,否则C#不允许if(整数)。而且我以不同的方式缩短了Main方法,但我认为如果没有任何参数,无论如何都无法预先将a [0]分配给整数(默认值是使用h = 1和seed = 1运行) 。谢谢其他一切!
2016年

5

Mathematica,950bytes-10%= 855字节

使用表达式压缩:

ToExpression[Uncompress["1:eJxdVG1v2jAQ7of9kMyVpna9pkkKLV0aROlW2AQVb1MqPGsKYCBaYtPEjFLgf+zn7vKGaD/kse/J+fz4zuePI9nr//twdOQ5ZTt0DHvkDLxRwGkTPGZHTs8TExnez6U/5nYvN3vcC+zAaXExU3P7l2Faz7T7m31xiEZuqwPZV5EvZrRLqcUYu62mdH/lq/E8IU3GoAmk6c9msVaXsRQEXoHUpVIy1LpLL/pDYLgn7oTynzPSBeIWKxpAGsEymQ1aQAbeUmvxhUrs3EzWBTk1BXI/96J99IfCPgiOOw6L4AsgnbnEpTGBNpB2us8aSOIepsYLbiIXRbynzDqI1sEIMvZVlDgLII98mWRFEhhnYcSe4EC+BXycua6AYPo8MePvDl6w+Y6o6qtciUMnmVO5xx2Qn28k1VMi+8uSqrlzTBBt83DEoy4dQXPrbofbl+0Tg/DsDK/CQ+ApxQU9yYt3jHX7PqU9ym4N3YSIbvSrUgV0s2SCXqlYoBvXRgnx0rpGNMs3iIZlXSaDaZrJYFilUjaaV7vz6mbzCsMdbFxwERvQQMSCtnCYwgPiMP29gEU67yC2YY34Ak+7HV4khsnZayonmjYdEOiwTrGFiG4uw/q+dTN0y7gCA8WW3qFZtt6jWckwVSxgjJH5gZhcsYQ24gpWiNmx6nCXnwRFDBmcYHZPD3Jo3WSSXZBpElYpvqI3g99wnJbp9NNFbcTs2Hm+qJ08yij0gtq9XAoV0xG70HvLgJ9XW36sTu0O3ihFyWDOtaXw//Io5tpYCuX5eJOxB9PG/CF9QYvSDvBWxQsZc7rJGh+1BbXYcXwoZiYQAkTD1icsIf2CAoIqNz6YgH54PvzSdtcJs1PluZw+9gxu50uhcTHhE82bKh69eSswFZ/D9KlYy7FCOah6EmOg/5kZdRM="]]

未压缩的代码(1168字节-10%= 1051.2字节):

a=5;m=0;b=Table[H,a];r=RandomChoice;R=RandomReal;l=Length;
q[Q_]:=" "<>ToString[Q[[2]]]<>" "<>Switch[Q[[1]],H,"Higgs Boson",z,"Bottom Quark",Z,"Bottom Antiquark",W,"W Boson",G,"Gluon",TL,"Tau Lepton",L,"Tau Antilepton",f,"Charm Quark",F,"Charm Antiquark",Z,"Z Boson",p,"Photons",M,"Muon",y,"Antimuon",x,"Top Quark",X,"Top Antiquark",P,"Positron",n,"Neutrino",c,"Antineutrino",e,"Electron",w,"Strange Antiquark",W,"Strange Quark",M,"Down Antiquark",o,"Down Quark",A,"Up Antiquark",B,"Up Quark"]
While[MemberQ[b,H|W|Z|x|X],m++;b=Flatten[(Switch[#,H,If[R[]<0.1,r[{.648,.141,.882,.0704,.0327,.0159,.00223,.00111,.000244,.000216}->{{z,Z},{W,W},{G,G},{TL,L},{f,F},{Z,Z},{p,p},{Z,P},{M,y},{x,X}}],H],W,If[R[]<0.5,r[{{P,n},{y,n},{L,n}}],W],Z,If[R[]<0.5,r[{0.206,0.034,0.034,0.034,0.152,0.152,0.152,0.118,0.118}->{{n,c},{e,P},{M,y},{TL,L},{o,M},{w,w},{z,Z},{B,A},{f,F}}],Z],(x|X),If[R[]<0.1295,r[{{W,o},{W,w},{W,z}}]],_,#]
)&/@b];s=q/@(Normal@Counts[b]/.Rule->List);Print["The universe contains"<>StringJoin[Flatten[Transpose[{Table[If[l@s==i,If[l@s==1,""," and"],If[i==1,"",","]],{i,1,l@s}],s}]]]<>"."];]
Print["Simulation ended after "<>ToString[0.1*m]<>" yoctoseconds."]

可以通过更改a的值来选择startparameter。

我注意到我为希格斯玻色子使用了错误的概率,但目前无法更改它(在几个小时左右的时间内)。因此,将3个或4个字节添加到当前解决方案中。(这是一个测试值)


3
在将近一年的时间里,以前的最好成绩一直保持着,并且您在我的十个小时后发布了您的最好成绩!天哪,老兄。:)
Alex Howansky

2
由于您遇到了挑战,我也必须这样做。对不起。:D
朱利安·克鲁格

5

Perl中,973个 986 959 944字节-10%= 849.6点

缩进和换行符不是代码的一部分,它们仅提供,因此您无需滚动30年就可以阅读全部内容。

有几个0字节的优化我从未想过要撤消。

%p=(H,Higgs.($o=$".Boson),W,W.$o,Z,Z.$o,B,Bottom.($Q=$".Quark),b,Bottom.($q=$".Antiquark),G,Gluon,A,Tau.($t=$".Lepton),a,Antitau.$t,P,Photon,M,Muon,w,Antimuon,T,Top.$Q,t,Top.$q,e,Positron,N,Neutrino,n,Antineutrino,E,Electron,D,Down.$Q,d,Down.$q,S,Strange.$Q,z,Strange.$q,U,Up.$Q,u,Up.$q,C,Charm.$Q,c,Charm.$q);
%d=(H,[433e-6,.648,Bb,.141,WW,.0882,GG,.0704,Aa,.0327,Cc,.0159,ZZ,.00223,PP,.00111,ZP,244e-6,Mw,216e-6,Tt],W,[.5,$x=1/3,eN,$x,wN,$x,tN],Z,[.5,.206,Nn,.034,Ee,.034,Mw,.034,Aa,.152,Dd,.152,Sz,.152,Bb,.152,Uu,.118,Uu,.118,Cc],T,[.1295,$x,WD,$x,WS,$x,WB],t,[.1295,$x,Wd,$x,Wz,$x,Wb]);
for(@a=(H)x<>;grep/[HWZTt]/,@a;$z++){
    for$m(@a){
        @b=(@b,$m),next if$d{$m}[0]<rand;
        $e=rand;
        ($e-=$d{$m}[($_*=2)+1])>0||($e=2,@b=(@b,split//,$d{$m}[$_+2]))for 0..9
    }
    (@a,@b,%u,$w)=@b;
    $u{$_}++for@a;
    $w.=" $u{$_} $p{$_}".($u{$_}>1?'s,':',')for keys%u;
    say"The universe contains",$w=~s/.$/./r=~s/,([^,]+)$/ and$1/r
}
$z/=10;say"Simulation ended after $z yoctoseconds."

显然,大部分代码都在创建初始哈希。 %p利用Perl的裸字功能,包含所有粒子的名称。 %r确定衰减率。如果这里没有显示它,那么它根本不会衰减。 %d包含衰减粒子。

由于输出中粒子的顺序无关紧要,因此我不必从Perl访问哈希中的键的随机方式更改它,这将导致如下所示:

[snip]
The universe contains 1 Higgs Boson.
The universe contains 1 Higgs Boson.
The universe contains 2 W Bosons.
The universe contains 2 Neutrinos, 1 Positron and 1 Top Antiquark.
The universe contains 1 Top Antiquark, 1 Positron and 2 Neutrinos.
The universe contains 1 Top Antiquark, 1 Positron and 2 Neutrinos.
The universe contains 1 Top Antiquark, 1 Positron and 2 Neutrinos.
The universe contains 2 Neutrinos, 1 Positron and 1 Top Antiquark.
The universe contains 1 Positron, 1 Top Antiquark and 2 Neutrinos.
The universe contains 2 Neutrinos, 1 Top Antiquark and 1 Positron.
The universe contains 1 Positron, 1 Strange Antiquark, 2 Neutrinos, 1 Bottom Antiquark and 2 W Bosons.
The universe contains 1 W Boson, 1 Bottom Antiquark, 2 Neutrinos, 1 Positron and 1 Strange Antiquark.
The universe contains 2 Neutrinos, 1 Bottom Antiquark, 1 W Boson, 1 Strange Antiquark and 1 Positron.
The universe contains 1 W Boson, 1 Bottom Antiquark, 2 Neutrinos, 1 Strange Antiquark and 1 Positron.
The universe contains 1 Bottom Antiquark, 4 Neutrinos, 1 Antimuon, 2 Positrons and 1 Strange Antiquark.

这确实是一次令人振奋的冒险。老实说,我玩得很开心!:)


5

Python的3.6.1,1183 1157 ... 905 889 * 0.9 = 800.1字节

第一次提交其中一个,但是这个挑战看起来很有趣,所以我们开始...

几乎可以肯定没有打高尔夫球,但是我对此没有经验,所以欢迎您提出任何建议。

from random import*
w,z='WZ';b,q,v=' boson',' .quark',[1]*3;p,n,u,t={'H':[433e-6,['Bb',w*2,'GG','Xx','Cc',z*2,'PP','ZP','Mm','Tt'],[6480,1410,882,704,32.7,15.9,2.23,1.11,.244,.216]],w:[.5,['FN','mN','xN'],v],z:[.5,['Nn','EF','Mm','Xx','Dd','Ss','Bb','Uu','Cc'],[2060]+[340]*3+[152]*3+[118]*2],'T':[.1295,['WD','WS','WB'],v]},{'H':'Higgs'+b,'B':'bottom'+q,w:w+b,'G':'gluon','X':'.tau lepton','C':'charm'+q,z:z+b,'P':'photon','M':'.muon','T':'top'+q,'E':'electron','F':'positron','N':'.neutrino','D':'down'+q,'S':'strange'+q,'U':'up'+q},['H']*int(input()),0
while{*u}&{*p}:
    for x in[*u]:
        if x in p and random()<p[x][0]:u.remove(x);u+=choices(*p[x][1:])[0]
    print("The universe contains %s."%' and'.join((', '.join(str(u.count(x))+' '+n[x.upper()].replace('.',(x>x.upper())*'anti')+(1<u.count(x))*'s'for x in{*u})).rsplit(',',1)));t+=.1
print('Simulation ended after %.1f yoctoseconds.'%t)

在线尝试!

编辑:为了简洁起见,下面列出了我所做的一些编辑(感谢评论员的帮助!):

  • 通过Cat向导(用分号代替换行符)和其他Python答案(节省了几个定义字符串的字节),节省了25个字节。
  • 想出了一些方法来节省另外107(!)字节,大多数只是更好地排列了字典,它不再是一个功能。
  • 实现的random.choices()是加权概率,而不是百分比,因此我可以节省一些字节,而不必将事情累加十到28字节!希格斯衰减概率是错误的-我读0.43%,而不是0.043%,所以花费了两个字节。
  • 从各种花哨的技巧中又保存了28个字节-设置交集any()+=而不是,而不是list.extend()和不同的import语句。
  • 将嵌套的dict交换为list的dict,用于choices(*p[x][1:])保存一对并x and y or z避免if...else...or
  • LBYL的分配稍好一些,但效果更好,可以enumerate()通过复制Universe并list.remove()在原始模型上使用来代替(enumerate无论如何,该方法都会被破坏)。
  • 修复了一些愚蠢的事情,更好的print()陈述和合并的if陈述。删除了一些不需要的括号。

更具可读性的版本:

from random import *
w,z='WZ'
b,q,v=' boson',' .quark',[1]*3
        # Decayable particle products/probabilities
p,n,u,t={'H':[433e-6,['Bb',w*2,'GG','Xx','Cc',z*2,'PP','ZP','Mm','Tt'],[6480,1410,882,704,32.7,15.9,2.23,1.11,.244,.216]],
            w:[.5,['FN','mN','xN'],v],z:[.5,['Nn','EF','Mm','Xx','Dd','Ss','Bb','Uu','Cc'],[2060]+[340]*3+[152]*3+[118]*2],
            'T':[.1295,['WD','WS','WB'],v]},
        # Particle names
        {'H':'Higgs'+b,'B':'bottom'+q,w:w+b,'G':'gluon','X':'.tau lepton','C':'charm'+q,z:z+b,
            'P':'photon','M':'.muon','T':'top'+q,'E':'electron','F':'positron','N':'.neutrino',
            'D':'down'+q,'S':'strange'+q,'U':'up'+q},
        # Universe
        ['H']*int(input()),
        # Time taken
        0
while {*u} & {*p}: # While any particles can still decay
    for x in[*u]: # Iterate through them
        if x in p and random()<p[x][0]: # Check if they should decay
            u.remove(x) # If they should, remove them
            u+=choices(*p[x][1:])[0] # And add in the products
    # Join particle names with their counts together, separated by ',', add 'anti' where
    # needed, add 's' where needed, replace last ',' with 'and', then print.
    a = ' and'.join((', '.join(str(u.count(x))
                    + ' '
                    + n[x.upper()].replace('.',(x>x.upper())*'anti')
                    + (1<u.count(x))*'s' for x in {*u})).rsplit(',',1))
    print("The universe contains %s." % a)
    t+=.1
print('Simulation ended after %.1f yoctoseconds.'%t)

具有5000希格斯玻色子的样本输出-稍后可能会进行更大的运行,以查看是否有任何顶部夸克衰减使其进入:

The universe contains 1 up antiquark, 23 charm quarks, 1 electron, 23 charm antiquarks, 371 tau leptons, 1542 neutrinos, 500 antimuons, 16 antineutrinos, 505 positrons, 4 muons, 3 photons, 3373 bottom quarks, 3373 bottom antiquarks, 1 up quark, 916 gluons and 897 antitau leptons.
Simulation ended after 2410.5 yoctoseconds.

如果我做错了什么,请告诉我,我会尽力解决!


4

Ruby,997995字节-10%= 895.5分

编辑:添加“和”作为面包箱注意到的最后一个分隔符

第一次在PPCG上发帖,这是一个古老的挑战,但是我做这件事很有趣。这是代码

s=%w(boson quark top bottom anti tau lepton charm muon neutrino down strange up)
t="Higgs 0;Z 0;W 0;2 1;2 41;3 1;3 41;gluon;5 6;45 6;7 1;7 41;photon;8;48;positron;9;49;electron;#a 1;#a 41;#b 1;#b 41;#c 1;#c 41"
h=[4.33e-2,50,50,12.95]
d=[[64.8,14.1,8.82,7.04,3.27,1.59,0.223,0.111,0.0244,0.0216],[20.6,*[3.4]*3,*[15.2]*3,*[11.8]*2],*[[33.3]*3]*3]
r=["fgcchhijklbbmmbmnode","qrspnoijtuvwfgxykl","pqoqjq","ctcvcf","ctcvcf"]
r=r.map{|a|a.chars.map{|e|e.ord-97}}
s.size.times{|i|c=i>9?"#"+(i+87).chr: i.to_s;t=t.gsub(c,s[i])}
t=t.split(';')
z=Random.new
p=[0]*25
p[0]=gets.to_i
o=0
f=->p{puts"The universe contains "+(*a,b=(0..24).map{|i|e=p[i];e>0?"#{e} "+t[i]+(e>1?"s":""):nil}.compact;a*", "+(a.size>0?" and ":"")+b)+"."}
while p[0..4].sum>0 do
    f[p]
    q=p.clone
    (0..4).map{|i|p[i].times{|j|a=z.rand(100.0);a<h[i]?(q[i]-=1;a=z.rand(100.0);d[i].size.times{|k|a<d[i][k]?(q[r[i][k]]+=1;q[r[i][k+1]]+=1):a-=d[i][k]}):0}}
    p=q.clone
    o+=1
end
f[p]
puts "Simulation ended after #{o/10.0} yoctoseconds."

字符串通过分解重复出现的单词(vars st)进行压缩。衰减的结果紧凑地存储为字符串(var r),每个字母都是一个粒子。函数f通过将粒子数组映射到字符串来打印Universe的状态。我觉得状态更新行中有一些字节需要切断,但是我找不到更好的方法。

样本输出

[snip]
The universe contains 1 Higgs boson.
The universe contains 1 Higgs boson.
The universe contains 3 W bosons, 4 gluons and 1 tau lepton.
The universe contains 3 W bosons, 4 gluons and 1 tau lepton.
The universe contains 2 W bosons, 4 gluons, 1 tau lepton, 1 antimuon and 1 neutrino.
The universe contains 2 W bosons, 4 gluons, 1 tau lepton, 1 antimuon and 1 neutrino.
The universe contains 1 W boson, 4 gluons, 1 tau lepton, 3 antimuons, 1 positron and 4 neutrinos.
The universe contains 4 gluons, 1 tau lepton, 4 antimuons, 1 positron and 5 neutrinos.
Simulation ended after 653.2 yoctoseconds.

性能

也不是那么坏!它在25秒内计算了100000希格斯玻色子

The universe contains 64751 bottom quarks, 93044 bottom antiquarks, 170984 gluons, 59927 tau leptons, 33038 antitau leptons, 14718 charm quarks, 12419 charm antiquarks, 5250 muons, 261567 antimuons, 53148 positrons, 305169 neutrinos, 2142 antineutrinos, 1575 electrons, 14080 down quarks and 7926 down antiquarks.
Simulation ended after 3131.4 yoctoseconds.

欢迎光临本站!你需要周围的空间>在你的while?自从我在Ruby中完成任何工作以来已经有一段时间了。
精神主义主义的O'Zaic,

一个问题:在粒子列表中,最后一个逗号需要替换为`和`才能满足挑战要求。
面包盒

2

D,1172 1101字节-10%= 990.9字节

import std.random,std.conv,std.stdio,std.algorithm,std.range;alias I=int,V=void,S=string,F=float,U=uniform01!F,W=writef,J=join,X=split;V main(S[]v){I[26]c;c[0]=to!I(v[1]);S[84]s;s[65..$]="antiX bosonXcharm Xdown XelectronXZXgluonXHiggsXtop Xbottom Xup Xtau leptonXmuonXneutrinoXWXphotonXquarkXpositronXstrange ".X('X');S[]f="HBXOBXFBXKQXKAQXDQXDAQXIQXIAQXJQXJAQXSQXSAQXCQXCAQXLXALXEXRXGXPXMXAMXNXAN".X('X');V 
D(I i,F p,F[]d,S v){d~=200;if(c[i]&&U()<p){c[i]--;p=U();foreach(j,q; d){if(p<q/100){c[v[2*j]-65]++;c[v[2*j+1]-65]++;break;}}}}S
C(T)(T s){return(s.length>1)?s[0..$-1].J(", ")~" and "~s[$-1]:s.J(" and ");}I
y=0;while(1){W("The universe contains "~C(iota(0,c.length).filter!(i=>c[i]).map!(i=>to!S(c[i])~" "~f[i].map!(a=>s[a]).J~((c[i]>1)?"s":"")).array)~".\n");y++;if(c[0]+c[1]+c[7]+c[8]<1)break;F[]u=[100/3.0,200/3.0];D(0,.000433,[.0216,.0460,.157,.38,1.97,5.24,12.28,21.1,35.2],"HIVWCUUUCCNOPQTTBBJK");D(2,.5,[11.8,23.6,38.8,54.,69.2,72.6,76.,79.4],"XYRSVWPQFGLMJKDENO");D(1,.5,u,"SXWXQX");D(7,.1295,u,"BFBLBJ");D(8,.1295,u,"BGBMBK");}W("Simulation ended after %f yoctoseconds.\n",y/10.0);}

不打高尔夫球

import std.random,std.conv,std.stdio,std.algorithm,std.range;
alias I=int,V=void,S=string,F=float,U=uniform01!F;

//uppercase is antiparticle.  The enums are replaced with constants
//in the golfed version.
enum P{ 
    h, w, z, //bosons
    u,U, d,D, t,T, b,B, s,S, c,C,//quarks
    l,L, //tau lepton, antitau lepton
    e,E, //electron,positron
    g, //gluon
    p, //photon
    m,M, //muon, antimuon
    n, N, //neutrino, antineutrino
};

void main(string[] v) {
    int[26]c;//particle counts
    c[0]=to!int(v[1]);//mandatory argument

    string format_particle(ulong i) {
        string[84] strs;
        strs[65..$]=["anti"," boson","charm ","down ","electron",/*f*/"Z",
        "gluon","Higgs",/*i*/"top ",/*j*/"bottom ",/*k*/"up ","tau lepton","muon","neutrino",/*o*/"W","photon","quark",/*r*/"positron","strange "];
        string[] fmt = [
            "HB","OB","FB",//bosons
            "KQ","KAQ",//up
            "DQ","DAQ",//down
            "IQ","IAQ",//top
            "JQ","JAQ",//bottom
            "SQ","SAQ",//strange
            "CQ","CAQ",//charm
            "L","AL",//Tau leptons
            "E","R",//electron/positron
            "G", //gluon
            "P", //photon
            "M","AM", //muon, antimuon
            "N", "AN", //neutrino, antineutrino
        ];
        //In the golfed version, we instead use X to delimit strings and call split to convert to array.

        return to!string(c[i])
            ~ " " ~ fmt[i].map!(a=>strs[a]).join
            ~ ((c[i]>1) ? "s" : "");
    }

    /* if there exist any of particle `i`, 
       it decays with probability `p`.
       into the particles specified in `v[j]`
       where `j` is drawn from distribution `decay_probs` */
    void decay(int i, float p, float[] decay_probs, P[] v...) {
        decay_probs ~= 2;//1.0, but with a margin for error in case of floating point precision issues
        if (c[i] && U()<p){
            c[i]--;

            p=U();
            foreach(j,q; decay_probs) {
                if (p<q) {
                    c[v[2*j]]++;
                    c[v[2*j+1]]++;
                    /*writef("Decay %s, Add: %s, %s\n",
                        format_particle(i),
                        format_particle(v[2*j]), format_particle(v[2*j+1]));*/
                    break;
                }
            }
        }
    }

    int y=0;
    while(1) {
        string commas(T)(T s) {
            return (s.length > 1)
                ?  s[0..$-1].join(", ") ~ " and " ~ s[$-1]
                :  s.join(" and ");
        }

        //print line for particle `d`
        writef("The universe contains " 
            ~ commas(
                iota(0,c.length)
                    .filter!(i=>c[i])
                    .map!(i=>format_particle(i))
                    .array) ~ ".\n");

        y++;
        if(c[P.h]+c[P.w]+c[P.t]+c[P.T]<1)break;

        F[] u = [1/3.0,2/3.0];
        decay(P.h, .000433,
            [.000216,.000460,.00157,.0038,.0197,.0524,.1228,.211,.352],
            P.t,P.T, P.m,P.M, P.z,P.p, P.p,P.p, P.z,P.z, P.c,P.C, P.l,P.L, P.g,P.g, P.w,P.w, P.b,P.B); 
        decay(P.z, .5,
            [.118,.236,.388,.54,.692,.726,.76,.794],
            P.n,P.N, P.e,P.E, P.m,P.M, P.l,P.L, P.d,P.D, P.s,P.S, P.b,P.B, P.u,P.U, P.c,P.C);
        decay(P.w,    .5, u, P.E,P.n, P.M,P.n, P.L,P.n);
        decay(P.t, .1295, u, P.w,P.d, P.w,P.s, P.w,P.b);
        decay(P.T, .1295, u, P.w,P.D, P.w,P.S, P.w,P.B);
        //In the golfed version, the list of enums is replaced by a string: each char is 65 + the enum's value.  D() is adjusted to subtract it again.
    }

    writef("Simulation ended after %f yoctoseconds.\n", y/10.0);
}

2

Kotlin:1330-10%= 1197字节

我有史以来第一次编写高尔夫球代码;由于列表比地图更具高尔夫性,因此效率很低,但看似正确!适用于JVM或JS实现,并带有(可选)参数。

operator fun String.minus(p:Pair<String,String>)=replace(p.first,p.second)
operator fun<A,B>A.div(b:B)=to(b)
val l=1.0
val e=l/3
val t=l-e
enum class V(val c:Double=.0,vararg val v:Pair<Pair<V,V>,Double>){E,F,G,P,L,AL,M,AM,N,AN,_Q,_AQ,CQ,CAQ,DQ,DAQ,SQ,SAQ,UQ,UAQ,WB(.5,P/N/e,AM/N/t,AL/N/l),TQ(.1295,WB/DQ/e,WB/SQ/t,WB/_Q/l),TAQ(.1295,WB/DAQ/e,WB/SAQ/t,WB/_AQ/l),ZB(.5,N/AN/.206,E/P/.24,M/AM/.274,L/AL/.308,DQ/DAQ/.46,SQ/SAQ/.612,_Q/_AQ/.764,UQ/UAQ/.882,CQ/CAQ/l),HiggsB(.000433,_Q/_AQ/.648,WB/WB/.789,G/G/.8772,L/AL/.9476,CQ/CAQ/.9803,ZB/ZB/.9962,F/F/.99843,ZB/F/.99954,M/AM/.999784,TQ/TAQ/l);fun d()=if(Math.random()<c)with(Math.random()){v.first{this<it.second}.first.toList()}else listOf(this)
override fun toString()=name-"_"/"bottom "-"A"/"anti"-"B"/" boson"-"C"/"charm "-"D"/"down "-"E"/"electron"-"F"/"photon"-"G"/"gluon"-"L"/"tau lepton"-"N"/"neutrino"-"M"/"muon"-"P"/"positron"-"Q"/"quark"-"S"/"strange "-"T"/"top "-"U"/"up "}
fun main(vararg a:String){var t=.0
var l=List(a.lastOrNull()?.toInt()?:1){V.HiggsB}
while(true){++t
var s="The universe contains"
with(l.toSet()){forEachIndexed{i,p->l.count{it==p}.let{s+=(" $it $p")
if(it>1)s+='s'
s+=when(size){i+1->"."
i+2->" and"
else->","}}}}
println(s)
if(l.filter{it.c>0}.isEmpty())break
for(p in l){l-=p;l+=p.d()}}
t/=10
print("Simulation ended after $t yoctoseconds.")}

少打高尔夫球

operator fun String.minus(p:Pair<String,String>)=replace(p.first,p.second)
operator fun<A,B>A.div(b:B)=to(b)
val l=1.0
val e=l/3
val t=l-e
enum class V(val c:Double=.0,vararg val v:Pair<Pair<V,V>,Double>){
    E,F,G,P,L,AL,M,AM,N,AN,_Q,_AQ,CQ,CAQ,DQ,DAQ,SQ,SAQ,UQ,UAQ,
    WB(.5,P/N/e,AM/N/t,AL/N/l),
    TQ(.1295,WB/DQ/e,WB/SQ/t,WB/_Q/l),
    TAQ(.1295,WB/DAQ/e,WB/SAQ/t,WB/_AQ/l),
    ZB(.5,N/AN/.206,E/P/.24,M/AM/.274,L/AL/.308,DQ/DAQ/.46,SQ/SAQ/.612,_Q/_AQ/.764,UQ/UAQ/.882,CQ/CAQ/l),
    HiggsB(.000433,_Q/_AQ/.648,WB/WB/.789,G/G/.8772,L/AL/.9476,CQ/CAQ/.9803,ZB/ZB/.9962,F/F/.99843,ZB/F/.99954,M/AM/.999784,TQ/TAQ/l);
    override fun toString()=name-
        "_"/"bottom "-
        "A"/"anti"-
        "B"/" boson"-
        "C"/"charm "-
        "D"/"down "-
        "E"/"electron"-
        "F"/"photon"-
        "G"/"gluon"-
        "L"/"tau lepton"-
        "N"/"neutrino"-
        "M"/"muon"-
        "P"/"positron"-
        "Q"/"quark"-
        "S"/"strange "-
        "T"/"top "-
        "U"/"up "
    fun d()=if(Math.random()<c)
        with(Math.random()){
            v.first{this<it.second}.first.toList()
        }else listOf(this)
}
fun main(vararg a:String){
    var t=.0
    var l=List(a.lastOrNull()?.toInt()?:99){V.HiggsB}
    while(true){
        ++t
        var s="The universe contains"
        with(l.toSet()){
            forEachIndexed{i,p->
                l.count{it==p}.let{
                    s+=(" $it $p")
                    if(it>1)s+='s'
                    s+=when(size){
                        i+1->"."
                        i+2->" and"
                        else->","
                    }
                }
            }
        }
        println(s)
        if(l.filter{it.c>0}.isEmpty())break
        for(p in l){l-=p;l+=p.d()}
    }
    t/=10
    print("Simulation ended after $t yoctoseconds.")
}

1

提交时间很长。

打高尔夫球的次数不多,但仍然比其他蟒蛇短。

以希格斯的初始量为输入。

Python 3中1134 1120字节- 10(%)= 1020.6 1008点

from random import *
n=int(input())
M=random
seed()
def D(i):
 for a in i:d[a]=d[a]+1 if a in d else 1
def X(p,A,B):
 for l in d[s]*' ':
  n[0]=1
  if M()<=p:d[s]-=1;r=M();D(A[B.index(next(x for x in B if x>r))])
s=lambda x:x.replace(Z,'')
Z,C,e,i,k,m,p,t,v='anti, boson,electron,gluon,neutrino,muon,photon,tau lepton,positron'.split(',')
B=' '+Z+'quark'
a='bottom'+B
c='charm'+B
f='down'+B
h="Higgs"+C
o='top'+B
u=Z+k
w="W"+C
x=Z+m
y=Z+t
z='Z'+C
S='strange'+B
U='up'+B
b,g,j,q,Q,T=map(s,[a,f,c,o,S,u])
d={h:n,0:0}
I=0
A=[(a,b),(w,w),(i,i),(t,y),(c,j),(z,z),(p,p),(z,p),(m,x),(o,q)]
B=[.648,.789,.8772,.9476,.9803,.9962,.99843,.99954,.999784,1]
O=[[k,v],[k,x],[k,y]]
E=[1/3,2/3,1]
F=[(u,k),(e,v),A[8],A[3],(g,f),(S,Q),A[0],(T,U),(c,j)]
G=[.206,.24,.274,.308,.46,.612,.764,.882,1]
H=[[w,g],[w,Q],[w,a]]
n={1}
while n:
 I+=1
 n={}
 P=dict(d)
 for s in P:
  if s==h:X(.00433,A,B)
  if s==w:X(.5,O,E)
  if s==z:X(.5,F,G)
  if s in [q,o]:X(.1295,H,E)
 l='The universe contains '
 for s in d:l+= str(d[s])+' '+s+'s'*(d[s]>1)+', ' if d[s]>0 else ''
 print(l[:-2]+'.')
print('Simulation ended after '+str(I/10)+' yoctoseconds.')

在线尝试!


1

F#,1993 1908字节-10%= 1718字节

open System
let r=new Random()
let p()=r.NextDouble()*100.0
type P=
 |A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z
let q="quark"
let n=dict[(A,"Higgs boson");(B,"Bottom "+q);(C,"Bottom anti"+q);(D,"Top "+q);(E,"Top anti"+q);(F,"W boson");(G,"Gluon");(H,"Tau lepton");(I,"Anti-tau lepton");(J,"Charm "+q);(K,"Charm anti"+q);(L,"Z boson");(M,"Photon");(N,"Muon");(O,"Antimuon");(P,"Antiquark");(Q,"Positron");(R,"Neutrino");(S,"Antineutrino");(T,"Electron");(U,"Down"+q);(V,"Down anti"+q);(W,"Strange "+q);(X,"Strange anti"+q);(Y,"Up "+q);(Z,"Up anti"+q);]
let c(u:P seq)=Option.isSome(Seq.tryFind(fun p->Seq.contains p [A;F;L;D])u)
let w()=
 if r.Next(2)=0 then
  let p=r.Next(3)
  if p=0 then[Q;R]elif p=1 then[O;R]else[I;R]
 else[F]
let t a=
 if p()<12.95 then
  let p=r.Next(3)
  if p=0 then[F;U]elif p=1 then[F;W]else[F;B]
 else[a]
let h()=
 if p()<0.0433 then
  let p=p()
  if p<64.8 then[B;C]elif p<78.9 then[F;F]elif p<87.72 then[G;G]elif p<94.76 then[H;I]elif p<98.03 then[J;K]elif p<99.62 then[L;L]elif p<99.843 then[M;M]elif p<99.954 then[L;M]elif p<99.9784 then[N;O]else[D;E]
 else[A]
let z()=
 if r.Next(2)=0 then
  let p=p()
  if p<20.6 then[R;S]elif p<24.0 then[T;Q]elif p<27.4 then[N;O]elif p<30.8 then[H;I]elif p<46.0 then[U;V]elif p<61.2 then[W;X]elif p<76.4 then[B;C]elif p<88.2 then[Y;Z]else[J;K]
 else[F]
let d u=List.map(fun p->if p=A then h()elif p=F then w()elif p=L then z()elif p=D||p=E then t p else[p])u|>List.concat 
let b h=List.init h (fun x->id A)
let o u=
 let e=List.countBy id u|>List.map(fun t->n.[fst t],snd t)|>List.map(fun t->
   if snd t>1 then(snd t,(fst t)+"s")else snd t,fst t)
 String.Join(", ",(List.map(fun x->(string(fst x))+" "+(snd x))e))|>printfn"The universe contains %s."
let [<EntryPoint>]m a=
 let mutable u=int a.[0]|>b
 let mutable t=0
 while c u do
  o u
  u<-d u
  t<-t+1
 o u
 (float t)/10.0|>printfn"Simulation ended after %f yoctoseconds."
 0

在线尝试!

松开它看起来像这样:

颗粒很多

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.