{"id":1846,"date":"2016-08-29T10:00:23","date_gmt":"2016-08-29T14:00:23","guid":{"rendered":"http:\/\/www.mymiller.name\/wordpress\/?p=1846"},"modified":"2019-03-31T05:22:30","modified_gmt":"2019-03-31T09:22:30","slug":"dividing-game","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/challenge\/dividing-game\/","title":{"rendered":"Dividing Game Interview Coding Sample"},"content":{"rendered":"\n<p>I was recently given the challenge to write an solution for the Dividing Game. &nbsp;The objective Player 1 and Player 2 each choose a number. &nbsp;The solution should output the number of common divisor&#8217;s they share in common between the selected numbers.<\/p>\n\n\n\n<p>This logic is rather simple, create a list of known divisors for each number, then use the list to only retain the contents that are common to both lists. &nbsp;Then you have your common divisors between the two numbers.\n<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.ArrayList;\n \n\/**\n * @author jmiller Class to play the dividing game\n *\/\npublic class DividingGame\n{\n    \/**\n     * Start the Dividing Game\n     *\n     * @param playerOne\n     *            Player 1 Chosen Number\n     * @param playerTwo\n     *            Player 2 Chosen Number\n     * @param divisor\n     *            Number to divide by\n     *\/\n    public DividingGame(int playerOne, int playerTwo, int divisor)\n    {\n        System.out.println(\"playerOne = \" + playerOne + \" \/ playerTwo = \" + playerTwo);\n        System.out.println(\"Returns: \" + this.getNumber(playerOne, playerTwo, divisor));\n    }\n \n    \/**\n     * Get the divisors for the number\n     *\n     * @param value\n     *            Number to divide\n     * @param divisor\n     *            Divide the number by this\n     * @return Array containing the values by the divisor\n     *\/\n    private ArrayList&lt;Integer> getDivisor(int value, int divisor)\n    {\n        ArrayList&lt;Integer> list = null;\n \n        \/\/ If we are not even with the divisor we are done.\n        if ((value % divisor) > 0)\n        {\n            list = new ArrayList&lt;Integer>();\n            list.add(new Integer(value));\n        }\n        else\n        {\n            list = this.getDivisor(value \/ divisor, divisor);\n            list.add(new Integer(value));\n        }\n \n        return list;\n    }\n \n    \/**\n     * Determine the number of common divisors\n     *\n     * @param playerOne\n     *            Player One picked Number\n     * @param playerTwo\n     *            Player Two picked Number\n     * @param divisor\n     *            Divide the number by this\n     * @return Number of common divisors\n     *\/\n    public int getNumber(int playerOne, int playerTwo, int divisor)\n    {\n        \/\/ Get the list of divisor's for each number\n        final ArrayList&lt;Integer> oneList = this.getDivisor(playerOne, divisor);\n        final ArrayList&lt;Integer> twoList = this.getDivisor(playerTwo, divisor);\n \n        \/\/ Only contain the common elements\n        oneList.retainAll(twoList);\n \n        \/\/ Return the size of the common elements\n        return oneList.size();\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I was recently given the challenge to write an solution for the Dividing Game. &nbsp;The objective Player 1 and Player 2 each choose a number. &nbsp;The solution should output the number of common divisor&#8217;s they share in common between the selected numbers. This logic is rather simple, create a list of known divisors for each [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1847,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[273],"tags":[],"series":[],"class_list":["post-1846","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-challenge"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/08\/calculator-1330104_640.jpg?fit=640%2C426&ssl=1","jetpack-related-posts":[{"id":1788,"url":"https:\/\/www.mymiller.name\/wordpress\/challenge\/algorithm-max-diff\/","url_meta":{"origin":1846,"position":0},"title":"Algorithm: Max Diff between consecutive elements in an ordered array","author":"Jeffery Miller","date":"July 3, 2024","format":false,"excerpt":"So you have an array that is ordered from highest to lowest, and now you need to know what is the maximum difference between consecutive elements in the array. \u00a0So let's take a look at what we are first talking about. int[] array = {1,2,3,5,7,11,13,17,19} As you can see we\u2026","rel":"","context":"In &quot;Challenge&quot;","block_context":{"text":"Challenge","link":"https:\/\/www.mymiller.name\/wordpress\/category\/challenge\/"},"img":{"alt_text":"algorithm max diff array","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/07\/silhouette-936724_640.jpg?fit=640%2C452&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/07\/silhouette-936724_640.jpg?fit=640%2C452&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/07\/silhouette-936724_640.jpg?fit=640%2C452&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2062,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/advancedcalendar\/","url_meta":{"origin":1846,"position":1},"title":"AdvancedCalendar &#8211; java.util.Calendar java.util.Date java.text.SimpleDateFormat","author":"Jeffery Miller","date":"November 24, 2025","format":false,"excerpt":"Every get tired of converting from Dates to Calendars and then need to use SimpleDateFormat to output it as a String? \u00a0How about parsing a string and getting a Date object? \u00a0Personally after a single project that had several \u00a0date time stamps that required manipulation I grew very tired of\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/02\/calendar-1255953_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/02\/calendar-1255953_640.jpg?fit=640%2C426&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2017\/02\/calendar-1255953_640.jpg?fit=640%2C426&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":1936,"url":"https:\/\/www.mymiller.name\/wordpress\/java\/advancedstring-java-lang-string-steroids\/","url_meta":{"origin":1846,"position":2},"title":"AdvancedString &#8211; java.lang.String on steroids!","author":"Jeffery Miller","date":"November 24, 2025","format":false,"excerpt":"Every need an additional method on the String Class? \u00a0Well I have and it would have made life much easier. \u00a0Unfortunately you can't subclass String as it is Final. \u00a0So what are you to do? \u00a0Well you wrap the String class. \u00a0I have created AdvancedString, which contains additional functionality and\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java\/"},"img":{"alt_text":"AdvancedString","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/rope-1379561_640.jpg?fit=640%2C425&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/rope-1379561_640.jpg?fit=640%2C425&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/09\/rope-1379561_640.jpg?fit=640%2C425&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2023,"url":"https:\/\/www.mymiller.name\/wordpress\/java\/simplifying-javafx-display-management-with-displaymanager\/","url_meta":{"origin":1846,"position":3},"title":"Simplifying JavaFX Display Management with DisplayManager","author":"Jeffery Miller","date":"April 20, 2026","format":false,"excerpt":"JavaFX provides a powerful platform for creating rich graphical user interfaces (GUIs) in Java applications. However, managing multiple displays and screens within a JavaFX application can be a complex task. To simplify this process and provide a flexible solution, we've developed the DisplayManager framework. In this article, we'll explore how\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/12\/board-1364650_640.jpg?fit=640%2C452&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/12\/board-1364650_640.jpg?fit=640%2C452&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2016\/12\/board-1364650_640.jpg?fit=640%2C452&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3225,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/caching-objects\/","url_meta":{"origin":1846,"position":4},"title":"Caching Objects","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Sometimes you need to maintain a large number of objects in memory. If it is strings you may want to take a look at StringCache, which is based on my Cache class presented here. Now the Cache workers simply call create an instance of Cache: Cache<Person> peopleCache = new Cache<>();\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2022\/02\/geocache-gd1a671d59_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2022\/02\/geocache-gd1a671d59_640.jpg?fit=640%2C360&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2022\/02\/geocache-gd1a671d59_640.jpg?fit=640%2C360&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3060,"url":"https:\/\/www.mymiller.name\/wordpress\/java_extra\/string-cache\/","url_meta":{"origin":1846,"position":5},"title":"String Cache","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Sometimes an application will have a large number of Strings. Due to memory we certainly do not want to keep multiple instances of duplicate strings in memory. A string cache can greatly reduce the number of Strings in memory. I had a case where I had millions of strings, and\u2026","rel":"","context":"In &quot;Java Extras&quot;","block_context":{"text":"Java Extras","link":"https:\/\/www.mymiller.name\/wordpress\/category\/java_extra\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/05\/geocache-398016_640.jpg?fit=640%2C480&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/05\/geocache-398016_640.jpg?fit=640%2C480&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2021\/05\/geocache-398016_640.jpg?fit=640%2C480&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/1846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=1846"}],"version-history":[{"count":4,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/1846\/revisions"}],"predecessor-version":[{"id":2536,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/1846\/revisions\/2536"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/1847"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=1846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=1846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=1846"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=1846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}