4 ms·
One line bash solutions: https://pastebin.com/QnKJEXxt https://pastebin.com/QnKJEXxt
by devit 7y ago
One line bash solutions: https://pastebin.com/QnKJEXxt https://pastebin.com/QnKJEXxt
- threatofrain 7y agoSurprisingly readable.
- noname120 7y agoYou can do shorter in languages with functional constructs. For example Python: sum(map(lambda x: x // 3 - 2, numbers))
- skinnyasianboi 7y agoKotlin: numbers.sumBy { it / 3 - 2 }
- the-dude 7y agoWhy is that a double slash?
- michaelmarkell 7y agoIt rounds down the quotient
- the-dude 7y agoHow intuitive. But thanks anyway.
- jacobolus 7y agoIn Python 2, floor division is the default for integer arguments and exact (to within machine precision) division the default for floating point arguments, but this caused a lot of unnecessary confusion: new users were surprised that 3.0/2.0 == 1.5, but 3/2 == 1. Thus for Python 3 the new // operator was added for explicit floor division (which is often quite useful in its own right), leaving the / operator to always return an exact (to machine precision) floating point result, even with integer arguments. cf. https://en.wikipedia.org/wiki/Principle_of_least_astonishment https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...
- empath75 7y agoone line ruby map reduce: input.map(&(-> (f) {->(g) {g.(g)}.(->(g) { f.(->(*args) {g.(g).(*args)})})}.(->(f) { ->(n) { n < 9 ? 0 : (n/3-2)+f.(n/3-2) } }))).reduce(&:+)