回答:
あなたは交換する必要があるかもしれないprintとalertあなたのJavaScript環境に応じて、または何か他のもの。
for(C=L=T=0;C++<10;print(L=T))while(!(T-L&&T+L-7))T=Math.random()*6+1|0
              バッシュ
#/!bin/bash
f=`expr $RANDOM % 6` 
f=`expr $f + 1`
printf "$f"
for ((i=0; i<9; i++))
do
   ((bad=7-$f))
   next=`expr $RANDOM % 6`
   next=`expr $next + 1`
   while [ $next -eq $bad ] || [ $next -eq $f ]
   do
      next=`expr $RANDOM % 6`
      next=`expr $next + 1`
   done
printf "$next"
f=$next
done
サンプルコード:http : //ideone.com/CCfro
((var=expression))は非常に素晴らしいです-私は最短の方法がそうだと思ったvar=$((expression))しかし、なぜあなたは一度だけそれを使用し、バックティックのexprで大量の文字を浪費するのですか?
                    for(i in 0:9)cat(F<-sample(setdiff(1:6,c(F,7-F)),1))
              for((i = 10、f = RANDOM%6 + 1; i-;))do printf $ f ((n =ランダム%4 + 1、m = f <4?f:7-f、f = n <m || ++ n <7-m?n:n + 1)) やった
重要な考え方は、[1、x]の乱数をyと等しくないように選択するために、[1、x-1]の乱数を選択し、> = yの場合にインクリメントできるということです。この問題では、[1,6]にfまたは7-fと等しくない乱数が必要です。min(f、7-f)、max(f、7-f)の順序で2つのテストを実行する必要があります。
最初は空の環境でiを初期化せずにループ条件を変更することで2文字を節約できると仮定します i++<10
Aman ZeeK Vermaの答えから大きくゴルフをしました。
for((i = 10、f = 0; i-;))do for((n = f; n == f || n + f == 7; f = RANDOM%6 + 1))do: やった printf $ f やった
NBはおそらく最初の行をに変更することで5文字縮小することができますfor((;i++<10;))が、それは常に有効とは限らない仮定を作ります。それはideoneでは問題なく動作しますが、シェルから実行している誰かが持っているiかf、ゼロ以外のものにエクスポートすることができます。
man bash、それをお勧めします。私はかつてそれをカバーツーカバーで読みましたが、何が可能か調べてみる価値があるかについて漠然とした考えを持っているだけで十分に役立ちました。
                    -join(0..9|%{($d=1..6-ne(7-$d)-ne$d|random)})
実際、かなり些細なことです。可能なサイコロロールのリストを生成し、1..67から最後のロールを引いたものに等しくないもののみを選択し、最後のロールに等しくないもののみを選択します。残りのリストから、ランダムなアイテムを選択してに割り当て$dます。$d最初は0通常のダイスを振るので最初に扱われるので。
テストスクリプト:
for($i=0;$i-lt20;$i++){
    $o=@(./tipping.ps1)
    if ($i-gt0-and$o-eq$o2) { throw "Must have random output" }
    if ($o.count-ne1) { throw "Must only have one line of output" }
    if ($o[0]-match'[^1-6]'){ throw "Invalid characters" }
    if($o[0].length-ne10){ throw "Wrong length: $($o[0].length)" }
    $r=[char[]]($o[0])|%{$_-48}
    for ($x=1;$x-lt$r.count;$x++){
        if ($r[$x-1]+$r[$x]-eq7) { throw "Not a tipping: $($r[$x-1]) and $($r[$x])" }
    }
    $o2=$o
}
歴史:
The term 'random' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
                    Get-Randomコマンドレットは、V1には存在しませんでした。
                    >:(?@4:{(i.6)-.],5&-)^:(<10)?6
