#!/usr/bin/env -S swipl %-- mode: prolog; -- :- module(prj4sol, [ sublistlengths/2,…
- User
#!/usr/bin/env -S swipl %-- mode: prolog; --
:- module(prj4_sol, [ sublist_lengths/2, same_length_sublists/1, fibonacci_sublists/1, assoc_lookup/3, assoc_replace/3, add_to_plus_expr/2, named_to_op_expr/2, named_expr_eval/2, named_expr_to_prefix_tokens/2, op_expr_to_prefix_tokens/2 ]).
%%%%%%%%%%%%%%%%%%%%%%%%%%% sublist_lengths/2 %%%%%%%%%%%%%%%%%%%%%%%%%%%
sublist_lengths([], []). sublist_lengths([H|T], [Len|LT]) :- length(H, Len), sublist_lengths(T, LT).
:-begin_tests(sublist_lengths). test(empty, [nondet]) :- sublist_lengths([], Lengths), Lengths = []. test(sublist_lengths1, [nondet]) :- sublist_lengths([[a, b]], Lengths), Lengths = [2]. test(sublist_lengths3, [nondet]) :- sublist_lengths([[2], [a, b], [x, y, z]], Lengths), Lengths = [1, 2, 3]. test(sublist_lengths_var_list, [nondet]) :- sublist_lengths(List, [1, 2, 3]), length(List, 3). :-end_tests(sublist_lengths).
%%%%%%%%%%%%%%%%%%%%%%%%% same_length_sublists/1 %%%%%%%%%%%%%%%%%%%%%%%%
all_same_length([]). all_same_length([_]). all_same_length([X, Y | T]) :- length(X, L), length(Y, L), all_same_length([Y | T]).
same_length_sublists(List) :- all_same_length(List).
:-begin_tests(same_length_sublists). test(empty, [nondet]) :- same_length_sublists([]). test(empties, [nondet]) :- same_length_sublists([[], [], []]). test(empties_fail, [fail]) :- same_length_sublists([[], [2], []]). test(sublists1, [nondet]) :- same_length_sublists([[[a, 2]], [[]], [c]]). test(sublists1_fail, [fail]) :- same_length_sublists([[a], [[]], [c, 2]]). test(sublists3, [nondet]) :- same_length_sublists([[a, [2], 4], [b, 5, [1]], [3, 2, c]]). test(sublists3_fail, [fail]) :- same_length_sublists([[a, 2, 4], [b, 5, 1], [3, [2, c]]]). :-end_tests(same_length_sublists).
%%%%%%%%%%%%%%%%%%%%%%%%%% fibonacci_sublists/1 %%%%%%%%%%%%%%%%%%%%%%%%%
fibonacci_sublists([]). fibonacci_sublists([]). fibonacci_sublists([, _]). fibonacci_sublists([A, B, C|T]) :- length(A, AL), length(B, BL), length(C, CL), CL is AL + BL, fibonacci_sublists([B, C|T]).
:-begin_tests(fibonacci_sublists). test(empty, [nondet]) :- fibonacci_sublists([]). test(zero, [nondet]) :- fibonacci_sublists([[]]). test(one, [nondet]) :- fibonacci_sublists([[], [a]]). test(two, [nondet]) :- fibonacci_sublists([[], [a], [c]]). test(three, [nondet]) :- fibonacci_sublists([[], [a], [c], [a, c]]). test(three_fail, [fail]) :- fibonacci_sublists([[], [a], [c], [a, c, c]]). test(four, [nondet]) :- fibonacci_sublists([[], [a], [c], [a, c], [1, 2, 3] ]). test(four_fail, [fail]) :- fibonacci_sublists([[], [a], [c], [a, c], [1, 2, 3, 4] ]). :-end_tests(fibonacci_sublists).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% assoc_lookup/3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
assoc_lookup(Assoc, Key, Value) :- member((Key, Value), Assoc).
:-begin_tests(assoc_lookup). test(empty, [fail]) :- assoc_lookup([], key, _Value). test(first, [nondet]) :- assoc_lookup([(key, 42), (a, 22), (b, 33)], key, Value), 42 = Value. :-end_tests(assoc_lookup).
- Assistant
- User
write the correct procedure for that
- Assistant
- User
Follow the restrictions, understand previous implemented procedures and then write the procedure for this task
- Assistant
- User
I want the procedure
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.