You're having trouble falling asleep, so your challenge today is to count sheep!
Given a non-negative integer, 3 for example, return a string wit...
For further actions, you may consider blocking this person and/or reporting abuse
This was quite a simple one so I decided to spice it up with emoji! Also, next-gen sleep simulation at the end.
Code:
Output:
Did anybody talk about oneliner?
And the results
This is sweet. Something similar but with more
Array
and lessmap
:or
PHP
JavaScript
PHP
I counted bugs because that is more reflective of what I would do while working :)
I also added a message for if you are able to go to sleep immediately
ruby <3
Ruby has pipes now?
Yes! pipeline operator added.
Feature #15799: pipeline operator - Ruby master - Ruby Issue Tracking System
And Numbered parameters.
Feature #4475: default variable name for parameter - Ruby master - Ruby Issue Tracking System
It's not released yet. You can try those new syntax by
rbenv install 2.7.0-dev
.Sadly, pipeline operator is reverted.
github.com/ruby/ruby/commit/2ed68d...
JavaScript
Most of the solutions are not taking input
0
into consideration.
Like for 0 the output should be
"0"
not an empty string.
Edit that can be made to question statement.
As according to question input can be a non-negative number. For rest of the inputs it should be like for 3,
"0 1 sheep...2 sheep... 3sheep..."
Pattern is print the numbers upto n starting with 0 and concate the string " sheep..." with them.
I kind of understand your suggestion (as zero is not positive nor negative, and the question statement would be more accurate if it was "Given a positive integer"), but I don't see why you suggest that base case.
Why for zero the output should be "0" and not "0 sheep..." or an empty string?
I made some assumptions for the pattern.
As i think the pattern is to print the numbers upto inputted number and concatinating string " sheep...", so as the total number of string " sheep..." in output string is equal to inputted number. that is no string for 0 but the "0" represent the number.
Oh, alright.
My solution in js
Scheme
A demo can be seen in Repl.it. The function would be called
(countSheep 4)
and the result would be:⬆️elixir
That was fast... might as well do it in another language too.
⬇️javascript
Here is the simple solution with PHP:
Rust solution: [Playground](
My solution in ruby
What about a range?
Oh, yeah.
Forgot about range.
Nice!
Trusty repl.it
Had no idea you could embed that,
how do you do that if you don't mind my asking?
Basically, you should add your '@username/replit_name' inside
See dev.to/p/editor_guide for more options.
Python :
In one line :
Some recursivity in JavaScript
or something like that.
Python
Erlang:
Perl solution, the integer is specified as an argument to the program:
Welcome to my fantasy world. :D
Output:
PHP
[gist.github.com/devparkk/334ee3d1f...]