タグ付けされた質問 「algorithm」

アルゴリズムの作成または実装に関連する課題について。

6
一貫したオーバーヘッドバイトスタッフィング(COBS)
これが以前に投稿されていないことに驚いています! 一貫オーバーヘッド・バイトスタッフィング(COBS)アルゴリズムが区切バイトストリームに使用されます。 フレームマーカー(0x00を使用します)を選択し、ストリーム内で0x00が発生するたびに、次の0x00が発生するまでバイト数で置き換えます(これをマイルストーンと呼びます)。これにより、値の範囲が0..255から1..255に減少し、0x00がストリーム内のフレームを明確に区切ることができるようになります。 マイルストーンで、次の255Bに0x00が含まれていない場合、これは最大マイルストーン長を超えます-アルゴリズムは255Bで「停止」し、別のマイルストーンを配置する必要があります。これは「一貫したオーバーヘッド」です。 最初のバイトは最初のマイルストーンになり、最後のマイルストーンはフレームマーカーまでのバイト数になります。 ウィキペディアのいくつかの例(色分けされている記事を読むのに最適です): 0x00 as frame marker Unencoded data (hex) Encoded with COBS (hex) 00 01 01 00 00 00 01 01 01 00 11 22 00 33 03 11 22 02 33 00 11 22 33 44 05 11 22 33 44 00 11 00 00 …

7
pseudoprimesをゴルフしましょう!
はじめに/背景 で、最近の議論で暗号チャット私は議論するために/のヘルプ挑戦されたフェルマー素数判定テストとカーマイケル数を。このテストは、a^(p-1) mod p==1常に素数に当てはまるがp、常にコンポジットには当てはまらないという前提に基づいています。カーマイケル番号は、基本的にはフェルマートのテストで最悪の敵です。取得するために同時に素数にならないように選択aする必要がある番号です。が共素数でない場合、本質的には、自明ではない因子を見つけましたpa^(p-1) mod p!=1apそして、誰もが知っているように、因数分解は非常に難しい場合があります。特に、すべての要素が十分に大きい場合。これで、Fermatテストが実際にはあまり使用されない理由がよくわかります(より優れたアルゴリズムがあります)。これは、(セキュリティの観点から)防御者としてのあなたが同じような量の作業を行わなければならない数があるためです。攻撃者(つまり、数を因数分解します)。 これらの数値が魅力的である理由がわかったので、可能な限り最短の方法で数値を生成します。必要に応じて、生成したコードを記憶することができます。 カーマイケル番号は、OEISではA002997としても知られています。関連する課題はすでに ありますが、サイズではなく速度が最適化されているため、ここからのエントリは競争力がありません。同じ議論が逆の方向にも当てはまり、ここのエントリはサイズを優先して速度とトレードオフをする可能性があります。 仕様 入力 これは標準のシーケンスチャレンジなので、正または負でない整数nを入力として使用します。n必要に応じて、0または1のインデックスを付けることができます(指定してください)。 出力 出力は、必要にn応じて、-番目のカーマイケル番号または最初のnカーマイケル番号のいずれかになります(指示してください)。 仕様 整数xは、xが複合である場合にのみカーマイケル数であり、のすべての整数yについてgcd(x,y)=1、それを保持しy^(x-1) mod x==1ます。 誰が勝ちますか? これはcode-golfなので、バイトで最短のコードが優先されます!標準のIOと抜け穴のルールが適用されます。 テストケース 最初のいくつかのカーマイケル番号は次のとおりです。 561,1105,1729,2465,2821,6601,8911,10585,15841, 29341,41041,46657,52633,62745,63973,75361,101101, 115921,126217,162401,172081,188461,252601,278545, 294409,314821,334153,340561,399001,410041,449065, 488881,512461
9 code-golf  math  sequence  number-theory  primes  code-golf  string  code-golf  math  combinatorics  permutations  restricted-complexity  code-golf  array-manipulation  code-golf  number  sequence  code-golf  number  sequence  code-golf  binary-matrix  code-golf  math  tips  javascript  algorithm  code-golf  string  code-golf  number  sequence  code-golf  math  arithmetic  parsing  code-golf  number  sequence  primes  code-golf  string  ascii-art  geometry  integer  code-golf  geometry  code-golf  number  array-manipulation  code-golf  math  geometry  code-golf  number  sequence  arithmetic  integer  code-golf  string  kolmogorov-complexity  code-golf  number  code-golf  number  chess  code-golf  sequence  decision-problem  subsequence  code-golf  math  number  primes  code-golf  primes  permutations  code-golf  integer  probability-theory  statistics  code-golf  string  code-golf  sequence  decision-problem  parsing  board-game  code-golf  binary  graph-theory  code-golf  board-game  classification  tic-tac-toe  code-golf  ascii-art  polyglot  code-golf  date  code-golf  geometry 

