@freemo @Absinthe
My attempt without division
https://git.sr.ht/~namark/mercury_stuff/tree/master/toys/other_product_no_div.m
It's linear but requires 3x the space. The idea is to calculate partial products of the list, from left to right, and right to left, then the final values based on corresponding neighbouring values in partial product lists.
Probably the worst explanation and my mercury code seems unreadable to me, so here's a c++ version
http://ix.io/1KzG/cpp
Common Lisp again:
(defun excluded-product (sequence)
(let ((product (reduce #'* sequence :initial-value 1)))
(map 'list (lambda (x) (/ product x)) sequence)))
(defun excluded-product-without-division (sequence)
(flet ((prod (seq)
(reduce #'* seq :initial-value 1)))
(loop while (cdr sequence)
for tail = (cdr sequence) then (cdr tail)
for head = nil then (append head (list (pop sequence)))
collect (* (prod head) (prod tail)))))