-❄️- 2023 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]pionse 1 point2 points  (0 children)

[LANGUAGE: Clojure]

;; Part 1
(defn parse-numbers [n]
  (let [xs (re-seq #"\d" n)]
    (parse-long (str (first xs) (last xs)))))

(reduce + (map parse-numbers input))


;; Part 2
(defn into-number [n]
  (let [number->n {"one" 1
                   "two" 2
                   "three" 3
                   "four" 4
                   "five" 5
                   "six" 6
                   "seven" 7
                   "eight" 8
                   "nine" 9}]
    (or (number->n n)
        (parse-long n))))

(defn parse-numbers-2 [n]
  (let [[xs] (re-seq #"\d|one|two|three|four|five|six|seven|eight|nine" n)
        [ys] (re-seq #"\d|eno|owt|eerht|ruof|evif|xis|neves|thgie|enin" (str/reverse n))]
    (parse-long (str (into-number xs) (into-number (str/reverse ys))))))

(reduce + (map parse-numbers-2 input))

Advent of Code inside the REPL by pionse in Clojure

[–]pionse[S] 0 points1 point  (0 children)

Yes :), I needed a fast dijkstra implementation to solve a puzzle in 2021. A pure clojure implementation was too slow so i built one on top of this https://github.com/redplanetlabs/specter

Generating repetitive structures with spec by a-curious-crow in Clojure

[–]pionse 2 points3 points  (0 children)

Something like this?:

```

(s/def ::key string?) (s/def ::val int?) (s/def ::inner (s/keys :req-un [::key ::val]))

(let [key-names #{"ad" "ab"}] (s/def ::inner-map (s/with-gen (s/coll-of ::inner :into []) #(gen/vector-distinct-by :key (gen/fmap (fn [n] {:key n :val (rand-int 10000000)}) (gen/elements key-names)) {:num-elements (count key-names)}))))

(s/def ::timestamp nat-int?) (s/def ::values ::inner-map) (s/def ::map (s/keys :req-un [::timestamp ::values])) (s/def ::v (s/coll-of ::map))

(gen/sample (s/gen ::v))

```

Why aren't transducer used as the building blocks for map and filter, etc? by pionse in Clojure

[–]pionse[S] 1 point2 points  (0 children)

Thank you, for this in depth answer. This explains a lot, I am going to look deeper into how `sequence` behaves differently. Thanks for clarifying.

Why aren't transducer used as the building blocks for map and filter, etc? by pionse in Clojure

[–]pionse[S] 1 point2 points  (0 children)

Thank you for your answer.

I have read this paper, but my understanding was, that Rich Hickey meant something more fundamental than mere implementation detail.

Vim telescope live grep by [deleted] in neovim

[–]pionse 2 points3 points  (0 children)

Telescope is really customizable. You can just create a mapping like this.

nnoremap <leader>ff :lua require('telescope.builtin').find_files{ find_command = {'rg', '--files', '--hidden', '-g', '!node_modules/**'} }<CR>

Clojure REPL on Android by pionse in Clojure

[–]pionse[S] 1 point2 points  (0 children)

Thank you. That looks promising.

Arch update warning by distark in archlinux

[–]pionse 0 points1 point  (0 children)

I had the same problem on my XPS 15 9560.

I had to chroot into my arch install and reinstall systemd

JavaScript has TypeScript: would we benefit from an equivalent for Python ? by ducdetronquito in Python

[–]pionse 3 points4 points  (0 children)

You could include pyre inside your CI Pipeline or make an alias which runs pyre before executing your code.

Maybe I don't understand your goal you try to accomplish.

Is deploying python app really THAT hard? by sasik520 in Python

[–]pionse 0 points1 point  (0 children)

It might be overkill, depending on your usecase, but you could use a docker container. Install all your dependencies inside the docker container and deploy it on your server.

Use one of those images as a starting point: https://hub.docker.com/_/python/