JavaScript:191文字
(ルール内で)選択した入力形式は、コンマで区切られた頻度数です。スペースや改行は許可されません。最初のNは指定しないでください。各番号は、オプションのドットがどこかにある、少なくとも1つの[0-9]桁の連続でなければなりません。入力の形式が正しくない場合、動作は未定義です。
使い方:
一部の整数頻度数の周期は、これらの数のGCDです。与えられた数値が整数でない場合は、整数としてすべてが得られるまで10を続けて乗算します(これは、非整数の数値が10進数で与えられるという事実を悪用します)。GCDを計算した後、結果を入力数の乗算に使用される10の累乗で割り、全体の周波数を取得します。これを逆にすると、周期がわかります。
注:私がこの答えを出した今、誰かが同じことをAPLまたはJでコーディングし、それを打ち負かすと確信しています。:(
コード:
d=1,s=prompt().split(",");for(a in s){s[a]=parseFloat(s[a]);while(s[a]*d%1>0)d*=10}g=s[0]*d;for(a in s){u=g;v=s[a]*=d;p=2;q=1;while(u>=p&v>=p)if(u%p|v%p)p++;else{u/=p;v/=p;q*=p}g=q}alert(d/g)
それをテストする:
Input: 50,10
Output: 0.1
Interpretation: One GIF blinks 10 times per second (period = 0.1s) and the other 50 times (period = 0.02s). So a combined GIF would repeat itself in 0.1 seconds.
Input: 2.7,3.4
Output: 10
Interpretation: One blinking at 2.7 times per second will blink 27 times in 10 seconds. One blinking 3.4 times per second will blink 34 times in 10 seconds. So, 10 seconds is a period, and since GCD(27,34)=1, it is the smallest.
Input: 4.8,7.2
Output: 0.4166666666666667
Interpretation: One blinking at 4.8 times per second and the other at 7.2 times per second, gives a frequency of 2.4 times per second, which is a period 0.41666... seconds.
Input: 0.6,12,7.9,4.33
Output: 100
Interpretation: Similar to second case. 60, 1200, 790 and 433 times each 100 seconds. The GCD of these numbers is 1.
Input: 400,200,25,350
Output: 0.04
Interpretation: The slowest is the 25 times per second, which is the overall frequency. 25 times per second is a period of 0.04 seconds.
Input: 440,200,35,360
Output: 0.2
Interpretation: In 0.2 seconds, we have 88, 40, 7 and 72 blinks.