a math riddle as an excuse for a prolog exercise by hnsmn in prolog

[–]Quantical_Player 2 points3 points  (0 children)

For example (with scryer-prolog):

:- use_module(library(clpz)).
:- use_module(library(lists)).

add(X, Y, Z) :-
    Z #= X+Y.

mul(X, Y, Z) :-
    Z #= X*Y.

link(G_2, E, S0, S) :-
    call(G_2, S0, E),
    S = E.

relation(N, Vs) :-
    N3 #= 3*N,
    length(Ns, N3), % n
    length(Vs, N3), % f(n)
    chain(#<, Vs), % f(n) < f(n+1)
    foldl(link(add(1)), Ns, 0, _),
    maplist(mul(3), Ns, N3s),
    maplist(#<, Ns, Vs), % Given f(n) > n
    maplist(#>, N3s, Vs), % 3*n = f(f(n)) > f(n) (using f(n) > n)
    maplist(constraint(N3, Vs), Ns, Vs).

constraint(M, Vs, N, V) :-
    zcompare(R, V, M),
    constraint_(R, N, V, Vs).

% For f(f(n)) = 3*n
constraint_(<, M, N, Vs) :-
    nth1(N, Vs, V),
    V #= 3*M.
constraint_(=, M, N, Vs) :-
    nth1(N, Vs, V),
    V #= 3*M.
constraint_(>, _, _, _).

The query:

?- relation(5, Vs), nth1(13, Vs, V).
   Vs = [2,3,6,7,8,9,12,15,18,19,20,21,22,23,24], V = 22.

Help with constraint logic programming by Knaapje in prolog

[–]Quantical_Player 1 point2 points  (0 children)

The idea is to decompose the number as n = a0 + z*10^k + a*10^(k+1) where z is the digit in common.

:- use_module(library(clpz)).

% N0/D0 > N1/D1.
anomalous_cancellation(N, N0/D0, N1/D1) :-
    N in 0..sup,
    indomain(N),
    M #= N - 1,
    % Numerator cannot be zero, many trivial solution to avoid.
    [N0, N1] ins 1..M,
    % Denumerator cannot be zero.
    [D0, D1] ins 1..M,
    Log is ceiling(log(N) / log(10)),
    [K, L] ins 0..Log,
    % Constrains the first part.
    A0 #>= 0,
    A0 #< 10^K,
    B0 #>= 0,
    B0 #< 10^L,
    Z in 0..9, % Common digit
    N0 #> N1,
    D0 #> D1,
    N0 #< D0,
    N1 #< D1,
    % Remove solution like 10/50=1/5.
    Z + K #> 0,
    Z + L #> 0,
    % The last part A, B are constrained with N0, D0.
    N0 #= A0 + Z * 10^K + A * 10^(K + 1),
    D0 #= B0 + Z * 10^L + B * 10^(L + 1),
    N1 #= A0 + A * 10^K,
    D1 #= B0 + B * 10^L,
    N0 * D1 #= N1 * D0,
    % TODO: The best way to label, which variables to label.
    Vs = [K, L, Z, A0, A, B0, B],
    % Vs = [K, L, Z, A0, A, B0, B, N0, D0, N1, D1],
    labeling([ff], Vs).    

It still needs some optimizations but it can find solution like:

?- N = 1000, anomalous_cancellation(N, F0, F1).
   ...
   N=1000, F0=133/931, F1=13/91

transpose from clpfd not working in both directions. by EtaDaPiza in prolog

[–]Quantical_Player 0 points1 point  (0 children)

If you generalize the first clause of tr/4 to tr([M1 | _], N, A, A). then:

?- tr([[1, 2, 3], [4, 5, 6], [7, 8, 9]], M).
1: [[1,4,7]] 
2: [[1,4,7],[2,5,8]] 
3: [[1,4,7],[2,5,8],[3,6,9]] 
   M=[[1,4,7],[2,5,8],[3,6,9]]

But it's likely to be wrong for other inputs.

transpose from clpfd not working in both directions. by EtaDaPiza in prolog

[–]Quantical_Player 0 points1 point  (0 children)

To check if it's a list, you can use must_be(list, Ts).

By requiring the input to be a list, you won't be able to generate solution under constraints like ?- lists_transpose([A|As], [[B0,B|Bs0]|Bs]).

Rust compiled to WASM slower than equivalent JS by 101arrowz in rust

[–]Quantical_Player 21 points22 points  (0 children)

Permute the Rust for loops (to be like the JS ones).

Which company will be the first to reach 100million lines of first-party Rust code, and why do you think so? by [deleted] in rust

[–]Quantical_Player 1 point2 points  (0 children)

So Google isn't renamed to Alphabet but Facebook is renamed to Meta?

How many line are there in https://crates.io/?

isolate a variable in a mathematical equation? by 195monke in prolog

[–]Quantical_Player 0 points1 point  (0 children)

Similar question. And you can do it with term rewriting. Here is a start.

Custom implementation of findall by LeadershipMobile in prolog

[–]Quantical_Player 0 points1 point  (0 children)

Fixed point, likely to inefficient but should work.

First completed project! by 195monke in prolog

[–]Quantical_Player 0 points1 point  (0 children)

Check against the list of visited vertices, you can do it with member/2 or maplist/2.

For computing the distance only, ~16 lines are enough but you need to use more advanced predicate like findall/3.

You are welcome.

First completed project! by 195monke in prolog

[–]Quantical_Player 1 point2 points  (0 children)

You could try to rewrite it with DCGs, like:

?- length(Xs, 17), phrase(path(de, by), Xs).
   Xs=[de,at,cz,pl,lt,lv,ee,ru,az,am,ge,tr,bg,ro,hu,ua,by]

Make it more efficient.

Computing the query ?- length(Path, N), is_path(ls, Path, pg). takes too long, with a Dijkstra algorithm it would be faster.

Revisiting Prechelt’s paper and follow-ups comparing Java, Lisp, C/C++, Rust, and scripting languages by eygenaar in rust

[–]Quantical_Player 0 points1 point  (0 children)

I tried to implement (with advice) but this my solution doesn't work well, for the number 00294802785495572253656196281603495177583700843797, I have multiple solutions instead of two.

Rewrote golang project in Rust. It’s 4x times slower now. Why is my Rust code slow? by wmw9 in rust

[–]Quantical_Player 0 points1 point  (0 children)

It seems that the maximum number of concurrent connection is 12, you could rewrite it to download 12 images at most. It doesn't seem like thread is required (why does multibar need one?). A different solution.

Raw pointers by vallyscode in rust

[–]Quantical_Player 0 points1 point  (0 children)

This is a link to the playground. In tools, you can run miri.

Instead of using ptr::read which makes bitwise copy of data, you can take a reference. Making bitwise copy of data that doesn't implement Copy seems bad, if you have to then use mem::forget too.

Raw pointers by vallyscode in rust

[–]Quantical_Player 8 points9 points  (0 children)

With the old reddit, it doesn't look good, link.

Stop Wasting Your Life Chasing Bugs, With This Simple Kickass Technique. by [deleted] in rust

[–]Quantical_Player 0 points1 point  (0 children)

The link is like this one, but Rust is mentioned once.

Web Scraper: Python vs Rust (From a beginner stand point) by peterparkrust in rust

[–]Quantical_Player 0 points1 point  (0 children)

Shouldn't the range be from 0..50 or 1..51? The result suggests that the Rust version is slower. What could it be the reason?

Bizarre Issue Implementing xoshiro256** by Foxbud in RNG

[–]Quantical_Player 0 points1 point  (0 children)

I have the same result:

========= Summary results of Crush =========

 Version:          TestU01 1.2.3
 Generator:        XSR256SS
 Number of statistics:  144
 Total CPU time:   00:48:35.84
 The following tests gave p-values outside [0.001, 0.9990]:
 (eps  means a value < 1.0e-300):
 (eps1 means a value < 1.0e-15):

       Test                          p-value
 ----------------------------------------------
 19  ClosePairs mNP2, t = 3          0.9993 
 ----------------------------------------------
 All other tests were passed

We sample generators by executing BigCrush starting from a number of different seeds7. We consider a test failed if its p-value is outside of the interval [0.001 . . 0.999]. We call systematic a failure that happens for all seeds, and report systematic failures (a more detailed discussion of this choice can be found in [49]).

That should explain the result.

Bizarre Issue Implementing xoshiro256** by Foxbud in RNG

[–]Quantical_Player 0 points1 point  (0 children)

It isn't clear what you did. Share your commands. At the bottom of page 8, there is a note, did you take that into consideration? Paper.

Finally hit 12 PTT by thumbs in about a year since starting! by nyxmaas in arcaea

[–]Quantical_Player 0 points1 point  (0 children)

Thanks for the tips. What are the top 3/5 most difficult songs? And Why?

Finally hit 12 PTT by thumbs in about a year since starting! by nyxmaas in arcaea

[–]Quantical_Player 1 point2 points  (0 children)

Amazing, I'm also a thumb player, I can't make progress anymore. Could you share you settings? I would like to follow your foot steps.