タイムトラベルのパラドックス


17

男性には2つのデバイスがあります。

  • タイムマシン -彼は考えることでこのマシンを制御できます。それにより、彼は、ある時点から過去または未来の別の時点(または現在の時点)にまったく時間をかけずに移動できます。彼がBからAに過去に移動する場合、AからBのすべての通常のイベント(タイムマシン、オルタネーターは除外)はまったく同じ方法で繰り返す必要があることに注意してください。その後、ポイントBからポイントAに戻ります。したがって、1回のタイムトラベルで無限ループが作成されます。
  • オルタネーター -この問題を認識して、彼は別のマシンを作成します。彼は、すべての物理的な出来事がループで繰り返されても、彼の考えが異なる場合があることに気付きます。したがって、このマシンは思考によっても制御できるように設計されています。マシンはいつでも使用して、使用した時間とは別の未来(過去ではない)を提供することができます。

長い例を使用して、すべての詳細を説明します。

1000 T+250 250 T+0 500 T-200 100 T-50 125 A 225 T-400 500 A 100 T-200 150 T-25 100 T+100 50 A 25
  • 1000年が経過しました。今は1000年です。
  • 彼は1000から1250まで移動します。
  • 250年が経ちました。今は1500年です。
  • 彼は1500から1500まで移動します。これは効果がありません(そして無視できます)。
  • 500年が経ちました。2000年になりました
  • 彼は2000年から1800年まで旅をしています。
  • 100年が経ちました。今は1900年です。
  • 彼は1900年から1850年に旅行します。
  • 125年が経ちますが、今回は、彼がループに入っているため、状況は異なります。1850年から1900年に50年が経過します。彼は1850年にループバックします。1850年から1900年にさらに50年が経過します。彼は再びループバックします。25年が経過し、1875年、つまり125年を完了します。
  • 彼はオルタネーターを使用しています。現在、彼が現在いる1875年とは別の未来があります。過去は変わりません。
  • 225年が経ちました。現在は2100年です。
  • 彼は2100から1700まで移動します。
  • 500年が経過:1700年から1875年までは通常175年です。いいえ、彼はオルタネーターに再び出会うことはありません。つまり、1875年以降に3番目の未来が作られました。通常は325年が経過し、2200年になります。
  • まだ定義されていない2200の未来は1つしか存在しないため、オルタネーターを使用しても効果はありません(無視してもかまいません)。
  • 100年が経ちました。現在は2300です。
  • 彼は2300から2100に移動します。
  • 150年が経過:2100年から2200年までは通常100年です。2番目の未来は2200から作成されます。50年が経過し、現在は2250年です。
  • 彼は2250から2225に移動することになっています。しかし、現在2つの異なるタイムラインに2つの2225が存在します。したがって、これはパラドックスにつながります。なぜなら、彼がどの時点に到達するかを判断できないからです。(彼がより最近のタイムラインに行くとは想定しません)したがって、これでシミュレーションが終了します。
  • 100 T+100 50 A 25パラドックスが発生し、シミュレーションの実行が停止したため、それ以上は完全に無視されます。

ヒント:例の理解に苦労している場合は、地球を掘っている道のようになる時間を想像してください。時間旅行の場合は、テレポーターを作成します。オルタネーターを使用している場合、既存のパスの壁に新しいパスを掘っています。

逆説

A、B、Cは3つの時点(次々と)であると仮定します。逆説は、次の場合に発生したと言われています。

  • ポイントCにあり、ポイントBにオルタネーターが存在し、ポイントBに複数の未来があり(そしてそれらの1つにいる)、タイムトラベルを介してBとCの間の任意のポイントにアクセスしようとします。
  • ポイントAにいて、ポイントBにオルタネーターが存在し、ポイントBの未来が複数存在し、タイムトラベルを介してポイントC(Bの後)にアクセスしようとしています。

入力

例に類似した一連のイベント。(フォーマットは柔軟です。)

出力

パラドックスが発生したかどうかを示す真実/偽の値。

チャレンジ

最短コード(バイト単位)が優先されます。


調子flexibleはどうformat

@ GlennRanders-Pehrsonああ、私はあなたが意味するものを得た。編集済み。
ghosts_in_the_code

2
@sysreq入力での追加の句読点(空白、コンマ、ブラケットなど)が許可されます。タイムトラベルとオルタネーターを区別できるキャラクター。+および-(順方向/逆方向)の代わりに使用できる文字。数値は任意の基数(2進数、10進数など)にすることができます。イベントは同じ順序でのみ入力されます。実際の年数は提供されません。startがゼロ(または他の整数)であると仮定し、実際の年数を自分で計算する必要があります(必要な場合)。
ghosts_in_the_code

1つの大きな例の代わりにいくつかの小さな例があれば役立ちますが、私はまだ投票しました!
明るくしない

回答:


4

ルビー、510 460バイト

