Code Monkey home page Code Monkey logo

guardgame's Introduction

GuardGame

You're being held in a guarded room in Dr. Boolean's mad science lab. How can you escape?

Beta Rabbit, a fellow captive and rabbit, notices a chance. The lab guards are always exceptionally bored, and have made up a game for themselves. They take the file numbers from the various specimens in the Professors lab, and see who can turn them into single digit numbers the fastest.

"I've observed them closely," Beta says. "For any number, the way they do this is by taking each digit in the number and adding them all together, repeating with the new sum until the result is a single digit. For example, when a guard picks up the medical file for Rabbit #1235, she would first add those digits together to get 11, then add those together to get 2, her final sum."

See if you can short circuit this game entirely with a clever program, thus driving the guards back to severe boredom. That way they will fall asleep and allow you to sneak out!

Write a function answer(x), which when given a number x, returns the final digit resulting from performing the above described repeated sum process on x.

x will be 0 or greater, and less than 2^31 -1 (or 2147483647), and the answer should be 0 or greater, and a single integer digit.

Test cases

Inputs: (long) x = 13 Output: (int) 4

Inputs: (long) x = 1235 Output: (int) 2

guardgame's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.