Giter VIP home page Giter VIP logo

crashing_stones's Introduction

Crashing_Stones

each day a quarry worker is given a pile of stones and told to reduce the larger stones into smaller. the workes must smash the stones together to reduce them and is told to always pick up the largest to stones and smash them tigether. If the sonnets are of equal weight, they both disintegrate entirely. If one is larger , the smaller one is disintegrated and the larger one is reduced by the weight of the smaller one. Eventually there is either one stone left that cannot be broken , or all of the stones have been smashed. Determine the weight of the last stone, or return 0 if there is none.

Complete the function lastStoneWeight in Ruby. The function must return an integer that denotes the weight of the last stone or 0 if all stones shattered into dust

Last StoneWeight has the following parameters : Int weights[n]: an array of integers indicating the weights of each stone โ€จ Example : Weight = [1,2,3,6,7,7].

The worker always starts with the two largest stones . In this case the two largest stones have equal weights of 7 so they both disintegrate when smashed . Next the works smashes weights 3 and 6 . The smalls one is destroyed and the larger weights 6-3= 3 units. Then, weights 3 and 2 are smashed together, which leaves a stone of weights 1. This is smashed with the last remaining stone of weight 1. There are no stones left so the remaining stone weight is 0

explanation: explanation: First the worker takes stones with weights 4 and 5 and crashes them into each other. The first disintegrates completely. The second is reduces to weight of 1. Next the worker crashes that stone into the last stone with weight 2. The smaller stone disintegrates and the last stone is reduced of the weight of 1.

crashing_stones's People

Contributors

mkrasicka avatar

Watchers

 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.