p=[0];w=[n=x=0]
i=gets.split.map{|s|
if x!=1
if s[0]=="A"
w<<n
else
if s[0..1]=="T+"
t=n
q=s[2..-1].to_i
if w[-1]==t||(w[-1]>t&&w[-1]<n+q)
w<<w[-1]
n+=q
else
n+=(t<p[-1]&&n+q>p[-1])?q%(p[-1]-n):q
end
elsif s[0..1]=="T-"
t=n
p<<n
n-=s[2..-1].to_i
x=(x==0&&w[-1]>0&&t>w[-1]&&n>w[-1])?1:0
else
t=n
q=s.to_i
if w[-1]==t||(w[-1]>t&&w[-1]<n+q)
w<<w[-1]
n+=q
else
n+=(t<p[-1]&&n+q>p[-1])?q%(p[-1]-n):q
end
end
end
else
break
end}
p x

入力

例として

出力

0 =パラドックスなし、1 =パラドックス

サンプル

提供されたサンプル入力:パラドックスが発生したことを示すを1000 T+250 250 T+0 500 T-200 100 T-50 125 A 225 T-400 500 A 100 T-200 150 T-25 100 T+100 50 A 25 返します1

ノート

これは、私が試みた最初の演習であるだけでなく、私が書いた最初のRubyプログラムでもあります。したがって、おそらくさらに短くなる可能性があります。

簡単な説明

p: Infinite loops
w: Alternate timelines
n: Now (regardless of timeline)
x: Paradox

無限ループは、時間内に前進しているときにのみ発生します。特にこれを解決するより良い方法を指摘している場合は、フィードバックをお待ちしております。


サンプルの入出力データを提供できますか?
アディソンクランプ

@VoteToClose-質問で提供されたデータとは別に、必要に応じてさらにサンプルデータを作成できますか?
ピーターアボリンズ

ああ、まあ、その「サンプル」部分を完全に見逃しました。私はアホです。+1
アディソンクランプ

3
すべてのthensは不要であり、削除できます。また、より多くの文字を保存する{...}代わりにdo...endを使用する必要があります。mapは1バイトを保存し、デフォルトで空白eachsplit分割します。初期化の最初の4行はに短縮できますp=[];w=[n=x=0]
ドアノブ

2
私はそれが3。5年だったことを知っています(笑..)、現在のコードを288バイトまでゴルフできると思います(私はRubyをあまりよく知らないので完全にはわかりません)。ただし、現在のコードは、順方向の時間旅行(OPの説明の2番目の箇条書き)のパラドックスを考慮していません。
ケビンクルーイッセン

3

05AB1E93 92 86 82 バイト

ðU0V#vyAQiYˆðUëy.ïiYy+DX˜såàiXD€нY@Ïн©θ-®¥OÄ%®θY-YOVëVëYy¦+©¯@àXðʘà*i1q}XY®Ÿª{U®V

入力はチャレンジの説明と同じ形式ですが、オルタネーターAabcdefghijklmnopqrstuvwxyz代わりにバイトを保存することを除きます。パラドックスが発生した場合は
出力1、そうでない場合は入力自体(105AB1Eでのみ真実であり、その他はすべて偽です)。

Java 10の回答に大まかに基づいています

オンラインでお試しください。

または、デバッグラインを追加してオンラインで試してください(TODO:すべてのテストケースで一度に適切なテストスイートを作成します。):
-後方タイムトラベルパラドックスを使用したテストケース:オンラインで試してください。
-フォワードタイムトラベルパラドックスを使用したテストケース:オンラインで試してください。
-タイムトラベルパラドックスのないテストケース:オンラインで試してみてください。

説明:

