I can easily parse strings with DCG using the Mercury programming language. It is compiled, statically typed, and fast.

#prolog #mercurylang #programming

Now I have added #Mercury --

https://rosettacode.org/wiki/Modular_arithmetic#Mercury

#RosettaCode #MercuryLang #LogicProgramming #FunctionalProgramming

(For convenience I use higher-order functions, so that the Functional Programming hashtag makes sense. Also, Mercury is a language in which tail recursion is the preferred method of looping. And, it just occurs to me, I wrote the program mostly as ‘functions’ rather than ‘predicates’!)

Modular arithmetic

Modular arithmetic is a form of arithmetic (a calculation technique involving the concepts of addition and multiplication) which is done on numbers with a defined...

Rosetta Code
@jsatk For me, it would be #MercuryLang or #Teyjus. Don't know when I'll make time though.

There is no order of evaluation, other than the order of evaluation that works.

#mercurylang

@codesections @freemo *writes them down to use as two way function names in mercury* #mercurylang

@Absinthe How about, one crazy function that works both ways!
https://git.sr.ht/~namark/mercury_stuff/tree/master/toys/serialize_btree.m

Though, it goes haywire if input is invalid or if value contains anything in the form of "|number|", where number is less than depth of the tree. Probably has something to do with compiler complaining that code I wrote is impure and non-deterministic, and me just silencing it.
Also it only handles string values, cause I don't know how to write generic code yet.

#toyprogrammingchallenge #mercurylang

~namark/mercury_stuff: toys/serialize_btree.m - sourcehut git

@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

#toyprogrammingchallenge
#mercurylang #cpp

~namark/mercury_stuff: toys/other_product_no_div.m - sourcehut git

@Absinthe
other product using division
https://git.sr.ht/~namark/mercury_stuff/tree/master/toys/other_product.m
hate all the edge cases

no division version in the working, hopefully would be much smoother.

#toyprogrammingchallenge #mercurylang

~namark/mercury_stuff: toys/other_product.m - sourcehut git

@Absinthe this one was actually "easy", just translated the description and mercury solved it for me (no squinting required), so I decided to throw in some input handling and that was the painful part as usual.
https://git.sr.ht/~namark/mercury_stuff/tree/master/toys/pairs_add_up_to.m

But of course the real challenge is doing it in one pass... in a language that might not have a concept of a pass...

#toyprogrammingchallenge #mercurylang

~namark/mercury_stuff: toys/pairs_add_up_to.m - sourcehut git

ninety nine vials of mercury
https://git.sr.ht/~namark/mercury_stuff/tree/master/toys/vials.m
took me ages and is probably the worst way to do it... worth it!
#toyprogrammingchallenge #mercurylang
~namark/mercury_stuff: toys/vials.m - sourcehut git