binary-search/Solution.java: prints -1 when the target is the last element (`9 1 3 5 7 9`) or in a 1-element list (`5 5`)
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
The bug is in problems/binary-search/Solution.java, where the search reports -1 once it narrows to a single position. Check linked pull request #30 first, since work is already under way. Done means 9 1 3 5 7 9 prints 4, 5 5 prints 0, and 3 1 3 prints 1, with those cases added to cases.txt and python3 run.py binary-search passing.
索引モデルが issue の本文から書いたものです。
説明
What I did
- Fresh checkout of
main, JDK 17. - Compile the Java solution and run it on a few inputs (the input is one line: the target, then the sorted list):
cd problems/binary-search
javac Solution.java
echo "9 1 3 5 7 9" | java Solution
echo "5 5" | java Solution
echo "3 1 3" | java Solution
echo "3 1 3 5" | java Solution
- For comparison, the Python solution:
echo "9 1 3 5 7 9" | python3 solution.py
What I expected
The problem README says: "Print the position (starting from 0) of the target in the list, or -1 if it isn't there." (problems/binary-search/README.md)
So 9 1 3 5 7 9 should print 4, 5 5 should print 0, 3 1 3 should print 1, and 3 1 3 5 should print 1.
What happened instead
9 1 3 5 7 9 -> -1 (expected 4)
5 5 -> -1 (expected 0)
3 1 3 -> -1 (expected 1)
3 1 3 5 -> 1 (correct)
The target is found, then reported as missing, whenever the search narrows to a single position. The Python and C++ solutions print the right answer for all of these. python3 run.py binary-search passes today because none of the cases in cases.txt ends the search on a single remaining position.
Environment
code-corner main @ 0c95800, JDK 17, Windows 11.
I'd like to work on the fix for this, and add the failing inputs to cases.txt as the Contributing section asks.
- 主要言語
- Python
- スター
- 1
- フォーク
- 6
- 平均マージ
- 17時間 52分
- マージ済み PR(30日)
- 14
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
techcsispit/code-corner のほかの issue
-
prime/solution.java doesn't compile: public class PrimeCheck in solution.java, README requires Solution.java with a Solution class対応中かも @tanujb03 が 1 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
techcsispit/code-corner#35 ·
メンテナーはふだん 1 日以内に返信
-
Prime solution in C++ incorrectly returns true for some composite numbers対応中かも @paramsj が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 25/100
techcsispit/code-corner#38 ·
メンテナーはふだん 1 日以内に返信
-
Failed compilations always report 0.000 seconds対応中かも @Shivangi-singh18 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
techcsispit/code-corner#37 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
run.py: Python solutions are skipped on Windows when run via python instead of python3対応中かも @tanujb03 が 1 日前に担当しました。 オープンbug good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 15/100
techcsispit/code-corner#29 ·
メンテナーはふだん 1 日以内に返信
-
fibonacci/solution.c: prints negative numbers for n of 47 or more (F(90) prints -1581614984)対応中かも @tanujb03 が 1 日前に担当しました。 オープンbug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
techcsispit/code-corner#27 ·
メンテナーはふだん 1 日以内に返信
techcsispit/code-corner の issue をすべて見る
似ている issue
-
docs pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pydantic/pydantic-ai#10113 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
GreedyBear-Project/GreedyBear#1727 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
ARM-software/CMSIS-DSP#354 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
kiat/codeAssist#391 ·
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
darnitdevorg/darnit#587 ·
メンテナーはふだん 1 日以内に返信