loading...

## 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

``````(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);
}

``````
code of conduct - report abuse