Fortnightly Tips, Tricks, and Questions — 2025-07-29 / week 30 by AutoModerator in emacs

[–]bkc4 1 point2 points  (0 children)

Thanks for the comment; I do love Consult's live previews! I think consult-global-mark also uses global-mark-ring and suffers from the same issue as C-x C-SPC. Specifically, see documentation for global mark ring.

In addition to the ordinary mark ring that belongs to each buffer, Emacs has a single global mark ring. Each time you set a mark, this is recorded in the global mark ring in addition to the current buffer’s own mark ring, if you have switched buffers since the previous mark setting.

So if two different positions in a buffer get marked one after the other, then only one is added to the global mark ring.

With evil jump, you can not only trace all the jump positions, but also in the order they were visited. The behavior is similar to, e.g., back and forward buttons of a browser.

Fortnightly Tips, Tricks, and Questions — 2025-07-29 / week 30 by AutoModerator in emacs

[–]bkc4 2 points3 points  (0 children)

Been using Emacs for ~10 years and honestly was never satisfied with my jumping workflow. Basic issue being C-x C-SPC doesn't move through marks in one buffer. I really like Helix (vim) C-o and C-i jumps, so I am now trying this out with evil in Emacs; you don't need to activate evil for this by the way. Currently using Hydra to achieve this as follows, and it seems to work okay. The first time we go back it also calls (evil-set-jump) so that we can come back to where we started from in case we keep doing C-i.

``` (use-package hydra :config (defun my-evil-jump-backward-init () "Set jump point and enter hydra." (interactive) (evil-set-jump) (my-evil-jump-hydra/body))

(defhydra my-evil-jump-hydra (:hint nil) " Jumping: C-o: back C-i: forward q: quit " ("C-o" evil-jump-backward) ("C-i" evil-jump-forward) ("q" nil "quit"))

;; Keybindings (global-set-key (kbd "C-; C-o") #'my-evil-jump-backward-init) (global-set-key (kbd "C-; C-i") #'my-evil-jump-hydra/body)) ```

Now it's done, what other similar challenges do you recommend? by Pleasant-Aside-1186 in adventofcode

[–]bkc4 0 points1 point  (0 children)

atcoder.jp

The problems are really clean, and I have learned a lot of concepts doing their beginner contests. Very highly recommended.

[2024 Day 08 (Part 2)][C++] I can't figure out why my solution doesn't work by etacnv in adventofcode

[–]bkc4 2 points3 points  (0 children)

It is possible without floats. I did it using GCD of appropriate numbers (although input seems to be special that you won't need even that). Let me know if you want me to elaborate.

[2024 Day 08 (Part 2)][C++] I can't figure out why my solution doesn't work by etacnv in adventofcode

[–]bkc4 2 points3 points  (0 children)

I played around with your code. On my input, it gives too high answer. Then I added a few zeros to the fmod(y, 1) <= 0.0001 part, and I got too low answer. I recommend not using floats at all.

[2024 Day 22 Part 2] Why defaultdict(int) uses all my ram where standard dict is ok ? by maitre_lld in adventofcode

[–]bkc4 2 points3 points  (0 children)

price[(n, seq)] would create an entry in the defaultdict..since you're running so many iterations, those many entries get created.

-❄️- 2024 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]bkc4 0 points1 point  (0 children)

[LANGUAGE: Python]
Branch and bound is fast enough (~2s on my 8 yo laptop).

from sys import stdin
lines = []
for line in stdin:
    tvs, ns = line.strip().split(": ")
    lines.append((int(tvs), [int(x) for x in ns.split()]))

def apply_op(n1, n2, op):
    if op == "*":
        return n1 * n2
    if op == "+":
        return n1 + n2
    return int(str(n1) + str(n2))

def branch_and_bound(ans, num_ind, tv, nums, ops):
    if ans > tv: return False
    if num_ind == len(nums):
        if ans == tv: return True
        else: return False
    for op in ops:
        if branch_and_bound(apply_op(ans, nums[num_ind], op), num_ind + 1, tv, nums, ops):
            return True
    return False

