NAME=push_swap
-SRCS=algorithm_complex.c algorithm_leafsort.c algorithm_simple.c cheatalloc.c clist.c closure.c leaf_sort.c leaf_sort_index.c leaf_sort_parse.c list.c main_pushswap.c op_count.c op_output.c op_p.c op_parse.c op_r.c op_rr.c op_s.c ops.c ops_groups.c ops_optimizer.c output.c psval.c slice.c splitsort.c splitsort_final.c splitsort_iter.c splitsort_part.c stack.c stacks.c stacks_get.c
+SRCS=algorithm_complex.c algorithm_leafsort.c algorithm_simple.c cheatalloc.c clist.c closure.c leaf_sort.c leaf_sort_index.c leaf_sort_parse.c list.c main_pushswap.c op_output.c op_p.c op_parse.c op_r.c op_rr.c op_s.c ops.c ops_count.c ops_optimizer.c ops_stackops.c output.c psval.c slice.c splitsort.c splitsort_final.c splitsort_iter.c splitsort_part.c stack.c stacks.c stacks_get.c
RESSRCS=_res_leaf_sort_lookup.h
/* By: clefrere <clefrere@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/02 22:15:12 by agilliar #+# #+# */
-/* Updated: 2025/12/16 14:55:34 by agilliar ### ########.fr */
+/* Updated: 2025/12/16 19:13:54 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
stack_push_back(&arg->state.a, psval_parse(str));
}
-int main(int argc, char **argv)
+typedef struct s_benchres
+{
+ t_ops_count pre_opt;
+ t_ops_count post_opt;
+ t_slice strategy;
+ float disorder;
+} t_benchres;
+
+static t_benchres pushswap_solve(t_args *args)
{
- t_args args;
t_ops ops;
t_optimizer opt;
+ t_benchres res;
+
+ ops = ops_compose(ops_output(), ops_count(&res.post_opt));
+ ops = ops_optimizer(ops, &opt);
+ ops = ops_compose(ops_stackops(), ops);
+ ops = ops_compose(ops_count(&res.pre_opt), ops);
+ stacks_apply(&args->state, &ops, args->algo);
+ ops_optimizer_commit(&opt, &args->state);
+ return (res);
+}
+
+#include <stdio.h>
+int main(int argc, char **argv)
+{
+ t_args args;
+ t_benchres res;
int i;
args.state = stacks_new();
i = 1;
while (i < argc)
arg_step(argv[i++], &args);
- ops = ops_compose(ops_stackops(), ops_optimizer(ops_output(), &opt));
- stacks_apply(&args.state, &ops, args.algo);
- ops_optimizer_commit(&opt, &args.state);
+ res = pushswap_solve(&args);
output_flush();
+ printf("pre: %lu\n", res.pre_opt.counters[OP_RR]);
+ printf("post: %lu\n", res.post_opt.counters[OP_RR]);
cheatexit(!stacks_is_solved(&args.state));
}
/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/03 12:28:28 by agilliar #+# #+# */
-/* Updated: 2025/12/16 12:48:13 by agilliar ### ########.fr */
+/* Updated: 2025/12/16 19:07:40 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
output_str_ln(data);
}
-t_closure op_output(t_op op)
+static t_closure op_output(t_op op)
{
t_closure res;
const char *const ops[11] = {
res.func = &op_output_inner;
return (res);
}
+
+t_ops ops_output(void)
+{
+ return (ops_init(op_output));
+}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* op_count.c :+: :+: :+: */
+/* ops_count.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: clefrere <clefrere@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/16 12:28:05 by clefrere #+# #+# */
-/* Updated: 2025/12/16 15:40:32 by clefrere ### ########.fr */
+/* Updated: 2025/12/16 18:10:40 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
-#include "leaf_sort.h"
+#include "pushswap.h"
static void op_count_inner(size_t *data, t_stacks *stack)
{
data[0]++;
}
-t_closure op_count(size_t *dst)
+static t_closure op_count(size_t *dst)
{
t_closure res;
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ops_groups.c :+: :+: :+: */
+/* ops_stackops.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 17:02:23 by agilliar #+# #+# */
-/* Updated: 2025/12/08 17:56:36 by agilliar ### ########.fr */
+/* Updated: 2025/12/16 19:08:41 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
+t_closure op_pa(void);
+t_closure op_pb(void);
+t_closure op_ra(void);
+t_closure op_rb(void);
+t_closure op_rr(void);
+t_closure op_rra(void);
+t_closure op_rrb(void);
+t_closure op_rrr(void);
+t_closure op_sa(void);
+t_closure op_sb(void);
+t_closure op_ss(void);
+
t_ops ops_stackops(void)
{
const t_ops ops = {
return (ops);
}
-
-t_ops ops_output(void)
-{
- return (ops_init(op_output));
-}
/* By: clefrere <clefrere@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/02 11:02:44 by agilliar #+# #+# */
-/* Updated: 2025/12/16 15:40:10 by clefrere ### ########.fr */
+/* Updated: 2025/12/16 19:08:25 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
t_closure ops[11];
} t_ops;
-typedef struct s__ops_count
+typedef struct s_ops_count
{
size_t counters[11];
} t_ops_count;
t_op op_parse(t_slice s);
-t_closure op_pa(void);
-t_closure op_pb(void);
-t_closure op_ra(void);
-t_closure op_rb(void);
-t_closure op_rr(void);
-t_closure op_rra(void);
-t_closure op_rrb(void);
-t_closure op_rrr(void);
-t_closure op_sa(void);
-t_closure op_sb(void);
-t_closure op_ss(void);
-
-t_closure op_output(t_op op);
-
-t_closure op_count(size_t *dst);
-t_ops ops_count(t_ops_count *counter);
-
t_closure op_compose(t_closure first, t_closure second);
t_ops ops_compose(t_ops lhs, t_ops rhs);
t_ops ops_init(t_closure (*gen)(t_op));
t_ops ops_stackops(void);
t_ops ops_output(void);
+t_ops ops_count(t_ops_count *counter);
+
t_ops ops_optimizer(t_ops commit, t_optimizer *data);
void ops_optimizer_commit(t_optimizer *data, t_stacks *stacks);