urbit/j/f/comb.c

73 lines
1.8 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/comb.c
**
** This file is in the public domain.
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-09-29 00:21:18 +04:00
/* functions
*/
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3qf_comb(
2014-09-06 00:13:24 +04:00
u3_noun mal,
u3_noun buz)
2013-09-29 00:21:18 +04:00
{
2014-11-06 02:36:30 +03:00
if ( (u3_none == mal) || (u3_none == buz) ) {
return u3_none;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun p_mal, q_mal, p_buz, q_buz, pp_buz, pq_buz;
2013-09-29 00:21:18 +04:00
2014-11-06 03:20:01 +03:00
if ( (c3y == u3r_p(mal, 0, &p_mal)) && (0 != p_mal) ) {
if ( (c3y == u3r_p(buz, 0, &p_buz)) && (0 != p_buz) ) {
2014-09-06 00:13:24 +04:00
return u3nc(
2014-08-21 01:18:34 +04:00
0,
2014-11-06 22:13:57 +03:00
u3qc_peg(p_mal, p_buz));
2013-09-29 00:21:18 +04:00
}
2014-11-06 03:20:01 +03:00
else if ( c3y == u3r_pq(buz, 2, &p_buz, &q_buz) &&
c3y == u3r_p(p_buz, 0, &pp_buz) &&
c3y == u3r_p(q_buz, 0, &pq_buz) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3nt
2014-08-21 01:18:34 +04:00
(2,
2014-09-06 00:13:24 +04:00
u3nc(0,
2014-11-06 22:13:57 +03:00
u3qc_peg(p_mal, pp_buz)),
2014-09-06 00:13:24 +04:00
u3nc(0,
2014-11-06 22:13:57 +03:00
u3qc_peg(p_mal, pq_buz)));
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
else return u3nt(7, u3k(mal),
u3k(buz));
2013-09-29 00:21:18 +04:00
}
#if 1
2014-11-06 03:20:01 +03:00
else if ( (c3y == u3r_bush(mal, &p_mal, &q_mal)) &&
2014-11-05 04:18:47 +03:00
(c3y == u3du(p_mal)) &&
(c3y == u3du(q_mal)) &&
2014-09-06 00:13:24 +04:00
(0 == u3h(q_mal)) &&
(1 == u3t(q_mal)) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3nt(8, u3k(p_mal),
u3k(buz));
2013-09-29 00:21:18 +04:00
}
#endif
2014-11-06 03:20:01 +03:00
else if ( (c3y == u3r_p(buz, 0, &p_buz)) &&
(c3y == u3r_sing(1, p_buz)) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3k(mal);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
else return u3nt(7, u3k(mal),
u3k(buz));
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
2014-11-06 22:13:57 +03:00
u3wf_comb(
2014-09-06 00:13:24 +04:00
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun mal, buz;
2013-09-29 00:21:18 +04:00
2014-11-18 00:56:51 +03:00
if ( c3n == u3r_mean(cor, u3x_sam_2, &mal, u3x_sam_3, &buz, 0) ) {
2014-11-06 02:36:30 +03:00
return u3_none;
2013-09-29 00:21:18 +04:00
} else {
2014-11-06 22:13:57 +03:00
return u3qf_comb(mal, buz);
2013-09-29 00:21:18 +04:00
}
}