{"action":"created","issue":{"url":"https://api.github.com/repos/rottenpen/blog/issues/9","repository_url":"https://api.github.com/repos/rottenpen/blog","labels_url":"https://api.github.com/repos/rottenpen/blog/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/rottenpen/blog/issues/9/comments","events_url":"https://api.github.com/repos/rottenpen/blog/issues/9/events","html_url":"https://github.com/rottenpen/blog/issues/9","id":348984369,"node_id":"MDU6SXNzdWUzNDg5ODQzNjk=","number":9,"title":"每天一道算法题(简单版)","user":{"login":"rottenpen","id":12029924,"node_id":"MDQ6VXNlcjEyMDI5OTI0","avatar_url":"https://avatars3.githubusercontent.com/u/12029924?v=4","gravatar_id":"","url":"https://api.github.com/users/rottenpen","html_url":"https://github.com/rottenpen","followers_url":"https://api.github.com/users/rottenpen/followers","following_url":"https://api.github.com/users/rottenpen/following{/other_user}","gists_url":"https://api.github.com/users/rottenpen/gists{/gist_id}","starred_url":"https://api.github.com/users/rottenpen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rottenpen/subscriptions","organizations_url":"https://api.github.com/users/rottenpen/orgs","repos_url":"https://api.github.com/users/rottenpen/repos","events_url":"https://api.github.com/users/rottenpen/events{/privacy}","received_events_url":"https://api.github.com/users/rottenpen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-08-09T05:37:45Z","updated_at":"2018-08-15T14:45:57Z","closed_at":null,"author_association":"OWNER","body":"In a small town the population is `p0 = 1000` at the beginning of a year. The population regularly increases by `2 `percent per year and moreover `50 `new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to `p = 1200 `inhabitants?\r\n\r\n```\r\nAt the end of the first year there will be: \r\n1000 + 1000 * 0.02 + 50 => 1070 inhabitants\r\n\r\nAt the end of the 2nd year there will be: \r\n1070 + 1070 * 0.02 + 50 => 1141 inhabitants (number of inhabitants is an integer)\r\n\r\nAt the end of the 3rd year there will be:\r\n1141 + 1141 * 0.02 + 50 => 1213\r\n\r\nIt will need 3 entire years.\r\n```\r\n\r\nMore generally given parameters:\r\n\r\np0, percent, aug (inhabitants coming or leaving each year), p (population to surpass)\r\n\r\nthe function nb_year should return n number of entire years needed to get a population greater or equal to p.\r\n\r\naug is an integer, percent a positive or null number, p0 and p are positive integers (> 0)\r\n\r\nExamples:\r\n```\r\nnb_year(1500, 5, 100, 5000) -> 15\r\nnb_year(1500000, 2.5, 10000, 2000000) -> 10\r\n```\r\nNote: Don't forget to convert the percent parameter as a percentage in the body of your function: if the parameter percent is 2 you have to convert it to 0.02.\r\n\r\n### 代码：\r\n``` javascript\r\nfunction nbYear(p0, percent, aug, p) {\r\n    // your code\r\n    var ny = 0\r\n    var sum = p0\r\n    while(sum < p){\r\n      sum = sum + sum*percent/100 + aug\r\n      ny = ny + 1\r\n    }\r\n    return ny\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/rottenpen/blog/issues/comments/413220623","html_url":"https://github.com/rottenpen/blog/issues/9#issuecomment-413220623","issue_url":"https://api.github.com/repos/rottenpen/blog/issues/9","id":413220623,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzIyMDYyMw==","user":{"login":"rottenpen","id":12029924,"node_id":"MDQ6VXNlcjEyMDI5OTI0","avatar_url":"https://avatars3.githubusercontent.com/u/12029924?v=4","gravatar_id":"","url":"https://api.github.com/users/rottenpen","html_url":"https://github.com/rottenpen","followers_url":"https://api.github.com/users/rottenpen/followers","following_url":"https://api.github.com/users/rottenpen/following{/other_user}","gists_url":"https://api.github.com/users/rottenpen/gists{/gist_id}","starred_url":"https://api.github.com/users/rottenpen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rottenpen/subscriptions","organizations_url":"https://api.github.com/users/rottenpen/orgs","repos_url":"https://api.github.com/users/rottenpen/repos","events_url":"https://api.github.com/users/rottenpen/events{/privacy}","received_events_url":"https://api.github.com/users/rottenpen/received_events","type":"User","site_admin":false},"created_at":"2018-08-15T14:45:57Z","updated_at":"2018-08-15T14:45:57Z","author_association":"OWNER","body":"### \"123456789876543212345678987654321...\" 的第 n 位是什么？\r\n\r\n答案：\r\n```\r\nfunction whichn(n){\r\n    let arr = [1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2]\r\n    return arr[n % 16 - 1]\r\n}\r\n\r\nfunction whichn(str, n){\r\n    return str.charAt(n-1)\r\n}\r\n\r\nfunction whichn(str, n){\r\n    str.split('')\r\n    return str.split('')[n - 1]\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"rottenpen"}}