13
比較チェーンを拡張
ほとんどの言語と異なり、Python a<b<cは数学で行われるように評価し、ブール値a<bをと比較するのではなく、実際には3つの数値を比較しcます。これをC(および他の多くの)で記述する正しい方法は、a<b && b<c。 この課題の課題は、このような任意の長さの比較チェーンをPython /直感的な表現から他の言語でどのように記述するかまで拡張することです。 仕様書 プログラムは演算子を処理する必要があります。 ==, !=, <, >, <=, >=。 入力には、整数のみを使用した比較チェーンがあります。 途中の比較の真実性について心配する必要はありません。これは、純粋に構文解析/構文上の課題です。 入力には、スペースで分割することで解析を簡単にする回答を防ぐための空白はありません。 ただし、出力には、&&' のみ、または比較演算子と&&'の両方のいずれか、または両方を囲む単一のスペースがある場合がありますが、一貫性があります。 テストケース Input Output --------------------------------------------------------------- 3<4<5 3<4 && 4<5 3<4<5<6<7<8<9 3<4 && 4<5 && 5<6 && 6<7 && 7<8 && 8<9 3<5==6<19 3<5 && 5==6 && 6<19 10>=5<7!=20 10>=5 && 5<7 && …
9 code-golf  parsing  conversion  syntax  code-golf  sequence  primes  code-challenge  geometry  optimization  code-golf  graph-theory  code-golf  number-theory  primes  integer  code-golf  source-layout  cops-and-robbers  code-golf  source-layout  cops-and-robbers  code-golf  sequence  primes  integer  code-golf  math  number-theory  primes  rational-numbers  code-golf  math  sequence  number-theory  primes  code-golf  string  code-golf  math  combinatorics  permutations  restricted-complexity  code-golf  array-manipulation  code-golf  number  sequence  code-golf  number  sequence  code-golf  binary-matrix  code-golf  math  tips  javascript  algorithm  code-golf  string  code-golf  number  sequence  code-golf  math  arithmetic  parsing  code-golf  number  sequence  primes  code-golf  string  ascii-art  geometry  integer  code-golf  geometry  code-golf  number  array-manipulation  code-golf  math  geometry  code-golf  number  sequence  arithmetic  integer  code-golf  string  kolmogorov-complexity  code-golf  number  code-golf  number  chess  code-golf  sequence  decision-problem  subsequence  code-golf  math  number  primes  code-golf  primes  permutations  code-golf  integer  probability-theory  statistics  code-golf  string  code-golf  sequence  decision-problem  parsing  board-game  code-golf  binary  graph-theory  code-golf  board-game  classification  tic-tac-toe  code-golf  ascii-art  polyglot  code-golf  date  code-golf  geometry 

30
int入力nを指定して、n * reversed(n)を出力します
整数nを指定して出力n * reversed(n) reversed(n)は、reverseの桁を取得したときに取得する数値ですn。 reverse(512) = 215 reverse(1) = 1 reverse(101) = 101 >>>>>>>> func(5) = 5*5 = 25 func(12) = 12*21 = 252 func(11) = 11*11 = 121 func(659) = 659*956 = 630004 最短のコードが勝ちます! リーダーボード コードスニペットを表示 var QUESTION_ID=144816,OVERRIDE_USER=71625;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var …
9 code-golf  math  arithmetic  code-golf  math  integer  code-golf  arithmetic  integer  code-golf  sequence  base-conversion  palindrome  code-golf  math  primes  integer  code-golf  parsing  conversion  syntax  code-golf  sequence  primes  code-challenge  geometry  optimization  code-golf  graph-theory  code-golf  number-theory  primes  integer  code-golf  source-layout  cops-and-robbers  code-golf  source-layout  cops-and-robbers  code-golf  sequence  primes  integer  code-golf  math  number-theory  primes  rational-numbers  code-golf  math  sequence  number-theory  primes  code-golf  string  code-golf  math  combinatorics  permutations  restricted-complexity  code-golf  array-manipulation  code-golf  number  sequence  code-golf  number  sequence  code-golf  binary-matrix  code-golf  math  tips  javascript  algorithm  code-golf  string  code-golf  number  sequence  code-golf  math  arithmetic  parsing  code-golf  number  sequence  primes  code-golf  string  ascii-art  geometry  integer  code-golf  geometry  code-golf  number  array-manipulation  code-golf  math  geometry  code-golf  number  sequence  arithmetic  integer  code-golf  string  kolmogorov-complexity  code-golf  number  code-golf  number  chess  code-golf  sequence  decision-problem  subsequence  code-golf  math  number  primes  code-golf  primes  permutations  code-golf  integer  probability-theory  statistics  code-golf  string  code-golf  sequence  decision-problem  parsing  board-game  code-golf  binary  graph-theory  code-golf  board-game  classification  tic-tac-toe  code-golf  ascii-art  polyglot  code-golf  date  code-golf  geometry 

4
各列が1つのTrueになる行を見つけます(以前はKnuthのアルゴリズムX)。
仕事 ブール行列を指定して、各列にTrueが1つだけある行の1つ(またはオプションで複数)のサブセットを見つけます。任意のアルゴリズムを使用できますが、前の例のように非常に大きな行列をサポートする必要があります。 可能なアルゴリズムの1つ(KnuthのアルゴリズムX) このアルゴリズムを使用する必要はありませんが、これが最善のオプションになる場合があります。 行列Aに列がない場合、現在の部分解は有効な解です。正常に終了します。 それ以外の場合は、列cを選択します。 A r、c = 1となるような行rを選択します。 行rを部分解に含めます。 各列のためのJようにAのR、J = 1、 行ごとにIようにA 、I、J = 1、 削除行I行列からA。行列Aから 列jを削除します。 削減された行列Aに対してこのアルゴリズムを再帰的に繰り返します。 *ステップ3は非決定的であり、後でステップ3を呼び出して行を見つけられなかった場合に、バックトラックする必要があります。 入力 最小の2×2行列Aの任意の表現、たとえば数値またはブール配列 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 0 1 1 0 1 0 0 1 0 1 …
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.