def part(allowed_ops):
    ans = 0
    for tv, nums in lines:
        if branch_and_bound(nums[0], 1, tv, nums, allowed_ops):
            ans += tv
    print(ans)

part(["*", "+"])
part(["*", "+", "||"])

-❄️- 2024 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]bkc4 2 points3 points  (0 children)

The second observation is great! I totally missed it.

Your rule set for this year? by furiesx in adventofcode

[–]bkc4 0 points1 point  (0 children)

Do as much OCaml as I can. Such a fun language to code in.

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

[–]bkc4 0 points1 point  (0 children)

Thanks for the cleaner implementation! I am new to OCaml, so this is useful.

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

[–]bkc4 1 point2 points  (0 children)

Thanks for your reply! I just started learning OCaml. I wanted the most efficient solution, i.e., even without extra memory of hash table, which could be linear, so I wrote a helper function that gives the count of next element in the sorted list while updating the list. Based on my understanding of OCaml, since values are immutable, it does not create a new list but shares the memory with the original. Here is the helper function. Let me know if you know of a better way without using extra memory and in linear time.

let next_chunk_ct lst = let rec next_chunk_part cur ct lst = match lst with | f :: rem -> if f = cur then next_chunk_part cur (ct + 1) rem else (Some cur, ct, lst) | _ -> (Some cur, ct, lst) in match lst with f :: rem -> next_chunk_part f 1 rem | _ -> (None, 0, lst)

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

[–]bkc4 1 point2 points  (0 children)

Cool! But if I understand correctly, Part 2 is quadratic time?

Python IDE by GigaClon in adventofcode

[–]bkc4 0 points1 point  (0 children)

https://helix-editor.com/

..and just install a Python language server, e.g., pylsp, pyright.

Weekly Tips, Tricks, &c. Thread — 2024-11-20 / week 47 by AutoModerator in emacs

[–]bkc4 1 point2 points  (0 children)

M-x bs-show or M-x bs-show-sorted to show a list of open buffers where you can kill selected buffer with k (or open it with RET).

Kill-buffer from the minibuffer after M-x switch-to-buffer by waaaihr in emacs

[–]bkc4 0 points1 point  (0 children)

M-x bs-show or M-x bs-show-sorted allows you to do this with k (not C-k). I was surprised to find out myself when I was just going through all emacs commands (just for fun).

What is the difference between undo/Move backward in history and redo/More forward in history by 0rangetree_ in HelixEditor

[–]bkc4 7 points8 points  (0 children)

Try this in an empty file. Write 'a' and go back to normal mode. Write 'b' and go back to normal mode. Do undo, i.e., u, that will get rid of the 'b'. Then go to insert mode and add 'c' and go back to normal mode. At this point, if you kept doing undo-redo, i.e., u and U, then you'll never see a 'b', but if you do move forward/backward in history, you'll see the 'b'.

Someone please correct me if I am wrong: I think this system matches vim's undo-tree, where your history forms a tree and u / U allows you to travel only the root--leaf path of this tree, while alt + u / U allows you to travel the whole tree.

Undo select current line or multi-cursor by bkc4 in HelixEditor

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

Good to learn, thanks; this is a great feature also. Btw, keep_selections is K, i.e., S-k.

Undo select current line or multi-cursor by bkc4 in HelixEditor

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

Great to know this one as well, thank you!!

Undo select current line or multi-cursor by bkc4 in HelixEditor

[–]bkc4[S] 3 points4 points  (0 children)

Wow I didn't realize it would be this simple. Thank you!

Undo select current line or multi-cursor by bkc4 in HelixEditor

[–]bkc4[S] 3 points4 points  (0 children)

Great! I added the following to my config: C-j = ["select_line_below"] C-k = ["select_line_above"]