0068【Edabit ★☆☆☆☆☆】I‘d Like a New Shade of Blue, Please

0068【Edabit ★☆☆☆☆☆】I'd Like a New Shade of Blue, Please

math numbers

Instructions

I have a bucket containing an amount of navy blue paint and I'd like to paint as many walls as possible. Create a function that returns the number of complete walls that I can paint, before I need to head to the shops to buy more.

  • n is the number of square meters I can paint.
  • w and h are the widths and heights of a single wall in meters.
Examples
javascript 复制代码
howManyWalls(100, 4, 5) // 5
howManyWalls(10, 15, 12) // 0
howManyWalls(41, 3, 6) // 2
Notes
  • Don't count a wall if I don't manage to finish painting all of it before I run out of paint.
  • All walls will have the same dimensions.
  • All numbers will be positive integers.
Solutions
javascript 复制代码
function howManyWalls(n, w, h) {
	return Math.floor(n/(w*h));
}
TestCases
javascript 复制代码
let Test = (function(){
    return {
        assertEquals:function(actual,expected){
            if(actual !== expected){
                let errorMsg = `actual is ${actual},${expected} is expected`;
                throw new Error(errorMsg);
            }
        },
        assertSimilar:function(actual,expected){
            if(actual.length != expected.length){
                throw new Error(`length is not equals, ${actual},${expected}`);
            }
            for(let a of actual){
                if(!expected.includes(a)){
                    throw new Error(`missing ${a}`);
                }
            }
        }
    }
})();
Test.assertEquals(howManyWalls(100, 4, 5), 5)
Test.assertEquals(howManyWalls(10, 15, 12), 0)
Test.assertEquals(howManyWalls(41, 3, 6), 2)
Test.assertEquals(howManyWalls(50, 11, 5), 0)
Test.assertEquals(howManyWalls(1, 1, 1), 1)

// Author: Joshua Señoron
相关推荐
阿俊-全栈开发3 分钟前
LikeShop 多商户标准版秒杀与优惠券叠加规则的自定义配置二开
开发语言·分布式·golang·likeshop开源商城·likeshop源码
IT枫斗者9 分钟前
缓存和数据库一致性:先更库还是先删缓存,延迟双删怎么落地
java·开发语言·数据库·人工智能·缓存·gateway
我是伪码农12 分钟前
12.5程序设计
数据结构·算法
Junsir大斗师20 分钟前
华为云平台下safeline【长亭雷池】反向代理实验
开发语言·nginx·安全·华为云
Shaoshing22 分钟前
LeetCode100 152.乘积最大子数组
数据结构·算法·leetcode
吞下星星的少年·-·26 分钟前
力扣 162. 寻找峰值(枚举,二分查找)
算法·leetcode·枚举·二分
风落青芜33 分钟前
C++模板初阶:函数模板与类模板
开发语言·数据结构·c++·算法
传奇开心果编程39 分钟前
【华为仓颉独特优势】第11课:回到主场——HarmonyOS 上的仓颉:ArkTS 互操作与“宿主问题”的终极答卷
开发语言·华为·harmonyos·编程语言理论·仓颉·cangjie·通用编程语言
纪念 22942 分钟前
C++ 算法模板与错题 (枚举)
c++·redis·算法
master3361 小时前
Java 是如何调用 C 语言接口的?native 方法的完整工作原理
java·c语言·开发语言