DEV Community

Discussion on: Daily Coding Puzzles - Nov 4th - Nov 9th

Collapse
 
aspittel profile image
Ali Spittel

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

Collapse
 
gypsydave5 profile image
David Wickes • Edited

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
Collapse
 
thejessleigh profile image
jess unrein • Edited

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
}
Collapse
 
jay profile image
Jay

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)
}
Collapse
 
aspittel profile image
Ali Spittel

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)
Collapse
 
clandau profile image
Courtney
function guessBlue(blueStart, redStart, bluePulled, redPulled) {
  let currentBlue = blueStart - bluePulled;
  let currentRed = redStart - redPulled;
  return currentBlue / (currentBlue + currentRed);
}