{"id":20744490,"url":"https://github.com/brianbroderick/ball-clock","last_synced_at":"2025-03-11T12:42:19.670Z","repository":{"id":93854338,"uuid":"43655776","full_name":"brianbroderick/ball-clock","owner":"brianbroderick","description":"A simple ball clock coding exercise","archived":false,"fork":false,"pushed_at":"2015-10-04T23:24:59.000Z","size":528,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-18T02:28:01.417Z","etag":null,"topics":["interview-test","ruby"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brianbroderick.png","metadata":{"files":{"readme":"README.rdoc","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-04T22:51:23.000Z","updated_at":"2018-02-11T01:17:46.000Z","dependencies_parsed_at":"2023-03-04T00:01:03.221Z","dependency_job_id":null,"html_url":"https://github.com/brianbroderick/ball-clock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianbroderick%2Fball-clock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianbroderick%2Fball-clock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianbroderick%2Fball-clock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianbroderick%2Fball-clock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brianbroderick","download_url":"https://codeload.github.com/brianbroderick/ball-clock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243039584,"owners_count":20226131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interview-test","ruby"],"created_at":"2024-11-17T07:15:46.642Z","updated_at":"2025-03-11T12:42:19.452Z","avatar_url":"https://github.com/brianbroderick.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"== Running the Program\n\nOnce you clone the repo, run bundle install.\n\nTo see the help screen run:\nbundle exec bin/ball-clock\n\nTo see the specific flags for the start command run:\nbundle exec bin/ball-clock help start\n\nTo run the clock run:\nbundle exec bin/ball-clock start\n\nCOMMAND OPTIONS\n    -b, --balls=BALLS     - Number of Balls (must be between 27 and 127) (default: 30)\n    -m, --minutes=MINUTES - Number of Minutes (default: none)\n\n== Note\n\nIn the second output option, my \"Main\" array is reversed. This may be because I originally ordered the balls from 30..1 and used push and pop instead of unshift.\nI believe it's more efficient to use push and pop instead of unshift. Or perhaps it was a trick question or typo in the requirements doc.\nAt any rate, my output shows like this:\n{\"Min\":[],\"FiveMin\":[22,13,25,3,7],\"Hour\":[6,12,17,4,15],\"Main\":[9,27,14,23,1,28,21,16,20,29,10,24,8,19,30,2,18,26,5,11]}\n\n== Requirements\n\nMovement has long been used to measure time. For example, the ball clock is a simple device which keeps track of the passing minutes by moving ball-bearings.\nEach minute, a rotating arm removes a ball bearing from the queue at the bottom, raises it to the top of the clock and deposits it on a track leading to indicators displaying minutes,\nfive-minutes and hours. These indicators display the time between 1:00 and 12:59, but without 'a.m.' or 'p.m.' indicators.\nThus 2 balls in the minute indicator, 6 balls in the five-minute indicator and 5 balls in the hour indicator displays the time 5:32.\n\nUnfortunately, most commercially available ball clocks do not incorporate a date indication, although this would be simple to do with the addition of further carry and indicator tracks.\nHowever, all is not lost! As the balls migrate through the mechanism of the clock, the order they are found in can be used to determine the time elapsed\nsince the clock had some specific ordering. The length of time which can be measured is limited because the orderings of the balls eventually begin to repeat.\nYour program must compute the time before repetition, which varies according to the total number of balls present.\n\n=== Operation of the Ball Clock\n\nEvery minute, the least recently used ball is removed from the queue of balls at the bottom of the clock, elevated,\nthen deposited on the minute indicator track, which is able to hold four balls. When a fifth ball rolls on to the minute indicator track,\nits weight causes the track to tilt. The four balls already on the track run back down to join the queue of balls waiting at the bottom in reverse order of their original\naddition to the minutes track. The fifth ball, which caused the tilt, rolls on down to the five-minute indicator track.\nThis track holds eleven balls. The twelfth ball carried over from the minutes causes the five-minute track to tilt, returning the eleven balls to the queue,\nagain in reverse order of their addition. The twelfth ball rolls down to the hour indicator.\n\nThe hour indicator also holds eleven balls, but has one extra fixed ball which is always present so that counting the balls in the hour indicator\nwill yield an hour in the range one to twelve.\nThe twelfth ball carried over from the five-minute indicator causes the hour indicator to tilt,\nreturning the eleven free balls to the queue, in reverse order,\nbefore the twelfth ball itself also returns to the queue.\n\n=== Guidelines\n\nThe exercise may be completed in Ruby, or JavaScript. Youâ€™re welcome to do it in more than one of the languages.\n\nNo permutation or LCM algorithms are allowed.  A full simulation is required. Please ensure that your code moves each ball.\n\n=== Implementation\n\nValid numbers are in the range 27 to 127.\n\nClocks must support two modes of computation.\n\nThe first mode takes a single parameter specifying the number of balls and reports the number of balls given in the input and the number of days (24-hour periods) which elapse before the clock returns to its initial ordering.\n\n  Sample Input\n  30\n  45\n\n  Output for the Sample Input\n  30 balls cycle after 15 days.\n  45 balls cycle after 378 days.\n\nThe second mode takes two parameters, the number of balls and the number of minutes to run for.  If the number of minutes is specified, the clock must run to the number of minutes and report the state of the tracks at that point in a JSON format.\n\n  Sample Input\n  30 325\n\n  Output for the Sample Input\n  {\"Min\":[],\"FiveMin\":[22,13,25,3,7],\"Hour\":[6,12,17,4,15],\"Main\"\n  [11,5,26,18,2,30,19,8,24,10,29,20,16,21,28,1,23,14,27,9]}\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianbroderick%2Fball-clock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianbroderick%2Fball-clock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianbroderick%2Fball-clock/lists"}