0029【Edabit ★☆☆☆☆☆】Profitable Gamble

2023-10-22 12:52
文章标签 edabit 0029 profitable gamble

本文主要是介绍0029【Edabit ★☆☆☆☆☆】Profitable Gamble,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

0029【Edabit ★☆☆☆☆☆】Profitable Gamble

conditions math validation

Instructions

Create a function that takes three arguments prob, prize, pay and returns true if prob * prize > pay; otherwise return false.

To illustrate:

profitableGamble(0.2, 50, 9)

… should yield true, since the net profit is 1 (0.2 * 50 - 9), and 1 > 0.

Examples
profitableGamble(0.2, 50, 9) // true
profitableGamble(0.9, 1, 2) // false
profitableGamble(0.9, 3, 2) // true
Notes
  • A profitable gamble is a game that yields a positive net profit, where net profit is calculated in the following manner: net_outcome = probability_of_winning * prize - cost_of_playing.
Solutions
function profitableGamble(prob, prize, pay) {return prob * prize > pay ;
}
TestCases
let Test = (function(){return {assertEquals:function(actual,expected){if(actual !== expected){let errorMsg = `actual is ${actual},${expected} is expected`;throw new Error(errorMsg);}}}
})();Test.assertEquals(profitableGamble(0.2, 50, 9), true)
Test.assertEquals(profitableGamble(0.9, 1, 2), false)
Test.assertEquals(profitableGamble(0.9, 3, 2), true)
Test.assertEquals(profitableGamble(0.33, 10, 3.30), true)
Test.assertEquals(profitableGamble(0, 1000, 0.01), false)
Test.assertEquals(profitableGamble(0.1, 1000, 7), true)
Test.assertEquals(profitableGamble(0, 0, 0), false)

这篇关于0029【Edabit ★☆☆☆☆☆】Profitable Gamble的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/261599

相关文章

0029__好奇,项目根目录下的.editorconfig文件

https://www.cnblogs.com/xieqian/p/10045610.html

LeetCode879. Profitable Schemes——动态规划

文章目录 一、题目二、题解 一、题目 There is a group of n members, and a list of various crimes they could commit. The ith crime generates a profit[i] and requires group[i] members to participate in it. If a

0062【Edabit ★☆☆☆☆☆】Arrow Functions

0062【Edabit ★☆☆☆☆☆】Arrow Functions closures higher_order_functions language_fundamentals logic Instructions In the Code tab you will find code that is missing a single character in order to pass t

0059【Edabit ★☆☆☆☆☆】【是否被允许喝酒】Drinks Allowed?

0059【Edabit ★☆☆☆☆☆】【是否被允许喝酒】Drinks Allowed? conditions language_fundamentals logic validation Instructions A bartender is writing a simple program to determine whether he should serve drinks to so

0061【Edabit ★☆☆☆☆☆】【字符串模板:格式化1】Format I: Template String

0061【Edabit ★☆☆☆☆☆】【字符串模板:格式化1】Format I: Template String language_fundamentals strings Instructions Write a template string according to the following example: Examples const a = "John";const

0055【Edabit ★☆☆☆☆☆】【弧度转角度】Radians to Degrees

0055【Edabit ★☆☆☆☆☆】【弧度转角度】Radians to Degrees logic math numbers Instructions Create a function that takes an angle in radians and returns the corresponding angle in degrees. Examples radiansTo

0049【Edabit ★☆☆☆☆☆】【修改Bug代码】Buggy Code

0049【Edabit ★☆☆☆☆☆】【修改Bug代码】Buggy Code bugs language_fundamentals Instructions The challenge is to try and fix this buggy code, given the inputs true and false. See the examples below for the expe

0051【Edabit ★☆☆☆☆☆】【解析表达式】Solve the Equation

0051【Edabit ★☆☆☆☆☆】【解析表达式】Solve the Equation language_fundamentals math Instructions Create a function that takes an equation (e.g. "1+1"), and returns the answer. Examples equation("1+1") //

0053【Edabit ★☆☆☆☆☆】【计算投票】Upvotes vs Downvotes

0053【Edabit ★☆☆☆☆☆】【计算投票】Upvotes vs Downvotes arrays language_fundamentals numbers objects Instructions Given an object containing counts of both upvotes and downvotes, return what vote count shou

0029Java程序设计-家政服务平台管理系统

文章目录 摘要目录系统设计开发环境 摘要 本文首先研究并介绍国内外目前的背景和现状,在此基础上给出论文的主要研究内容,其次,对家政服务平台管理系统的需求进行了分析。再次,对家政服务平台管理系统进行了总体设计,根据其总体设计、软件架构和总体功能模块进行了详细设计,作出了业务流程图以及数据流程图。总体上把系统分为会员、市场部、管理员、超管四种角色,前台上主要包括会员注册、会员登录、