<commit_before>
:- object(hanoi(_Threads)).

	:- info([
		version is 1.1,
		date is 2007/12/27,
		author is '<NAME>',
		comment is 'Multi-threaded version of the Towers of Hanoi problem.',
		parameters is ['Threads'- 'Number of threads to use. Valid values are 1, 2, 4, 8, 16, etc.']]).

	:- threaded.

	:- public(run/1).
	:- mode(run(+integer), one).
	:- info(run/1, [
		comment is 'Solves the towers of Hanoi problem for the specified number of disks.',
		argnames is ['Disks']]).

	run(Disks) :-
		parameter(1, Threads),
		mt_move(Threads, Disks, left, middle, right).

	mt_move(1, Disks, Left, Aux, Right) :- !,
		st_move(Disks, Left, Aux, Right).
	mt_move(Threads, Disks, Left, Aux, Right) :-
		Threads > 1,
		Threads2 is Threads//2,
		Disks > 1,
		Disks2 is Disks - 1,
		threaded((
			mt_move(Threads2, Disks2, Left, Right, Aux),
			mt_move(Threads2, Disks2, Aux, Left, Right)
		)).

	st_move(1, _Left, _, _Right) :- !.
	st_move(Disks, Left, Aux, Right) :-
		Disks > 1,
		Disks2 is Disks - 1,
		st_move(Disks2, Left, Right, Aux),
		st_move(Disks2, Aux, Left, Right).

:- end_object.
<commit_msg>Updated the "hanoi" multi-threading example to collect and return all moves instead of simply simulating them.<commit_after>
:- object(hanoi(_Threads)).

	:- info([
		version is 1.1,
		date is 2007/12/27,
		author is '<NAME>',
		comment is 'Multi-threaded version of the Towers of Hanoi problem.',
		parameters is ['Threads'- 'Number of threads to use. Valid values are 1, 2, 4, 8, 16, etc.']]).

	:- threaded.

	:- public(run/2).
	:- mode(run(+integer, -list), one).
	:- info(run/2, [
		comment is 'Solves the towers of Hanoi problem for the specified number of disks.',
		argnames is ['Disks', 'Moves']]).

	run(Disks, Moves) :-
		parameter(1, Threads),
		mt_move(Threads, Disks, left, middle, right, [], Moves).

	mt_move(1, Disks, Left, Aux, Right, Acc, Moves) :- !,
		st_move(Disks, Left, Aux, Right, Acc, Moves).
	mt_move(Threads, Disks, Left, Aux, Right, Acc, Moves) :-
		Threads > 1,
		Threads2 is Threads//2,
		Disks > 1,
		Disks2 is Disks - 1,
		threaded((
			mt_move(Threads2, Disks2, Left, Right, Aux, [Left-Right| Acc2], Moves),
			mt_move(Threads2, Disks2, Aux, Left, Right, Acc, Acc2)
		)).

	st_move(1, Left, _, Right, Acc, [Left-Right| Acc]) :- !.
	st_move(Disks, Left, Aux, Right, Acc, Moves) :-
		Disks > 1,
		Disks2 is Disks - 1,
		st_move(Disks2, Left, Right, Aux, [Left-Right| Acc2], Moves),
		st_move(Disks2, Aux, Left, Right, Acc, Acc2).

	write_moves([]).
	write_moves([Move| Moves]) :-
		write_move(Move), nl,
		write_moves(Moves).

	write_move(Pole1-Pole2) :-
		write('Move a disk from '),
		writeq(Pole1),
		write(' to '),
		writeq(Pole2),
		write('.'),
		nl.

:- end_object.

{'fraction_non_alphanumeric': 0.16820702402957485, 'fraction_numerical': 0.029574861367837338, 'mean_word_length': 3.5175292153589317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5086591', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1073, 'n_words': 311}