Skip to content

Instantly share code, notes, and snippets.

View laurentpetit's full-sized avatar

Laurent Petit laurentpetit

View GitHub Profile
@laurentpetit
laurentpetit / gist:4976706
Created February 18, 2013 11:21
Je suis à vie biaisé par la prog. fonctionnelle. Impossible pour moi de voir ce genre de code sans penser : "y'a un bug, comment ça peut même fonctionner !"
@Override
public void saveContent(ConstList item) {
List<ConstListElement> elements = item.getElements();
elements.clear();
for( Element element : getList().getItems() ){
elements.add(element.getConstListElement());
}
}
(defn find+download-deps [project-string]
; left as an exercise to the reader (pun intended)
)
@laurentpetit
laurentpetit / gist:4677475
Created January 30, 2013 21:52
Solution Clojure pour l'échoppe de monades de scalaskel. Pour l'algorithme commenté, voir https://gist.github.com/4677385
(defn- changes-envisageables [montant valeur-faciale]
(range 0 (inc (quot montant valeur-faciale))))
(defn- reste-a-rendre [montant nb-pieces valeur-faciale]
(- montant (* nb-pieces valeur-faciale)))
(defn changes [montant]
(let [BAR 7, QIX 11, BAZ 21]
(for [nb-baz (changes-envisageables montant BAZ)
:let [reste (reste-a-rendre montant nb-baz BAZ)]
@laurentpetit
laurentpetit / gist:4677385
Last active December 11, 2015 23:29
Solution Clojure pour l'échoppe de monades de scalaskel - ALGORITHME COMMENTE
(defn- changes-envisageables
"Pour un montant amount, quelles quantites de pieces
de valeur faciale face pouvons-nous rendre.
Par exemple pour un montant de 21, et un pièce de valeur faciale 7,
la réponse sera (0, 1, 2, 3).
Tip: (quot amount face) renvoie le quotient entier de la division de amount
par face"
[montant valeur-faciale]
(range 0 (inc (quot montant valeur-faciale))))
=> (post-enonce2 "[ { \"VOL\": \"bright-telescope-91\", \"DEPART\": 2, \"DUREE\": 7, \"PRIX\": 21 }, { \"VOL\": \"steep-farmhand-81\", \"DEPART\": 0, \"DUREE\": 1, \"PRIX\": 12 }, { \"VOL\": \"shrill-peephole-67\", \"DEPART\": 4, \"DUREE\": 3, \"PRIX\": 3 }, { \"VOL\": \"crazy-watchtower-73\", \"DEPART\": 1, \"DUREE\": 1, \"PRIX\": 6 }, { \"VOL\": \"curious-mainframe-35\", \"DEPART\": 4, \"DUREE\": 17, \"PRIX\": 4 }, { \"VOL\": \"tender-lava-90\", \"DEPART\": 9, \"DUREE\": 2, \"PRIX\": 6 }, { \"VOL\": \"hungry-backward-44\", \"DEPART\": 9, \"DUREE\": 1, \"PRIX\": 7 }, { \"VOL\": \"super-genie-14\", \"DEPART\": 6, \"DUREE\": 5, \"PRIX\": 6 }, { \"VOL\": \"vast-yak-32\", \"DEPART\": 8, \"DUREE\": 3, \"PRIX\": 8 }, { \"VOL\": \"high-pitched-dunce-44\", \"DEPART\": 9, \"DUREE\": 3, \"PRIX\": 1 } ]")
:uri /jajascript/optimize0.806, Query:"10 enchères: [ { "VOL": "bright-telescope-91", "DEPART": 2, "DUREE": 7, "PRIX": 21 }, { "VOL": "steep-farmhand-81", "DEPART": 0, "DUREE": 1, "PRIX": 12 }, { "VOL": "shrill-peepho
=> (post-enonce2 "[ { \"VOL\": \"bright-telescope-91\", \"DEPART\": 2, \"DUREE\": 7, \"PRIX\": 21 }, { \"VOL\": \"steep-farmhand-81\", \"DEPART\": 0, \"DUREE\": 1, \"PRIX\": 12 }, { \"VOL\": \"shrill-peephole-67\", \"DEPART\": 4, \"DUREE\": 3, \"PRIX\": 3 }, { \"VOL\": \"crazy-watchtower-73\", \"DEPART\": 1, \"DUREE\": 1, \"PRIX\": 6 }, { \"VOL\": \"curious-mainframe-35\", \"DEPART\": 4, \"DUREE\": 17, \"PRIX\": 4 }, { \"VOL\": \"tender-lava-90\", \"DEPART\": 9, \"DUREE\": 2, \"PRIX\": 6 }, { \"VOL\": \"hungry-backward-44\", \"DEPART\": 9, \"DUREE\": 1, \"PRIX\": 7 }, { \"VOL\": \"super-genie-14\", \"DEPART\": 6, \"DUREE\": 5, \"PRIX\": 6 }, { \"VOL\": \"vast-yak-32\", \"DEPART\": 8, \"DUREE\": 3, \"PRIX\": 8 }, { \"VOL\": \"high-pitched-dunce-44\", \"DEPART\": 9, \"DUREE\": 3, \"PRIX\": 1 } ]")
:uri /jajascript/optimize0.806, Query:"10 enchères: [ { "VOL": "bright-telescope-91", "DEPART": 2, "DUREE": 7, "PRIX": 21 }, { "VOL": "steep-farmhand-81", "DEPART": 0, "DUREE": 1, "PRIX": 12 }, { "VOL": "shrill-peepho
@laurentpetit
laurentpetit / ccw-0.11.0-patch-lein-new.clj
Last active December 11, 2015 15:08
Tentative fix for the CCW 0.11.0 issue when creating new leiningen projects
;; Tentative fix for the CCW 0.11.0 issue when creating new leiningen projects
;; - In your running Eclipse, open an embedded REPL View (a REPLView which will be directly connected to the JVM running your Eclipse !) :
;; - Mac= Cmd+Alt+Q (Win/Lin= Ctrl+Alt+Q), then select "New REPL client for embedded Eclipse nrepl server"
;; - a REPL View should appear
;; - Copy the content of this patch into the REPL's input area and evaluate it as usual
;; - If everything goes fine, you should see "#'ccw.leiningen.util/lein-project" in the REPL log area
;; - You should now be able to create new projects with the leiningen wizard
(def lein-bundle (ccw.util.bundle/load-and-get-bundle "ccw.leiningen"))
(defn optimize [bids]
(letfn [(plan-at [plans h] (val (first (subseq plans >= h))))
(step [plans [h bids]]
(assoc plans h (apply max-key :gain (val (first plans))
(for [{:keys [vol depart prix]} bids
:let [{:keys [gain path]} (plan-at plans depart)]]
{:gain (+ gain prix) :path (conj path vol)}))))]
(val (first (reduce step (sorted-map-by > 0 {:gain 0 :path []})
(sort-by key (group-by #(+ (:duree %) (:depart %)) bids)))))))
;; query
{:ssl-client-cert nil,
:remote-addr "10.82.21.198",
:scheme :http,
:request-method :post,
:query-string nil,
:content-type "application/x-www-form-urlencoded",
:uri "/jajascript/optimize",
:server-name "codestory2013.herokuapp.com",
:headers {"x-heroku-dynos-in-use" "1",
@laurentpetit
laurentpetit / gist:4538379
Last active December 11, 2015 03:29
enonce 2

Location d'astronef sur Jajascript

Votre cousin par alliance, Martin O. sur la planète Jajascript vient de monter sa petite entreprise de vol spatial privée: Jajascript Flight Rental. Il loue aux grosses corporations son astronef lorsqu'elles ont de fortes charges ou un pépin avec leurs propres appareils. Il s'occupe de la maintenance et de l'entretien de son petit astronef. Il ne pouvait s'en payer qu'un pour démarrer.

Ces grosses corporations envoient des commandes de location qui consistent en un intervalle de temps, et le prix qu'ils sont prêts à payer pour louer l'astronef durant cet intervalle.

Les commandes de tous les clients sont connues plusieurs jours à l'avance. Ce qui permet de faire un planning pour une journée. Les commandes viennent de plusieurs sociétés différentes et parfois elles se chevauchent. On ne peut donc pas toutes les honorer.

Idéalement, il faut donc être capable de prendre les plus rentables, histoire de maximiser les gains de sa petite entreprise, et de s'acheter d'autres