.build
+*.swp
push_swap
checker
NAME=push_swap
-SRCS=algorithm_quicksort.c algorithm_selection_sort.c cheatalloc.c clist.c list.c main_pushswap.c op_output.c op_p.c op_r.c op_rr.c op_s.c ops.c ops_groups.c ops_optimizer.c output.c psval.c slice.c stack.c stacks.c
+SRCS=algorithm_quicksort.c algorithm_selection_sort.c cheatalloc.c clist.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_groups.c ops_optimizer.c output.c psval.c slice.c stack.c stacks.c
RESSRCS=_res_leaf_sort_lookup.h
remakefile : clean
sed -i "s/^SRCS=.*/$$(echo -n SRCS=; echo -n *.c)/" Makefile
- sed -i "s/^BINSRCS=.*/$$(echo -n ASSETSRCS=; echo -n _res_*.h)/" Makefile
+ sed -i "s/^RESSRCS=.*/$$(echo -n RESSRCS=; echo -n _res_*.h)/" Makefile
.PHONY : all clean fclean re bonus remakefile
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* leaf_sort.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2025/12/10 18:01:04 by agilliar #+# #+# */
+/* Updated: 2025/12/10 18:35:51 by agilliar ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LEAF_SORT_H
+# define LEAF_SORT_H
+
+# include "pushswap.h"
+
+# define LEAF_OPS_MAX 12
+
+typedef struct s_leaf_solution
+{
+ size_t used;
+ t_op store[LEAF_OPS_MAX];
+} t_leaf_solution;
+
+typedef struct s_leaf_lookup
+{
+ t_leaf_solution zero[1];
+ t_leaf_solution one[1];
+ t_leaf_solution two[2];
+ t_leaf_solution three[6];
+ t_leaf_solution four[24];
+} t_leaf_lookup;
+
+typedef struct s_leaf_lookups
+{
+ t_leaf_lookup local;
+ t_leaf_lookup other;
+} t_leaf_lookups;
+
+extern void _binary__build_leaf_sort_lookup_res_start(void);
+extern void _binary__build_leaf_sort_lookup_res_end(void);
+
+t_leaf_lookups *leaf_lookups(void);
+
+#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* leaf_sort_parse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2025/12/10 17:59:06 by agilliar #+# #+# */
+/* Updated: 2025/12/10 19:15:53 by agilliar ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "leaf_sort.h"
+
+static t_leaf_solution leaf_solution_parse(t_slice *iter)
+{
+ t_leaf_solution res;
+ t_slice rem;
+ t_slice curr;
+ t_op op;
+
+ rem = slice_split(iter, '\n');
+ res.used = 0;
+ while (rem.len)
+ {
+ curr = slice_split(&rem, ' ');
+ op = op_parse(curr);
+ if (op == OP_INVALID || res.used >= LEAF_OPS_MAX)
+ cheatexit(1);
+ res.store[res.used++] = op;
+ }
+ return (res);
+}
+
+static t_leaf_lookup leaf_lookup_parse(t_slice *iter)
+{
+ int i;
+ t_leaf_lookup res;
+
+ i = 0;
+ while (i < 1)
+ res.zero[i++] = leaf_solution_parse(iter);
+ i = 0;
+ while (i < 1)
+ res.one[i++] = leaf_solution_parse(iter);
+ i = 0;
+ while (i < 2)
+ res.two[i++] = leaf_solution_parse(iter);
+ i = 0;
+ while (i < 6)
+ res.three[i++] = leaf_solution_parse(iter);
+ i = 0;
+ while (i < 24)
+ res.four[i++] = leaf_solution_parse(iter);
+ return (res);
+}
+
+static t_leaf_lookups leaf_lookups_parse(t_slice iter)
+{
+ t_leaf_lookups res;
+
+ res.local = leaf_lookup_parse(&iter);
+ res.other = leaf_lookup_parse(&iter);
+ if (iter.len)
+ cheatexit(1);
+ return (res);
+}
+
+t_leaf_lookups *leaf_lookups(void)
+{
+ static t_leaf_lookups *store = NULL;
+ t_slice raw;
+
+ if (store)
+ return (store);
+ store = cheatalloc(sizeof(t_leaf_lookups));
+ raw = slice_new_range(
+ (void *)&_binary__build_leaf_sort_lookup_res_start,
+ (void *)&_binary__build_leaf_sort_lookup_res_end
+ );
+ *store = leaf_lookups_parse(raw);
+ return (store);
+}
/* By: clefrere <clefrere@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/02 22:15:12 by agilliar #+# #+# */
-/* Updated: 2025/12/10 17:56:45 by agilliar ### ########.fr */
+/* Updated: 2025/12/10 19:17:52 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
stack_push_back(&arg->state.a, psval_parse(str));
}
+#include "leaf_sort.h"
+#include <stdio.h>
+
int main(int argc, char **argv)
{
t_args args;
t_ops ops;
t_optimizer opt;
- slice_output(slice_new_range(
- &_binary__build_leaf_sort_lookup_res_start,
- &_binary__build_leaf_sort_lookup_res_end
- ));
args.state = stacks_new();
args.bench = false;
args.algo = NULL;
+ t_leaf_lookups *test = leaf_lookups();
+ printf("%i", test->other.four[0].store[2]);
for (int i = 1; i < argc; i++)
arg_step(argv[i], &args);
ops = ops_compose(ops_stackops(), ops_optimizer(ops_output(), &opt));
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* op_parse.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2025/12/10 18:11:35 by agilliar #+# #+# */
+/* Updated: 2025/12/10 18:19:50 by agilliar ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "pushswap.h"
+
+t_op op_parse(t_slice s)
+{
+ if (slice_eq(s, slice_new("sa")))
+ return (OP_SA);
+ if (slice_eq(s, slice_new("sb")))
+ return (OP_SB);
+ if (slice_eq(s, slice_new("ss")))
+ return (OP_SS);
+ if (slice_eq(s, slice_new("pa")))
+ return (OP_PA);
+ if (slice_eq(s, slice_new("pb")))
+ return (OP_PB);
+ if (slice_eq(s, slice_new("ra")))
+ return (OP_RA);
+ if (slice_eq(s, slice_new("rb")))
+ return (OP_RB);
+ if (slice_eq(s, slice_new("rr")))
+ return (OP_RR);
+ if (slice_eq(s, slice_new("rra")))
+ return (OP_RRA);
+ if (slice_eq(s, slice_new("rrb")))
+ return (OP_RRB);
+ if (slice_eq(s, slice_new("rrr")))
+ return (OP_RRR);
+ return (OP_INVALID);
+}
/* By: clefrere <clefrere@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/02 11:02:44 by agilliar #+# #+# */
-/* Updated: 2025/12/10 17:44:35 by agilliar ### ########.fr */
+/* Updated: 2025/12/10 18:19:34 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
typedef enum e_op
{
- OP_SENTINEL = -1,
+ OP_INVALID = -1,
OP_SA = 0,
OP_SB = 1,
OP_SS = 2,
const char *ptr;
} t_slice;
-extern void _binary__build_leaf_sort_lookup_res_start(void);
-extern void _binary__build_leaf_sort_lookup_res_end(void);
-
void cheatexit(int errcode);
void *cheatalloc(size_t len);
t_psval psval_parse(const char *s);
void psval_output(t_psval val);
+t_op op_parse(t_slice s);
+
t_closure op_pa(void);
t_closure op_pb(void);
t_closure op_ra(void);
t_slice slice_new(const char *s);
t_slice slice_new_range(void *start, void *end);
bool slice_eq(t_slice lhs, t_slice rhs);
-t_slice slice_split_first(t_slice *rem, char at);
+t_slice slice_split(t_slice *rem, char at);
void slice_output(t_slice s);
void algorithm_selection_sort(const t_stacks *stacks, t_closure cb);
/* By: agilliar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/10 17:08:21 by agilliar #+# #+# */
-/* Updated: 2025/12/10 17:56:18 by agilliar ### ########.fr */
+/* Updated: 2025/12/10 18:41:15 by agilliar ### ########.fr */
/* */
/* ************************************************************************** */
return (i == lhs.len);
}
-t_slice slice_split_first(t_slice *rem, char at)
+t_slice slice_split(t_slice *rem, char at)
{
t_slice res;
res.ptr = rem->ptr;
while (rem->len)
{
- if (*rem->ptr == at)
+ if (*(rem->ptr) == at)
break ;
rem->len--;
rem->ptr++;