ðU                         # Set variable `X` (time-travels) to a space character " "
0V                         # Set variable `Y` (current year) to 0
#                          # Split the (implicit) input by spaces
 v                         # And loop over each event `y`:
  yAQi                     #  If the current event `y` is an alternator ("abcdefghijklmnopqrstuvwxyz"):
      Yˆ                   #   Add the current year `Y` to alternators-list `GB`
      ðU                   #   And reset variable `X` to " "
  ëyi                    #  Else-if the current event `y` is an integer:
       Yy+                 #   Calculate the current year `Y` plus the integer `y`
          D                #   Duplicate `Y+y`
           X˜såài          #   If this `Y+y` is within any of the time-travel ranges:
                 X €н      #    Get the starting positions of each time-travel
                     Y@    #    Check for each starting position if the current year `Y` is >= it
                  D    Ï   #    And only leave the time-travel ranges for which this is truthy
                        н  #    Then pop and push the first one
                         © #    Store this time-travel range in variable `r` (without popping)
                 θ         #    Pop and only leave the time-travel destination
                  -        #    Subtract it from the `Y+y` we duplicated
                       %   #    And modulo it with:
                   ®¥OÄ    #     The absolute distance of the time-travel `r`
                 ®θ        #    Then push the time-travel destination again
                   Y-      #    And subtract the current year `Y`
                 YO        #    Then sum these two and the current year `Y` together
                   V       #    And pop and store it as new year `Y`
       ë                   #   Else (`Y+y` is not within any time-travel ranges)
        V                  #    Simply pop and store the duplicated `Y+y` as new year `Y`
  ë                        #  Else (the current event `y` is a time-travel)
    y¦                     #   Remove the leading "T"
   Y  +                    #   And add the value to the current year `Y`
       ©                   #   Store this value in variable `r`
        ¯@à                #   Check if any alternator in list `GB` is >= this value
           XðÊ˜à           #   Check if there are any time-travels
                *i  }      #   And if both are truhy:
                  1        #    Push a 1
                   q       #    Stop the program
                           #    (after which the top of the stack is output implicitly)
    Y®Ÿ                    #   Create a list in the range [current year `Y`, new year `r`]
   X   ª                   #   Append it to the time-travels `X`
        {                  #   And then sort these time-travels
         U                 #   After which we pop and store it as updated `X`
   ®V                      #   And then set `Y` to the new year `r`
                           # (if we haven't reached `q`, the (implicit) input is output instead)

3

Java 10、498 485 478バイト

import java.util.*;s->{var a=new Stack<Long>();var m=new TreeMap<Long,Long>();long p=0,c=0,t,v,k;o:for(var S:s.split(" "))if((t=S.charAt(0))>65){var b=S.charAt(1)>44;v=new Long(S.substring(2));for(var A:a)p=A>c+(b?-v:v)|m.size()<1?p:1;if(v>0)m.put(c,b?c-v:c+v);c+=b?-v:v;}else if(t>64){a.add(c);m.clear();}else{t=new Long(S);e:for(var e:m.entrySet())if((k=e.getKey())>=c){for(v=c;v<=c+t;)if(a.contains(v++))break e;c=(v=e.getValue())+(c+t-v)%(k-v);continue o;}c+=t;}return p>0;}

入力は(現時点では)チャレンジの説明と同じ形式です。

@BenjaminUrquhartのおかげで-13バイト。@ceilingcatの
おかげで-7バイト。

オンラインそれを試してみてくださいまたは追加のデバッグラインとオンラインでそれを試してみてください

説明:

import java.util.*;            // Required import for the List and TreeMap
s->{                           // Method with String parameter and boolean return-type
  var a=new Stack<Long>();     //  Create a List for the alternators
  var m=new TreeMap<Long,Long>();
                               //  Create a sorted Map for the time-travels
  long p=0,                    //  Paradox-flag, initially 0
       c=0,                    //  Current year, initially 0
       t,v,k;                  //  Temp-values, uninitialized
  o:for(var S:s.split(" "))    //  Loop over the input substrings split by space:
    if((t=S.charAt(0))>65){    //   If the first character is a 'T':
      var b=S.charAt(1)>44;    //    Check if the second character is a '-'
      v=new Long(S.substring(2));
                               //    Convert the String-value to a number
      for(long A:a)            //    Loop over the alternators
        p=A>                   //     If an alternator is larger than:
            c+                 //      The current year, plus
              (b?              //      If we travel backwards in time:
                 -v            //       Subtract the value
                :              //      Else (we travel forward in time):
                 v)            //       Add the value
          |m.size()<1?         //     Or if no previous time-travels occurred:
           p                   //      Leave the paradox-flag the same
          :                    //     Else:
           1;                  //      Set the paradox-flag to 1
      if(v>0)                  //     If the value is not 0 (edge-case for "T+0")
        m.put(c,b?c-v:c+v);    //      Add the from-to time-travel to the Map
      c+=b?-v:v;}              //     Increase/decrease the year accordingly
    else if(t>64){             //   Else-if the character is an 'A':
      a.add(c);                //    Add the current year to the alternators-list
      m.clear();}              //    And empty the time-travel Map
    else{                      //   Else (it's a number)
      t=new Long(S);           //    Convert the String to a number
      e:for(var e:m.entrySet())//    Loop over the time-travels:
        if((k=e.getKey())      //     If the time-travel starting point is
                         >=c){ //     larger than or equal to the current year
          for(v=c;v<=c+t;)     //      Loop from the current year to the year+number:
            if(a.contains(v++))//       If the alternator-list contains any of these years
              break e;         //        Stop the time-travel loop
          c=                   //      Set the current year to:
             (v=e.getValue())  //       The time-travel destination
             +                 //       Plus:
              (c+t             //        The current year plus the number
                  -v)          //        minus the time-travel destination
                     %(k-v);   //        Modulo the time-travel from-to distance
          continue o;}         //      And then continue the outer input-loop
      c+=t;}                   //    Increase the current year by the number 
  return p>0;}                 //  Return whether the paradox-flag is 1

なぜ使用しないのLongですか?
ベンジャミンアー

1
@BenjaminUrquhart良い質問..最初は私のリストとマップは生のタイプだったのでint、短くなりましたが、マップエントリのキーと値のペアでエラーが発生しました。その後、すべてをLongに変更することを考えませんでした。-13をありがとう!
ケビンクルーッセン
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.