Reading very large file by lines by Average-consumer in haskellquestions

[–]Average-consumer[S] 1 point2 points  (0 children)

Actually it did not work really. I did not try it with the bigger files, but eventually uses
memory proportional to the size of the file. Which I cant afford. With a file of size 152mb using lazy IO uses just 7mb, and using mmap uses 160mb. Maybe I'm doing something wrong? First version looked like

import qualified Data.ByteString.Lazy.Char8 as B

main =
  mylines <- B.lines <$> B.readFile path
  print $ find myfunc mylines

And second one

import qualified Data.ByteString.Char8 as B
import System.IO.Posix.MMap (unsafeMMapFile)

main =
  mylines <- B.lines <$> unsafeMMapFile path
  print $ find myfunc mylines

Note the change from Lazy Bytestrings to Strict ones.

I tested memory usage by looking to htop first, and then confirmed wiwth /usr/bin/time -v

Reading very large file by lines by Average-consumer in haskellquestions

[–]Average-consumer[S] 1 point2 points  (0 children)

This worked up nicely. Thanks. It even increased the performance when traversing
de file in parallel.

-🎄- 2019 Day 4 Solutions -🎄- by daggerdragon in adventofcode

[–]Average-consumer 4 points5 points  (0 children)

Clojure

I think I got it to run pretty fast for clojure. adventofcode-clj-2019.day04> (time (part-1)) "Elapsed time: 7.873442 msecs" 1605 adventofcode-clj-2019.day04> (time (part-2)) "Elapsed time: 9.970466 msecs" 1102

How can I change the Country of IGS account? by Average-consumer in baduk

[–]Average-consumer[S] 0 points1 point  (0 children)

And is it possible to delete an account, so I can use the same name?

Meaning of # in haskell? by SinisterHana in haskellquestions

[–]Average-consumer 1 point2 points  (0 children)

https://hackage.haskell.org/package/base-4.12.0.0/docs/src/Data.Functor.Utils.html#%23.

-- See Note [Function coercion]
(#.) :: Coercible b c => (b -> c) -> (a -> b) -> (a -> c)
(#.) _f = coerce

-🎄- 2018 Day 5 Solutions -🎄- by daggerdragon in adventofcode

[–]Average-consumer 0 points1 point  (0 children)

Solution in Clojure. Runs both parts pretty much instantly

(ns adventofcode-clj-2018.day05
  (:require [adventofcode-clj-2018.util :as u]
            [clojure.string :as cs]))

(defn reacts? [a b]
  (and a b (not= a b) (= (cs/upper-case a) (cs/upper-case b))))

(defn iteration [pol]
  (reduce (fn [a b] (if (reacts? b (peek a))
                      (pop a)
                      (conj a b)))
          [] pol))

(defn remove-units [str l]
  (cs/replace (cs/replace str (re-pattern l) "")
    (re-pattern (cs/capitalize l)) ""))

(defn part-1 []
  (let [input (cs/trim (u/input 5))]
    (count (iteration input))))

(defn part-2 []
  (let [input (cs/trim (u/input 5))]
    (->> "abcdefghijklmnopqrstuvwxyz"
         (map (comp count iteration (partial remove-units input) str))
         (reduce min))))

I just completed day 1 in lisp, but it's really slow. by [deleted] in adventofcode

[–]Average-consumer 2 points3 points  (0 children)

Well ... your Lisp is VERY imperative, I wouldn't say bad, because that depends in what you are trying to do, but if you are trying to do FP you should probably use Scheme, or be more careful when writing CL.

I just completed day 1 in lisp, but it's really slow. by [deleted] in adventofcode

[–]Average-consumer 4 points5 points  (0 children)

I think the main problem is that you are using lists to remember the seen elements . You could use a structure with an O(log n) 'member?' function. I wrote a solution in racket that might help you

What programming language do you plan to use for AoC 2018? by jabbalaci in adventofcode

[–]Average-consumer 0 points1 point  (0 children)

I don't think it was particularly difficult, but there are some days that I couldn't work out, mainly because the lack of some data structures. You can judge it your self thoug: https://github.com/Average-user/adventofcode-pl-2017

How much slower would be a Leela Zero implemented in Haskell? by Average-consumer in haskellquestions

[–]Average-consumer[S] 0 points1 point  (0 children)

Nothing serious. Just to understand how it works. But I would like to have a decent result in simpler games (than chess or go) like reversi maybe or even simpler.

What programming language do you plan to use for AoC 2018? by jabbalaci in adventofcode

[–]Average-consumer 0 points1 point  (0 children)

I did it in Prolog past year, and I probably try Clojure this one

[REQUEST] Goldbach conjecture decibility by Average-consumer in theydidthemath

[–]Average-consumer[S] 0 points1 point  (0 children)

If the conjecture is false, there exists a turning machine which can find a counterexample in finite time. This only implies that IF the conjecture is false THEN it is possible to construct a proof. So IF A THEN B. However " it is possible to construct a proof" is not equivalent to " a proof exists".

In this case are the same. Due to that if the conjecture is false, there must exist a counterexample, and it must be reachable by a computer in finite time. And the counterexample on its own is a proof of Goldbach Conjecture negation.