summaryrefslogtreecommitdiff
path: root/Phone Book/A needle in the hay
diff options
context:
space:
mode:
Diffstat (limited to 'Phone Book/A needle in the hay')
-rw-r--r--Phone Book/A needle in the hay/task-info.yaml68
-rw-r--r--Phone Book/A needle in the hay/task-remote-info.yaml2
-rw-r--r--Phone Book/A needle in the hay/task.html26
3 files changed, 96 insertions, 0 deletions
diff --git a/Phone Book/A needle in the hay/task-info.yaml b/Phone Book/A needle in the hay/task-info.yaml
new file mode 100644
index 0000000..ae3121b
--- /dev/null
+++ b/Phone Book/A needle in the hay/task-info.yaml
@@ -0,0 +1,68 @@
+type: edu
+custom_name: stage1
+files:
+- name: src/phonebook/Main.java
+ visible: true
+ text: |
+ package phonebook;
+
+ public class Main {
+ public static void main(String[] args) {
+ System.out.println("Hello World!");
+ }
+ }
+ learner_created: false
+- name: test/PhoneBookTest.java
+ visible: false
+ text: "import org.hyperskill.hstest.stage.StageTest;\nimport org.hyperskill.hstest.testcase.CheckResult;\n\
+ import org.hyperskill.hstest.testcase.TestCase;\n\nimport java.util.Arrays;\n\
+ import java.util.List;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\
+ \npublic class PhoneBookTest extends StageTest {\n\n private long timeOnTestStart;\n\
+ \ private static String outputFirstTest;\n \n @Override\n public List<TestCase>\
+ \ generate() {\n timeOnTestStart = System.currentTimeMillis();\n \
+ \ return Arrays.asList(\n new TestCase<>().setTimeLimit(30 * 60\
+ \ * 1000),\n new TestCase<>().setTimeLimit(30 * 60 * 1000).setCheckFunc((reply,\
+ \ attach) -> {\n if (reply.equals(outputFirstTest)) {\n \
+ \ return CheckResult.wrong(\n \"\
+ Your program output is exactly the same during different runs. \" +\n \
+ \ \"Does your program just output a string?\"\n \
+ \ );\n\n }\n return CheckResult.correct();\n\
+ \ })\n );\n }\n \n private CheckResult checkPhrases(String\
+ \ reply, String... phrases) {\n reply = reply.toLowerCase();\n for\
+ \ (String phrase : phrases) {\n if (!reply.contains(phrase.toLowerCase()))\
+ \ {\n return CheckResult.wrong(\"Not found the part `\" + phrase\
+ \ + \"` in your output.\");\n }\n }\n return CheckResult.correct();\n\
+ \ }\n \n private Pattern timePattern = Pattern.compile(\".*(\\\\d+)\\\
+ \\s*min.*?(\\\\d+)\\\\s*sec.*?(\\\\d+)\\\\s*ms.*\", Pattern.DOTALL);\n \n \
+ \ // returns -1 if not matches.\n private long getUserEstimatedTime(String\
+ \ reply) {\n Matcher matcher = timePattern.matcher(reply);\n if\
+ \ (!matcher.matches()) {\n return -1;\n }\n int min =\
+ \ Integer.parseInt(matcher.group(1));\n int sec = Integer.parseInt(matcher.group(2));\n\
+ \ int ms = Integer.parseInt(matcher.group(3));\n \n return\
+ \ ms + sec * 1000 + min * 1000 * 60;\n }\n \n @Override\n public CheckResult\
+ \ check(String reply, Object clue) {\n\n outputFirstTest = reply;\n\n \
+ \ long realTime = System.currentTimeMillis() - timeOnTestStart;\n \
+ \ timeOnTestStart = System.currentTimeMillis();\n// System.out.println(\"\
+ Time delta: \" + realTime);\n \n if (!reply.contains(\"500 / 500\"\
+ ) && !reply.contains(\"500/500\")) {\n return CheckResult.wrong(\"\
+ Your output should contain `500 / 500` fragment.\");\n }\n \n \
+ \ CheckResult res = checkPhrases(reply, \"start searching\", \"found\",\n\
+ \ \"min.\", \"sec.\", \"ms.\");\n if (!res.isCorrect())\
+ \ {\n return res;\n }\n long estimatedTime = getUserEstimatedTime(reply);\n\
+ \ if (estimatedTime == -1) {\n return CheckResult.wrong(\"Your\
+ \ output format doesn't contain numbers before min, sec, ms words.\");\n \
+ \ }\n \n if (realTime < 1000) {\n return CheckResult.wrong(\"\
+ Your program completes too fast. Faster than a second!\");\n }\n \
+ \ \n double ratio = estimatedTime / (realTime + 0.0);\n if (ratio\
+ \ < 0.5 || ratio > 1.5) {\n return CheckResult.wrong(\"Too large difference\
+ \ between the real working time and your output. \" +\n \"\
+ Real program working time was \" + realTime + \" ms, and your output contained\
+ \ \" + estimatedTime + \"ms in total.\");\n }\n \n return\
+ \ CheckResult.correct();\n }\n}\n"
+ learner_created: false
+feedback_link: https://hyperskill.org/projects/63/stages/340/implement#comment
+status: Solved
+feedback:
+ message: Congratulations!
+ time: Wed, 27 Apr 2022 15:20:47 UTC
+record: -1
diff --git a/Phone Book/A needle in the hay/task-remote-info.yaml b/Phone Book/A needle in the hay/task-remote-info.yaml
new file mode 100644
index 0000000..93b8bed
--- /dev/null
+++ b/Phone Book/A needle in the hay/task-remote-info.yaml
@@ -0,0 +1,2 @@
+id: 5482
+update_date: Fri, 11 Mar 2022 08:50:15 UTC
diff --git a/Phone Book/A needle in the hay/task.html b/Phone Book/A needle in the hay/task.html
new file mode 100644
index 0000000..dcfb2dd
--- /dev/null
+++ b/Phone Book/A needle in the hay/task.html
@@ -0,0 +1,26 @@
+<h5 style="text-align: center;" id="description">Description</h5>
+
+<p>Have you ever had to use one of those 2000+ page phone books full of various organizations and people's names, written in a small font and with multiple columns on each page? Finding the information you need in such books can be an ordeal. In fact, even computers struggle to search through the millions of entries in a directory.</p>
+
+<p>In this project, you will create a phone book, implementing several algorithms, and comparing their efficiency when using a big dataset.</p>
+
+<p>For this, you will need to download the file <a target="_blank" target="_blank" href="https://stepik.org/media/attachments/lesson/197761/directory.txt" rel="nofollow noopener noreferrer">directory.txt</a> that contains the phone numbers of over a million people in multiple cities.</p>
+
+<p>At this stage, you should implement the simplest possible search to find the numbers of a few people whose names are listed in the file <a target="_blank" target="_blank" href="https://stepik.org/media/attachments/lesson/197761/find.txt" rel="nofollow noopener noreferrer">find.txt</a>.</p>
+
+<p>It takes a time to find all the records from the big file. We recommend you manually test your program with the simplified data: <a target="_blank" target="_blank" href="https://stepik.org/media/attachments/lesson/210117/small_directory.txt" rel="noopener noreferrer nofollow">small_directory.txt</a> and <a target="_blank" target="_blank" href="https://stepik.org/media/attachments/lesson/210117/small_find.txt" rel="noopener noreferrer nofollow">small_find.txt</a>. But to pass all the tests you have to work with the big files above.</p>
+
+<p>Note how long it takes you to do this when using a linear search so that you can compare results with other search methods.</p>
+
+<p>To measure the time difference, you can use <code class="java">System.currentTimeMillis()</code>.</p>
+
+<p>Also notice that you don't need to read the file "directory.txt" again and again after each query. You should load all lines into memory and measure only the search process.</p>
+
+<p><div class="alert alert-warning">Please, do not keep the downloaded files inside your project directory because the server can reject large files and you will see the message <strong>"Failed to post submission to the Hyperskill"</strong>.</div></p>
+
+<h5 style="text-align: center;" id="example">Example</h5>
+
+<p>Below is an example of how your output should look:</p>
+
+<pre><code class="java">Start searching...
+Found 500 / 500 entries. Time taken: 1 min. 56 sec. 328 ms.</code></pre> \ No newline at end of file