Number Drills: Blue and red marbles (8 KYU):
You've decided to write a function, guess_blue() to help automatically calculate whether you should guess "blue" or "red". The function should take four arguments.
CodeWars
(defun guess-blue (blue-in red-in blue-out red-out) (let ((blue (- blue-in blue-out)) (red (- red-in red-out))) (/ blue (+ red blue))) (guess-blue 5 5 2 3) ;; => 3/5
the fun of a language with rationals:
(guess-blue 1 2 0 0) ;; => 1/3
Go
func Guess(bStart int, rStart int, bGone int, rGone int)(probability float32) { var b = bStart - bGone var r = rStart - rGone probability = float32(b) / float32(r + b) return }
Rust
fn guess_blue(blue_start: u32, red_start: u32, blue_pulled: u32, red_pulled: u32) -> f32 { let blue = (blue_start - blue_pulled) as f32; let red = (red_start - red_pulled) as f32; blue / (blue + red) }
Python!
def guess_blue(blue_start, red_start, blue_pulled, red_pulled): blue = blue_start - blue_pulled red = red_start - red_pulled return blue / (red + blue)
function guessBlue(blueStart, redStart, bluePulled, redPulled) { let currentBlue = blueStart - bluePulled; let currentRed = redStart - redPulled; return currentBlue / (currentBlue + currentRed); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Monday
Number Drills: Blue and red marbles (8 KYU):
You've decided to write a function, guess_blue() to help automatically calculate whether you should guess "blue" or "red". The function should take four arguments.
CodeWars
Common Lisp
the fun of a language with rationals:
Go
Rust
Python!