Skip to content

Instantly share code, notes, and snippets.

@mirontoli
Forked from joladev/katze.clj
Last active August 29, 2015 14:02
Show Gist options
  • Save mirontoli/f93ac4d19351777ac3ce to your computer and use it in GitHub Desktop.
Save mirontoli/f93ac4d19351777ac3ce to your computer and use it in GitHub Desktop.

ekvation 1:

15h + k + 0,25m = 100 (1)

multiplicerad med 4 för att få heltal:

60h + 4k + m = 400 (1)

ekvation 2:

h + k + m = 100 (2)

sätt in (2) i (1) ger:

60(100 - k - m) + 4k + m = 400

5600 = 56k + 59m

k = (5600 - 59m)/56 = 100 - 59m/56

enda heltalslösningen är för m = 56 vilket ger k = 41

h = 100 - k - m = 3

alltså:

3 hundar: 3 x 15 = 45 kr

41 katter: 41 kr

56 möss: 56 x 0,25 = 14 kr

(def combinations
(for [dog (range 1 98) cat (range 1 98)
:when (>= 98 (+ dog cat))]
(let [mouse (- 100 dog cat)]
{:dog dog :cat cat :mouse mouse})))
(defn winner? [{:keys [dog cat mouse]}]
(== 100 (+ (* 15 dog) (* 1 cat) (* 0.25 mouse))))
(defn find-winner []
(filter winner? combinations))
(println (find-winner))
$range = 1..98
$combinations = $range | % {
$dog = $_
$range | % {
$cat = $_
return @{"Dog" = $dog; "Cat" = $cat; "Mouse" = 100 - $dog -$cat }
}
} | ? { $_.Mouse -gt 0 }
function winner?($combination) {
return $combination.Dog * 15 + $combination.Cat * 1 + $combination.Mouse * 0.25 -eq 100
}
$winner = $combinations | ? { winner? $_ }
1..98 | % {
$dog = $_
1..98 | % {
$cat = $_
@{
"Dog" = $dog
"Cat" = $cat
"Mouse" = 100 - $dog -$cat
}
}
} | ? {
$_.Mouse -gt 0
} | ? { $_.Dog * 15 + $_.Cat * 1 + $_.Mouse * 0.25 -eq 100 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment