{"action":"created","comment":{"url":"https://api.github.com/repos/javaslang/javaslang/pulls/comments/71468675","id":71468675,"diff_hunk":"@@ -0,0 +1,123 @@\n+/*     / \\____  _    _  ____   ______  / \\ ____  __    _______\n+ *    /  /    \\/ \\  / \\/    \\ /  /\\__\\/  //    \\/  \\  //  /\\__\\   JΛVΛSLΛNG\n+ *  _/  /  /\\  \\  \\/  /  /\\  \\\\__\\\\  \\  //  /\\  \\ /\\\\/ \\ /__\\ \\   Copyright 2014-2016 Javaslang, http://javaslang.io\n+ * /___/\\_/  \\_/\\____/\\_/  \\_/\\__\\/__/\\__\\_/  \\_//  \\__/\\_____/   Licensed under the Apache License, Version 2.0\n+ */\n+package javaslang.collection.euler;\n+\n+import java.math.BigDecimal;\n+import java.math.RoundingMode;\n+import javaslang.Function1;\n+import javaslang.Tuple;\n+import javaslang.Tuple2;\n+import javaslang.collection.CharSeq;\n+import javaslang.collection.List;\n+import javaslang.collection.Stream;\n+import org.junit.Test;\n+\n+import javaslang.control.Option;\n+\n+import static org.assertj.core.api.Assertions.assertThat;\n+\n+/**\n+ * <strong>Problem 26: Reciprocal cycles</strong>\n+ * <p>\n+ * A unit fraction contains 1 in the numerator. The decimal representation of\n+ * the unit fractions with denominators 2 to 10 are given:\n+ * <pre>\n+ * 1/2\t= 0.5\n+ * 1/3\t= 0.(3)\n+ * 1/4\t= 0.25\n+ * 1/5\t= 0.2\n+ * 1/6\t= 0.1(6)\n+ * 1/7\t= 0.(142857)\n+ * 1/8\t= 0.125\n+ * 1/9\t= 0.(1)\n+ * 1/10\t= 0.1\n+ * </pre> Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It\n+ * can be seen that 1/7 has a 6-digit recurring cycle.\n+ * <p>\n+ * Find the value of d < 1000 for which 1/d contains the longest recurring cycle\n+ * in its decimal fraction part. <p>\n+ * See also\n+ * <a href=\"https://projecteuler.net/problem=26\">projecteuler.net problem 26\n+ * </a>.\n+ */\n+public class Euler26Test {\n+\n+    @Test\n+    public void shouldSolveProblem26() {\n+        assertThat(recurringCycleLengthForDivisionOf1(2)._2).isEqualTo(0);\n+        assertThat(recurringCycleLengthForDivisionOf1(3)._2).isEqualTo(1);\n+        assertThat(recurringCycleLengthForDivisionOf1(4)._2).isEqualTo(0);\n+        assertThat(recurringCycleLengthForDivisionOf1(5)._2).isEqualTo(0);\n+        assertThat(recurringCycleLengthForDivisionOf1(6)._2).isEqualTo(1);\n+        assertThat(recurringCycleLengthForDivisionOf1(7)._2).isEqualTo(6);\n+        assertThat(recurringCycleLengthForDivisionOf1(8)._2).isEqualTo(0);\n+        assertThat(recurringCycleLengthForDivisionOf1(9)._2).isEqualTo(1);\n+        assertThat(recurringCycleLengthForDivisionOf1(10)._2).isEqualTo(0);\n+        assertThat(deonominatorBelow1000WithTheLongetsRecurringCycleOfDecimalFractions()).isEqualTo(983);\n+    }\n+\n+    private static int deonominatorBelow1000WithTheLongetsRecurringCycleOfDecimalFractions() {\n+        return List.range(2, 1000)\n+                .map(Euler26Test::recurringCycleLengthForDivisionOf1)\n+                .maxBy(Tuple2::_2)\n+                .get()._1;\n+    }\n+\n+    private static Tuple2<Integer, Integer> recurringCycleLengthForDivisionOf1(int divisor) {\n+        return Tuple.of(\n+                divisor,\n+                recurringCycleLengthInDecimalFractionPart(\n+                        CharSeq.of(BigDecimal.ONE.divide(BigDecimal.valueOf(divisor), 2000, RoundingMode.UP).toString())\n+                        .transform(removeLeadingZeroAndDecimalPoint())\n+                        .transform(removeRoundingDigit())\n+                        .transform(removeTrailingZeroes())\n+                        .mkString()\n+                ));\n+    }\n+\n+    private static int recurringCycleLengthInDecimalFractionPart(String decimalFractionPart) {\n+        return CharSeq.of(decimalFractionPart)\n+                .reverse()\n+                .toStream() // Stream is lazy evaluated which ensures the rest is only evaluated until the recurring cycle is found.\n+                .transform(createCandidateCycles())\n+                .transform(removeCandidatesLongerThanHalfTheFullString(decimalFractionPart))\n+                .transform(findFirstRecurringCycle(decimalFractionPart))\n+                .map(String::length)\n+                .getOrElse(0);\n+    }\n+\n+    private static Function1<CharSeq, CharSeq> removeLeadingZeroAndDecimalPoint() {\n+        return seq -> seq.drop(2);\n+    }\n+\n+    private static Function1<CharSeq, CharSeq> removeRoundingDigit() {\n+        return seq -> seq.dropRight(1);\n+    }\n+\n+    private static Function1<CharSeq, CharSeq> removeTrailingZeroes() {\n+        return seq -> seq\n+                .reverse()\n+                .dropWhile(c -> Character.valueOf('0').equals(c)) //Remove any trailing zeroes","path":"javaslang/src/test/java/javaslang/collection/euler/Euler26Test.java","position":103,"original_position":103,"commit_id":"0b6d0aa7397d9eaafa8821f00ab6f1357e1bb77f","original_commit_id":"0b6d0aa7397d9eaafa8821f00ab6f1357e1bb77f","user":{"login":"danieldietrich","id":743833,"avatar_url":"https://avatars.githubusercontent.com/u/743833?v=3","gravatar_id":"","url":"https://api.github.com/users/danieldietrich","html_url":"https://github.com/danieldietrich","followers_url":"https://api.github.com/users/danieldietrich/followers","following_url":"https://api.github.com/users/danieldietrich/following{/other_user}","gists_url":"https://api.github.com/users/danieldietrich/gists{/gist_id}","starred_url":"https://api.github.com/users/danieldietrich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danieldietrich/subscriptions","organizations_url":"https://api.github.com/users/danieldietrich/orgs","repos_url":"https://api.github.com/users/danieldietrich/repos","events_url":"https://api.github.com/users/danieldietrich/events{/privacy}","received_events_url":"https://api.github.com/users/danieldietrich/received_events","type":"User","site_admin":false},"body":"Does unboxing work: `.dropWhile(c -> c == '0')`?","created_at":"2016-07-20T05:46:38Z","updated_at":"2016-07-20T05:46:38Z","html_url":"https://github.com/javaslang/javaslang/pull/1453#discussion_r71468675","pull_request_url":"https://api.github.com/repos/javaslang/javaslang/pulls/1453","_links":{"self":{"href":"https://api.github.com/repos/javaslang/javaslang/pulls/comments/71468675"},"html":{"href":"https://github.com/javaslang/javaslang/pull/1453#discussion_r71468675"},"pull_request":{"href":"https://api.github.com/repos/javaslang/javaslang/pulls/1453"}}},"pull_request":{"url":"https://api.github.com/repos/javaslang/javaslang/pulls/1453","id":77920849,"html_url":"https://github.com/javaslang/javaslang/pull/1453","diff_url":"https://github.com/javaslang/javaslang/pull/1453.diff","patch_url":"https://github.com/javaslang/javaslang/pull/1453.patch","issue_url":"https://api.github.com/repos/javaslang/javaslang/issues/1453","number":1453,"state":"open","locked":false,"title":"Added solution for Euler number 26","user":{"login":"jorander","id":3429824,"avatar_url":"https://avatars.githubusercontent.com/u/3429824?v=3","gravatar_id":"","url":"https://api.github.com/users/jorander","html_url":"https://github.com/jorander","followers_url":"https://api.github.com/users/jorander/followers","following_url":"https://api.github.com/users/jorander/following{/other_user}","gists_url":"https://api.github.com/users/jorander/gists{/gist_id}","starred_url":"https://api.github.com/users/jorander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorander/subscriptions","organizations_url":"https://api.github.com/users/jorander/orgs","repos_url":"https://api.github.com/users/jorander/repos","events_url":"https://api.github.com/users/jorander/events{/privacy}","received_events_url":"https://api.github.com/users/jorander/received_events","type":"User","site_admin":false},"body":"The solution uses two rather long chains of manipulation of CharSeq/Stream and I thought it got the code hard to read. In order to make the main methods easier to read I experimented with using #transform() as a way to encapsulate manipulations with a common goal without breaking the laziness of Stream. I think I got an pretty good result. What do you think about such an approach?","created_at":"2016-07-19T05:47:38Z","updated_at":"2016-07-20T05:46:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88c87ad7ea5276aae9d2d0e9b71c837fa4b2d96c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/javaslang/javaslang/pulls/1453/commits","review_comments_url":"https://api.github.com/repos/javaslang/javaslang/pulls/1453/comments","review_comment_url":"https://api.github.com/repos/javaslang/javaslang/pulls/comments{/number}","comments_url":"https://api.github.com/repos/javaslang/javaslang/issues/1453/comments","statuses_url":"https://api.github.com/repos/javaslang/javaslang/statuses/0b6d0aa7397d9eaafa8821f00ab6f1357e1bb77f","head":{"label":"jorander:126_euler_number_26","ref":"126_euler_number_26","sha":"0b6d0aa7397d9eaafa8821f00ab6f1357e1bb77f","user":{"login":"jorander","id":3429824,"avatar_url":"https://avatars.githubusercontent.com/u/3429824?v=3","gravatar_id":"","url":"https://api.github.com/users/jorander","html_url":"https://github.com/jorander","followers_url":"https://api.github.com/users/jorander/followers","following_url":"https://api.github.com/users/jorander/following{/other_user}","gists_url":"https://api.github.com/users/jorander/gists{/gist_id}","starred_url":"https://api.github.com/users/jorander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorander/subscriptions","organizations_url":"https://api.github.com/users/jorander/orgs","repos_url":"https://api.github.com/users/jorander/repos","events_url":"https://api.github.com/users/jorander/events{/privacy}","received_events_url":"https://api.github.com/users/jorander/received_events","type":"User","site_admin":false},"repo":{"id":35902480,"name":"javaslang","full_name":"jorander/javaslang","owner":{"login":"jorander","id":3429824,"avatar_url":"https://avatars.githubusercontent.com/u/3429824?v=3","gravatar_id":"","url":"https://api.github.com/users/jorander","html_url":"https://github.com/jorander","followers_url":"https://api.github.com/users/jorander/followers","following_url":"https://api.github.com/users/jorander/following{/other_user}","gists_url":"https://api.github.com/users/jorander/gists{/gist_id}","starred_url":"https://api.github.com/users/jorander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorander/subscriptions","organizations_url":"https://api.github.com/users/jorander/orgs","repos_url":"https://api.github.com/users/jorander/repos","events_url":"https://api.github.com/users/jorander/events{/privacy}","received_events_url":"https://api.github.com/users/jorander/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jorander/javaslang","description":"Functional component library for Java 8+.","fork":true,"url":"https://api.github.com/repos/jorander/javaslang","forks_url":"https://api.github.com/repos/jorander/javaslang/forks","keys_url":"https://api.github.com/repos/jorander/javaslang/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jorander/javaslang/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jorander/javaslang/teams","hooks_url":"https://api.github.com/repos/jorander/javaslang/hooks","issue_events_url":"https://api.github.com/repos/jorander/javaslang/issues/events{/number}","events_url":"https://api.github.com/repos/jorander/javaslang/events","assignees_url":"https://api.github.com/repos/jorander/javaslang/assignees{/user}","branches_url":"https://api.github.com/repos/jorander/javaslang/branches{/branch}","tags_url":"https://api.github.com/repos/jorander/javaslang/tags","blobs_url":"https://api.github.com/repos/jorander/javaslang/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jorander/javaslang/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jorander/javaslang/git/refs{/sha}","trees_url":"https://api.github.com/repos/jorander/javaslang/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jorander/javaslang/statuses/{sha}","languages_url":"https://api.github.com/repos/jorander/javaslang/languages","stargazers_url":"https://api.github.com/repos/jorander/javaslang/stargazers","contributors_url":"https://api.github.com/repos/jorander/javaslang/contributors","subscribers_url":"https://api.github.com/repos/jorander/javaslang/subscribers","subscription_url":"https://api.github.com/repos/jorander/javaslang/subscription","commits_url":"https://api.github.com/repos/jorander/javaslang/commits{/sha}","git_commits_url":"https://api.github.com/repos/jorander/javaslang/git/commits{/sha}","comments_url":"https://api.github.com/repos/jorander/javaslang/comments{/number}","issue_comment_url":"https://api.github.com/repos/jorander/javaslang/issues/comments{/number}","contents_url":"https://api.github.com/repos/jorander/javaslang/contents/{+path}","compare_url":"https://api.github.com/repos/jorander/javaslang/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jorander/javaslang/merges","archive_url":"https://api.github.com/repos/jorander/javaslang/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jorander/javaslang/downloads","issues_url":"https://api.github.com/repos/jorander/javaslang/issues{/number}","pulls_url":"https://api.github.com/repos/jorander/javaslang/pulls{/number}","milestones_url":"https://api.github.com/repos/jorander/javaslang/milestones{/number}","notifications_url":"https://api.github.com/repos/jorander/javaslang/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jorander/javaslang/labels{/name}","releases_url":"https://api.github.com/repos/jorander/javaslang/releases{/id}","deployments_url":"https://api.github.com/repos/jorander/javaslang/deployments","created_at":"2015-05-19T19:05:21Z","updated_at":"2016-07-02T20:54:53Z","pushed_at":"2016-07-19T05:41:38Z","git_url":"git://github.com/jorander/javaslang.git","ssh_url":"git@github.com:jorander/javaslang.git","clone_url":"https://github.com/jorander/javaslang.git","svn_url":"https://github.com/jorander/javaslang","homepage":"http://javaslang.com","size":12238,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"javaslang:master","ref":"master","sha":"81fa282f6102312e87f2f67615c615daa3746d22","user":{"login":"javaslang","id":5786132,"avatar_url":"https://avatars.githubusercontent.com/u/5786132?v=3","gravatar_id":"","url":"https://api.github.com/users/javaslang","html_url":"https://github.com/javaslang","followers_url":"https://api.github.com/users/javaslang/followers","following_url":"https://api.github.com/users/javaslang/following{/other_user}","gists_url":"https://api.github.com/users/javaslang/gists{/gist_id}","starred_url":"https://api.github.com/users/javaslang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javaslang/subscriptions","organizations_url":"https://api.github.com/users/javaslang/orgs","repos_url":"https://api.github.com/users/javaslang/repos","events_url":"https://api.github.com/users/javaslang/events{/privacy}","received_events_url":"https://api.github.com/users/javaslang/received_events","type":"Organization","site_admin":false},"repo":{"id":16378879,"name":"javaslang","full_name":"javaslang/javaslang","owner":{"login":"javaslang","id":5786132,"avatar_url":"https://avatars.githubusercontent.com/u/5786132?v=3","gravatar_id":"","url":"https://api.github.com/users/javaslang","html_url":"https://github.com/javaslang","followers_url":"https://api.github.com/users/javaslang/followers","following_url":"https://api.github.com/users/javaslang/following{/other_user}","gists_url":"https://api.github.com/users/javaslang/gists{/gist_id}","starred_url":"https://api.github.com/users/javaslang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javaslang/subscriptions","organizations_url":"https://api.github.com/users/javaslang/orgs","repos_url":"https://api.github.com/users/javaslang/repos","events_url":"https://api.github.com/users/javaslang/events{/privacy}","received_events_url":"https://api.github.com/users/javaslang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/javaslang/javaslang","description":"A functional library for Java 8+ that provides persistent data types and functional control structures.","fork":false,"url":"https://api.github.com/repos/javaslang/javaslang","forks_url":"https://api.github.com/repos/javaslang/javaslang/forks","keys_url":"https://api.github.com/repos/javaslang/javaslang/keys{/key_id}","collaborators_url":"https://api.github.com/repos/javaslang/javaslang/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/javaslang/javaslang/teams","hooks_url":"https://api.github.com/repos/javaslang/javaslang/hooks","issue_events_url":"https://api.github.com/repos/javaslang/javaslang/issues/events{/number}","events_url":"https://api.github.com/repos/javaslang/javaslang/events","assignees_url":"https://api.github.com/repos/javaslang/javaslang/assignees{/user}","branches_url":"https://api.github.com/repos/javaslang/javaslang/branches{/branch}","tags_url":"https://api.github.com/repos/javaslang/javaslang/tags","blobs_url":"https://api.github.com/repos/javaslang/javaslang/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/javaslang/javaslang/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/javaslang/javaslang/git/refs{/sha}","trees_url":"https://api.github.com/repos/javaslang/javaslang/git/trees{/sha}","statuses_url":"https://api.github.com/repos/javaslang/javaslang/statuses/{sha}","languages_url":"https://api.github.com/repos/javaslang/javaslang/languages","stargazers_url":"https://api.github.com/repos/javaslang/javaslang/stargazers","contributors_url":"https://api.github.com/repos/javaslang/javaslang/contributors","subscribers_url":"https://api.github.com/repos/javaslang/javaslang/subscribers","subscription_url":"https://api.github.com/repos/javaslang/javaslang/subscription","commits_url":"https://api.github.com/repos/javaslang/javaslang/commits{/sha}","git_commits_url":"https://api.github.com/repos/javaslang/javaslang/git/commits{/sha}","comments_url":"https://api.github.com/repos/javaslang/javaslang/comments{/number}","issue_comment_url":"https://api.github.com/repos/javaslang/javaslang/issues/comments{/number}","contents_url":"https://api.github.com/repos/javaslang/javaslang/contents/{+path}","compare_url":"https://api.github.com/repos/javaslang/javaslang/compare/{base}...{head}","merges_url":"https://api.github.com/repos/javaslang/javaslang/merges","archive_url":"https://api.github.com/repos/javaslang/javaslang/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/javaslang/javaslang/downloads","issues_url":"https://api.github.com/repos/javaslang/javaslang/issues{/number}","pulls_url":"https://api.github.com/repos/javaslang/javaslang/pulls{/number}","milestones_url":"https://api.github.com/repos/javaslang/javaslang/milestones{/number}","notifications_url":"https://api.github.com/repos/javaslang/javaslang/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/javaslang/javaslang/labels{/name}","releases_url":"https://api.github.com/repos/javaslang/javaslang/releases{/id}","deployments_url":"https://api.github.com/repos/javaslang/javaslang/deployments","created_at":"2014-01-30T14:07:25Z","updated_at":"2016-07-20T02:10:04Z","pushed_at":"2016-07-20T04:58:11Z","git_url":"git://github.com/javaslang/javaslang.git","ssh_url":"git@github.com:javaslang/javaslang.git","clone_url":"https://github.com/javaslang/javaslang.git","svn_url":"https://github.com/javaslang/javaslang","homepage":"http://javaslang.io","size":13658,"stargazers_count":1043,"watchers_count":1043,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":120,"mirror_url":null,"open_issues_count":107,"forks":120,"open_issues":107,"watchers":1043,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/javaslang/javaslang/pulls/1453"},"html":{"href":"https://github.com/javaslang/javaslang/pull/1453"},"issue":{"href":"https://api.github.com/repos/javaslang/javaslang/issues/1453"},"comments":{"href":"https://api.github.com/repos/javaslang/javaslang/issues/1453/comments"},"review_comments":{"href":"https://api.github.com/repos/javaslang/javaslang/pulls/1453/comments"},"review_comment":{"href":"https://api.github.com/repos/javaslang/javaslang/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/javaslang/javaslang/pulls/1453/commits"},"statuses":{"href":"https://api.github.com/repos/javaslang/javaslang/statuses/0b6d0aa7397d9eaafa8821f00ab6f1357e1bb77f"}}}}
{"actor":{"display_login":"danieldietrich"}}