{"action":"created","comment":{"url":"https://api.github.com/repos/fbocharov/au-java/pulls/comments/59975986","id":59975986,"diff_hunk":"@@ -0,0 +1,87 @@\n+package ru.spbau.bocharov.streams;\n+\n+import java.io.IOException;\n+import java.nio.file.Files;\n+import java.nio.file.Paths;\n+import java.util.*;\n+import java.util.stream.Collectors;\n+import java.util.stream.DoubleStream;\n+import java.util.stream.Stream;\n+\n+import static java.util.stream.Collectors.toList;\n+\n+public final class SecondPartTasks {\n+\n+    private SecondPartTasks() {}\n+\n+    // Найти строки из переданных файлов, в которых встречается указанная подстрока.\n+    public static List<String> findQuotes(List<String> paths, CharSequence sequence) {\n+        return paths.stream()\n+                    .map(SecondPartTasks::safeLines)\n+                    .flatMap(Collection::stream)\n+                    .filter(line -> line.contains(sequence))\n+                    .collect(toList());\n+    }\n+\n+    // В квадрат с длиной стороны 1 вписана мишень.\n+    // Стрелок атакует мишень и каждый раз попадает в произвольную точку квадрата.\n+    // Надо промоделировать этот процесс с помощью класса java.util.Random и посчитать, какова вероятность попасть в мишень.\n+    public static double piDividedBy4() {\n+        return zipSubstracted(new Random().doubles(), new Random().doubles())\n+                .limit(SHOT_COUNT)\n+                .filter(p -> p.x * p.x + p.y * p.y <= TARGET_RADIUS * TARGET_RADIUS)\n+                .count() / (double) SHOT_COUNT;\n+    }\n+\n+    // Дано отображение из имени автора в список с содержанием его произведений.\n+    // Надо вычислить, чья общая длина произведений наибольшая.\n+    public static String findPrinter(Map<String, List<String>> compositions) {\n+        return compositions.entrySet()\n+                           .stream()\n+                           .max(Comparator.comparing(e -> e.getValue().stream().mapToInt(String::length).sum()))\n+                           .map(Map.Entry::getKey)\n+                           .orElse(\"\");\n+    }\n+\n+    // Вы крупный поставщик продуктов. Каждая торговая сеть делает вам заказ в виде Map<Товар, Количество>.\n+    // Необходимо вычислить, какой товар и в каком количестве надо поставить.\n+    public static Map<String, Integer> calculateGlobalOrder(List<Map<String, Integer>> orders) {\n+        return orders.stream()\n+                     .map(Map::entrySet)\n+                     .flatMap(Collection::stream)\n+                     .collect(Collectors.toMap(\n+                            Map.Entry::getKey,\n+                            Map.Entry::getValue,\n+                            Integer::sum));\n+    }\n+\n+    private static final int SHOT_COUNT = 10000;\n+    private static final double TARGET_RADIUS = 0.5;\n+\n+    private static List<String> safeLines(String path) {\n+        try (Stream<String> lines = Files.lines(Paths.get(path))) {\n+            return lines.collect(toList());\n+        } catch (IOException e) {\n+            throw new RuntimeException(e.getMessage());\n+        }\n+    }\n+\n+    private static Stream<Pair> zipSubstracted(DoubleStream left, DoubleStream right) {\n+        Iterator<Double> leftIterator = left.iterator();\n+        Iterator<Double> rightIterator = right.iterator();\n+\n+        return Stream.generate(() -> new Pair(leftIterator.next()  - TARGET_RADIUS,\n+                                              rightIterator.next() - TARGET_RADIUS));\n+    }\n+\n+    private static class Pair {\n+        private double x;\n+        private double y;","path":"hw/streams/src/main/java/ru/spbau/bocharov/streams/SecondPartTasks.java","position":79,"original_position":79,"commit_id":"57f4883a93ec33fa520f215f0d82925378556b1d","original_commit_id":"57f4883a93ec33fa520f215f0d82925378556b1d","user":{"login":"sproshev","id":4990763,"avatar_url":"https://avatars.githubusercontent.com/u/4990763?v=3","gravatar_id":"","url":"https://api.github.com/users/sproshev","html_url":"https://github.com/sproshev","followers_url":"https://api.github.com/users/sproshev/followers","following_url":"https://api.github.com/users/sproshev/following{/other_user}","gists_url":"https://api.github.com/users/sproshev/gists{/gist_id}","starred_url":"https://api.github.com/users/sproshev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sproshev/subscriptions","organizations_url":"https://api.github.com/users/sproshev/orgs","repos_url":"https://api.github.com/users/sproshev/repos","events_url":"https://api.github.com/users/sproshev/events{/privacy}","received_events_url":"https://api.github.com/users/sproshev/received_events","type":"User","site_admin":false},"body":"final, -0.5","created_at":"2016-04-17T00:08:36Z","updated_at":"2016-04-17T00:08:36Z","html_url":"https://github.com/fbocharov/au-java/pull/4#discussion_r59975986","pull_request_url":"https://api.github.com/repos/fbocharov/au-java/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/fbocharov/au-java/pulls/comments/59975986"},"html":{"href":"https://github.com/fbocharov/au-java/pull/4#discussion_r59975986"},"pull_request":{"href":"https://api.github.com/repos/fbocharov/au-java/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/fbocharov/au-java/pulls/4","id":65877862,"html_url":"https://github.com/fbocharov/au-java/pull/4","diff_url":"https://github.com/fbocharov/au-java/pull/4.diff","patch_url":"https://github.com/fbocharov/au-java/pull/4.patch","issue_url":"https://api.github.com/repos/fbocharov/au-java/issues/4","number":4,"state":"open","locked":false,"title":"Java05. ДЗ 04, Бочаров Федор","user":{"login":"fbocharov","id":4655777,"avatar_url":"https://avatars.githubusercontent.com/u/4655777?v=3","gravatar_id":"","url":"https://api.github.com/users/fbocharov","html_url":"https://github.com/fbocharov","followers_url":"https://api.github.com/users/fbocharov/followers","following_url":"https://api.github.com/users/fbocharov/following{/other_user}","gists_url":"https://api.github.com/users/fbocharov/gists{/gist_id}","starred_url":"https://api.github.com/users/fbocharov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbocharov/subscriptions","organizations_url":"https://api.github.com/users/fbocharov/orgs","repos_url":"https://api.github.com/users/fbocharov/repos","events_url":"https://api.github.com/users/fbocharov/events{/privacy}","received_events_url":"https://api.github.com/users/fbocharov/received_events","type":"User","site_admin":false},"body":"@sproshev, review this pr, please","created_at":"2016-04-09T10:50:45Z","updated_at":"2016-04-17T00:08:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d0a48accd0cf000b1ace9c3f280fb1d3a7ffbacb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/fbocharov/au-java/pulls/4/commits","review_comments_url":"https://api.github.com/repos/fbocharov/au-java/pulls/4/comments","review_comment_url":"https://api.github.com/repos/fbocharov/au-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fbocharov/au-java/issues/4/comments","statuses_url":"https://api.github.com/repos/fbocharov/au-java/statuses/57f4883a93ec33fa520f215f0d82925378556b1d","head":{"label":"fbocharov:hw04","ref":"hw04","sha":"57f4883a93ec33fa520f215f0d82925378556b1d","user":{"login":"fbocharov","id":4655777,"avatar_url":"https://avatars.githubusercontent.com/u/4655777?v=3","gravatar_id":"","url":"https://api.github.com/users/fbocharov","html_url":"https://github.com/fbocharov","followers_url":"https://api.github.com/users/fbocharov/followers","following_url":"https://api.github.com/users/fbocharov/following{/other_user}","gists_url":"https://api.github.com/users/fbocharov/gists{/gist_id}","starred_url":"https://api.github.com/users/fbocharov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbocharov/subscriptions","organizations_url":"https://api.github.com/users/fbocharov/orgs","repos_url":"https://api.github.com/users/fbocharov/repos","events_url":"https://api.github.com/users/fbocharov/events{/privacy}","received_events_url":"https://api.github.com/users/fbocharov/received_events","type":"User","site_admin":false},"repo":{"id":51925815,"name":"au-java","full_name":"fbocharov/au-java","owner":{"login":"fbocharov","id":4655777,"avatar_url":"https://avatars.githubusercontent.com/u/4655777?v=3","gravatar_id":"","url":"https://api.github.com/users/fbocharov","html_url":"https://github.com/fbocharov","followers_url":"https://api.github.com/users/fbocharov/followers","following_url":"https://api.github.com/users/fbocharov/following{/other_user}","gists_url":"https://api.github.com/users/fbocharov/gists{/gist_id}","starred_url":"https://api.github.com/users/fbocharov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbocharov/subscriptions","organizations_url":"https://api.github.com/users/fbocharov/orgs","repos_url":"https://api.github.com/users/fbocharov/repos","events_url":"https://api.github.com/users/fbocharov/events{/privacy}","received_events_url":"https://api.github.com/users/fbocharov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fbocharov/au-java","description":"Homeworks for Java language course in SPbAU.","fork":false,"url":"https://api.github.com/repos/fbocharov/au-java","forks_url":"https://api.github.com/repos/fbocharov/au-java/forks","keys_url":"https://api.github.com/repos/fbocharov/au-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fbocharov/au-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fbocharov/au-java/teams","hooks_url":"https://api.github.com/repos/fbocharov/au-java/hooks","issue_events_url":"https://api.github.com/repos/fbocharov/au-java/issues/events{/number}","events_url":"https://api.github.com/repos/fbocharov/au-java/events","assignees_url":"https://api.github.com/repos/fbocharov/au-java/assignees{/user}","branches_url":"https://api.github.com/repos/fbocharov/au-java/branches{/branch}","tags_url":"https://api.github.com/repos/fbocharov/au-java/tags","blobs_url":"https://api.github.com/repos/fbocharov/au-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fbocharov/au-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fbocharov/au-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/fbocharov/au-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fbocharov/au-java/statuses/{sha}","languages_url":"https://api.github.com/repos/fbocharov/au-java/languages","stargazers_url":"https://api.github.com/repos/fbocharov/au-java/stargazers","contributors_url":"https://api.github.com/repos/fbocharov/au-java/contributors","subscribers_url":"https://api.github.com/repos/fbocharov/au-java/subscribers","subscription_url":"https://api.github.com/repos/fbocharov/au-java/subscription","commits_url":"https://api.github.com/repos/fbocharov/au-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/fbocharov/au-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/fbocharov/au-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/fbocharov/au-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/fbocharov/au-java/contents/{+path}","compare_url":"https://api.github.com/repos/fbocharov/au-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fbocharov/au-java/merges","archive_url":"https://api.github.com/repos/fbocharov/au-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fbocharov/au-java/downloads","issues_url":"https://api.github.com/repos/fbocharov/au-java/issues{/number}","pulls_url":"https://api.github.com/repos/fbocharov/au-java/pulls{/number}","milestones_url":"https://api.github.com/repos/fbocharov/au-java/milestones{/number}","notifications_url":"https://api.github.com/repos/fbocharov/au-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fbocharov/au-java/labels{/name}","releases_url":"https://api.github.com/repos/fbocharov/au-java/releases{/id}","deployments_url":"https://api.github.com/repos/fbocharov/au-java/deployments","created_at":"2016-02-17T13:49:17Z","updated_at":"2016-04-08T13:39:14Z","pushed_at":"2016-04-09T10:50:45Z","git_url":"git://github.com/fbocharov/au-java.git","ssh_url":"git@github.com:fbocharov/au-java.git","clone_url":"https://github.com/fbocharov/au-java.git","svn_url":"https://github.com/fbocharov/au-java","homepage":null,"size":32,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"fbocharov:master","ref":"master","sha":"7ac10912c28eace28bacf675680a23fb2ebb868c","user":{"login":"fbocharov","id":4655777,"avatar_url":"https://avatars.githubusercontent.com/u/4655777?v=3","gravatar_id":"","url":"https://api.github.com/users/fbocharov","html_url":"https://github.com/fbocharov","followers_url":"https://api.github.com/users/fbocharov/followers","following_url":"https://api.github.com/users/fbocharov/following{/other_user}","gists_url":"https://api.github.com/users/fbocharov/gists{/gist_id}","starred_url":"https://api.github.com/users/fbocharov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbocharov/subscriptions","organizations_url":"https://api.github.com/users/fbocharov/orgs","repos_url":"https://api.github.com/users/fbocharov/repos","events_url":"https://api.github.com/users/fbocharov/events{/privacy}","received_events_url":"https://api.github.com/users/fbocharov/received_events","type":"User","site_admin":false},"repo":{"id":51925815,"name":"au-java","full_name":"fbocharov/au-java","owner":{"login":"fbocharov","id":4655777,"avatar_url":"https://avatars.githubusercontent.com/u/4655777?v=3","gravatar_id":"","url":"https://api.github.com/users/fbocharov","html_url":"https://github.com/fbocharov","followers_url":"https://api.github.com/users/fbocharov/followers","following_url":"https://api.github.com/users/fbocharov/following{/other_user}","gists_url":"https://api.github.com/users/fbocharov/gists{/gist_id}","starred_url":"https://api.github.com/users/fbocharov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbocharov/subscriptions","organizations_url":"https://api.github.com/users/fbocharov/orgs","repos_url":"https://api.github.com/users/fbocharov/repos","events_url":"https://api.github.com/users/fbocharov/events{/privacy}","received_events_url":"https://api.github.com/users/fbocharov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fbocharov/au-java","description":"Homeworks for Java language course in SPbAU.","fork":false,"url":"https://api.github.com/repos/fbocharov/au-java","forks_url":"https://api.github.com/repos/fbocharov/au-java/forks","keys_url":"https://api.github.com/repos/fbocharov/au-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fbocharov/au-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fbocharov/au-java/teams","hooks_url":"https://api.github.com/repos/fbocharov/au-java/hooks","issue_events_url":"https://api.github.com/repos/fbocharov/au-java/issues/events{/number}","events_url":"https://api.github.com/repos/fbocharov/au-java/events","assignees_url":"https://api.github.com/repos/fbocharov/au-java/assignees{/user}","branches_url":"https://api.github.com/repos/fbocharov/au-java/branches{/branch}","tags_url":"https://api.github.com/repos/fbocharov/au-java/tags","blobs_url":"https://api.github.com/repos/fbocharov/au-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fbocharov/au-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fbocharov/au-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/fbocharov/au-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fbocharov/au-java/statuses/{sha}","languages_url":"https://api.github.com/repos/fbocharov/au-java/languages","stargazers_url":"https://api.github.com/repos/fbocharov/au-java/stargazers","contributors_url":"https://api.github.com/repos/fbocharov/au-java/contributors","subscribers_url":"https://api.github.com/repos/fbocharov/au-java/subscribers","subscription_url":"https://api.github.com/repos/fbocharov/au-java/subscription","commits_url":"https://api.github.com/repos/fbocharov/au-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/fbocharov/au-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/fbocharov/au-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/fbocharov/au-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/fbocharov/au-java/contents/{+path}","compare_url":"https://api.github.com/repos/fbocharov/au-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fbocharov/au-java/merges","archive_url":"https://api.github.com/repos/fbocharov/au-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fbocharov/au-java/downloads","issues_url":"https://api.github.com/repos/fbocharov/au-java/issues{/number}","pulls_url":"https://api.github.com/repos/fbocharov/au-java/pulls{/number}","milestones_url":"https://api.github.com/repos/fbocharov/au-java/milestones{/number}","notifications_url":"https://api.github.com/repos/fbocharov/au-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fbocharov/au-java/labels{/name}","releases_url":"https://api.github.com/repos/fbocharov/au-java/releases{/id}","deployments_url":"https://api.github.com/repos/fbocharov/au-java/deployments","created_at":"2016-02-17T13:49:17Z","updated_at":"2016-04-08T13:39:14Z","pushed_at":"2016-04-09T10:50:45Z","git_url":"git://github.com/fbocharov/au-java.git","ssh_url":"git@github.com:fbocharov/au-java.git","clone_url":"https://github.com/fbocharov/au-java.git","svn_url":"https://github.com/fbocharov/au-java","homepage":null,"size":32,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/fbocharov/au-java/pulls/4"},"html":{"href":"https://github.com/fbocharov/au-java/pull/4"},"issue":{"href":"https://api.github.com/repos/fbocharov/au-java/issues/4"},"comments":{"href":"https://api.github.com/repos/fbocharov/au-java/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/fbocharov/au-java/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/fbocharov/au-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fbocharov/au-java/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/fbocharov/au-java/statuses/57f4883a93ec33fa520f215f0d82925378556b1d"}}}}