Hackerrank Ruby Control Structures - Until Solution
.MathJax_SVG_Display {text-align: center; margin: 1em 0em; position: relative; display: block!important; text-indent: 0; max-width: none; max-height: none; min-width: 0; min-height: 0; width: 100%} .MathJax_SVG .MJX-monospace {font-family: monospace} .MathJax_SVG .MJX-sans-serif {font-family: sans-serif} .MathJax_SVG {display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 100%; font-size-adjust: none; text-indent: 0; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0} .MathJax_SVG * {transition: none; -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none} .mjx-svg-href {fill: blue; stroke: blue}
This challenge has a beautiful one-liner answer.
"A hacker practices on HackerRank until getting to a rating of O(1) read as (Oh-one)"
Call the method coder.practice
until coder.oh_one?
becomes true
.
Use the until
control structure.
until
is the logical equivalent of while not
.
Hint
while not <condition>
<code>
end
or
until <condition>
<code>
end
or the beautiful one-liner
<code> until <condition>
Solution in ruby
Approach 1.
until coder.oh_one? do coder.practice end
Approach 2.
# Enter your code here. Read input from STDIN. Print output to STDOUT
coder.practice until coder.oh_one?
Approach 3.
# Enter your code here. Read input from STDIN. Print output to STDOUT
coder.practice until coder.oh_one?