-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5dd59a
commit b71b7d1
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
(ns main | ||
(:require [clojure.string :as str])) | ||
|
||
(defn debug [x] | ||
(println x) | ||
x) | ||
(defn gimme-type [x] | ||
(println (type x)) | ||
x) | ||
|
||
(defn gcd [a b] | ||
(println (type a) " - " (type b)) | ||
(loop [a' a | ||
b' b] | ||
(println (type a') " - " (type b')) | ||
(if (= 0 b') | ||
a' | ||
(recur 'b (mod a' b'))))) | ||
|
||
(defn process-input [line] | ||
(let [[a' _ b' o c' _ d'] (str/split line #" ") | ||
[a b c d] (map #(Integer/parseInt %) [a' b' c' d'])] | ||
(cond | ||
(= o "+") | ||
(-> (* b d) | ||
(* a) | ||
(/ b) | ||
(+ (* b d)) | ||
(* c) | ||
(/ d) | ||
(gcd (* b d))) | ||
(= o "-") | ||
(-> (* b d) | ||
(* a) | ||
(/ b) | ||
(- (* b d)) | ||
(* c) | ||
(/ d) | ||
(gcd (* b d))) | ||
(= o "*") | ||
(-> a | ||
(* c) | ||
(gcd (* b d))) | ||
:else | ||
(-> a | ||
(debug) | ||
(gimme-type) | ||
(* d) | ||
(debug) | ||
(gimme-type) | ||
(gcd (* b c)))))) | ||
|
||
(defn main [] | ||
(let [c (-> (read-line) | ||
(Integer/parseInt))] | ||
(loop [c' c] | ||
(process-input (read-line)) | ||
(when c' | ||
(recur (- c' 1)))))) | ||
|
||
(main) |
Empty file.