Giter Club home page Giter Club logo

funny_plant's Introduction

Funny Plant

Problem

Scientist have discovered a new plant. The fruit of the plant can feed 1 person for a whole week and best of all, the plant never dies. Fruits take 1 week to grow. Each week the plant gives 1 fruit more than the week before. To get more plants you need to plant a fruit. Each week you will prioritise planting one fruit from each plant, and what is left over can be consumed.

You start with one plant. Now you need to calculate after how many weeks, you can support a group of x people, given y fruits to start with.

Input

15 1

Output

5

Input description

The input gives you 2 positive integers x and y, being x the number of people needed to be fed and y the number of fruits you start with.

Output description

The number of weeks before you can feed the entire group of people.

Explanation

Here you have a table that shows the growth when starting with 1 fruit. It shows when the plant came into existence (is planted) and how may fruit it bears each week

Plant 1 2 3 4 5 6 7 8 9 10 11 12 13 Total # of fruits in a harvest

0——————————-—0

10———————————0

210——————————-1

321000————————-3

432111000000—————6

543222111111

Week

1 0 - - - - - - - - - - - - 0

2 1 0 - - - - - - - - - - - 1

3 2 1 0 0 0 - - - - - - - - 3

4 3 2 1 1 1 0 0 0 0 0 0 0 0 8

5 4 3 2 2 2 1 1 1 1 1 1 1 1 21

At week 1 we have 1 plant giving 0 fruits, because it has just been planted.

When week 2 comes along we have 1 plant that gives off a fruit and then we use that fruit to plant plant 2.

Then in week 3 we have 2 fruits from plant 1, 1 from plant 2, so we can plant 3 new plants.

Challenge Input

200 15

50000 1

150000 250

Challenge Output

5

14

9

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.