6 2 3 5 4 2 4 1 3 6
説明(右から左に読む):
?6 0〜5の乱数を返します^:(<10)関数を9回適用し、途中で結果を蓄積します。機能は次のとおりです。?@4:{(i.6)-.],5&-
] , 5&- 入力数と5の補数の配列を返します(現在0から始まる数を処理しているため、反対面の合計は5です)(i. 6) -. 0から5までの整数の完全なセットからそれらを削除します。入力位置からの1回のティッピング操作の後、すべての有効な位置が残ります。?@4: { そのうちの1つをランダムに選択します。>: シーケンス全体をインクリメントして、数字を1〜6の間隔に戻します。16 2f 25 08 41 20 17 30 16 2f 31 31 25 09 19 32
仕組み
16 2f 25     # make range from 1 to 6 and push random element
08           # start block
    41       # duplicate top of stack twice
    20 17 30 # negate top of stack and add 7
    16 2f    # push range from 1 to 6
    31 31    # do set-wise difference with each of the two previous numbers
    25       # push a random element from the list
09           # end block
19 32        # repeat block 9 times
              2つの改行が必要であり、それぞれ1文字として文字カウントに含まれます。
RANDOMIZE:FOR I=0TO 9
1N=INT(RND*6)+1:IF L=N OR L+N=7THEN 1
?N:L=N:NEXT
              v->{int d=(int)(Math.random()*6+1),i=10,p;String r=""+d;for(;i-->0;r+=d)for(p=d;p==d|p+d==7;d=(int)(Math.random()*6+1));return r;}
詳細なメインメソッドを使用した完全なプログラムとして、これは代わりに178バイトになります。
interface M{static void main(String[]a){int d=(int)(Math.random()*6+1),i=10,p;String r=""+d;for(;i-->0;r+=d)for(p=d;p==d|p+d==7;d=(int)(Math.random()*6+1));System.out.print(r);}}
説明:
 v->{              // Method with empty unused parameter and String return-type
   int d=(int)(Math.random()*6+1),
                   //  Random dice-roll 1-6
       i=10,       //  Counter-integer, starting at 10
       p;          //  Temp integer to store new side
   String r=""+d;  //  Result-String, starting at the first dice-roll
   for(;i-->0;     //  Loop (1) 10 times:
       r+=d)       //    After every iteration, append the result with a random side
     for(p=d;      //   Set the new side to the current side
         p==d      //   Loop (2) as long as the new side and current side are the same
         |p+d==7;  //   or as long as both combined are exactly 7:
       d=(int)(Math.random()*6+1)
                   //    Set the new side to a random side 1-6
     );            //   End of loop (2)
                   //  End of loop (1) (implicit / single-line body)
  return r;        //  Return the result-String
}                  // End of method
              a=randi(6)
for i=1:9;b=1:6;b([a,7-a])=[];a=b(randi(4))
end
              c(3,5,1,4,2,6)[(sample(1:6,1)+cumsum(sample((-2:2)[-3],9,T)))%%6+1]
ゴルファーのRの回答がありますが、これはこれまでに提出された回答とは異なるアプローチだと思います。
c(3,5,1,4,2,6)                                                     #A dice and its facets
               (sample(1:6,1)                                      #Initial dice roll
                             +cumsum(sample((-2:2)[-3],9,T)))      #9 tippings in c(-2,-1,1,2)
                                                             %%6+1 #converts to values in [0,6]
              [                                                   ]#
              6LΩUTFX?6LʒDXÊsX+7Ê*}ΩU
間違いなくゴルフはできますが、現在は見ていません。
説明:
6LΩ              # Pick a random value from the range [1,6]
                 #  i.e. [1,2,3,4,5,6] → 3
   U             # Save this random value in variable `X`
TF               # Loop 10 times:
  X?             #  Print `X` without newline to STDOUT
  6Lʒ     }      #  Create a range [1,6] again, and filter it by:
     DXÊ         #   Check if the current value is not equal to `X`
                 #    i.e. 1 and 3 → 1 (truthy)
                 #    i.e. 3 and 3 → 0 (falsey)
     sX+         #   Sum the current value with `X`
                 #    i.e. 1 and 3 → 4
                 #    i.e. 3 and 3 → 6
        7Ê       #   And check if it's not equal to 7
                 #    i.e. 4 and 7 → 1 (truthy)
                 #    i.e. 6 and 7 → 1 (truthy)
     *           #   If both checks are truthy, keep it in the filtered list
                 #    i.e. 1 and 1 → 1 (truthy)
                 #    i.e. 0 and 1 → 0 (falsey)
           Ω     #  Pick a random value from the filtered list
                 #   i.e. [1,2,5,6] → 1
            U    #  And save it in variable `X` for the next iteration of the loop