nx_climbout_gate.nx source
↩ module page · 82 lines · 4420 B
1// nx_climbout_gate.nx -- R5 GATE: proves the climb-out plan engine fuses the arc into ONE prioritized plan
2// and shows an overwhelmed person the one right next step. Actions (each from an engine built this arc):
3// stabilize: pay overdue HOA ($35 late fee avoided) tier 0
4// recover: dispute medical overbilling ($2,650) tier 1
5// cut-cost: shop cheaper auto insurance ($600) tier 2 (listed first, smaller)
6// cut-cost: refinance to 9% CDFI ($10,136.96) tier 2 (listed second, bigger)
7// attack: avalanche the 24% card ($727.25) tier 3
8// build: build a $1,000 buffer ($0 direct) tier 4
9// Order-of-operations (tier asc) + impact-desc within a tier => [stabilize, recover, refinance, insurance,
10// avalanche, buffer]; total climb-out = $14,149.21; ADHD sees ONLY the first step. Exits 0 iff ALL pass.
11// license_tier: ORIGINAL
12import "nx_syscalls.nx"
13import "nx_money.nx"
14import "nx_accommodate.nx"
15import "nx_climbout.nx"
16
17func g_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
18func g_putn(v: i64) -> i64 {
19 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
20 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
21 let d: *u8 = sys_mmap(24); var k: i64 = 0
22 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
23 var j: i64 = k - 1
24 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
25 return 0
26}
27func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 {
28 if got == want { st[0] = st[0] + 1; g_puts(" PASS "); g_puts(name); g_puts("\n") }
29 else { st[1] = st[1] + 1; g_puts(" FAIL "); g_puts(name); g_puts(" got="); g_putn(got); g_puts(" want="); g_putn(want); g_puts("\n") }
30 return 0
31}
32func seti(a: *i64, i: i64, v: i64) -> i64 { a[i] = v; return 0 }
33
34func main() -> i64 {
35 let st: *i64 = sys_mmap(16) as *i64
36 st[0] = 0; st[1] = 0
37
38 let tier: *i64 = sys_mmap(8 * 8) as *i64
39 let impact: *i64 = sys_mmap(8 * 8) as *i64
40 seti(tier,0,CO_STABILIZE); seti(impact,0,3500) // pay overdue HOA
41 seti(tier,1,CO_RECOVER); seti(impact,1,265000) // dispute overbilling
42 seti(tier,2,CO_CUTCOST); seti(impact,2,60000) // cheaper insurance (smaller, listed first)
43 seti(tier,3,CO_CUTCOST); seti(impact,3,1013696) // refinance (bigger, listed second)
44 seti(tier,4,CO_ATTACKDEBT); seti(impact,4,72725) // avalanche
45 seti(tier,5,CO_BUILD); seti(impact,5,0) // build buffer
46 let n: i64 = 6
47
48 let order: *i64 = sys_mmap(8 * 8) as *i64
49 co_plan(tier, impact, n, order)
50 g_puts(" [info] plan order: ");
51 var p: i64 = 0
52 while p < n { g_putn(order[p]); g_puts(" "); p = p + 1 }
53 g_puts("\n")
54
55 chk("step 1 = stabilize (pay overdue HOA, action 0)", order[0], 0, st)
56 chk("step 2 = recover (dispute overbilling, action 1)", order[1], 1, st)
57 chk("step 3 = refinance FIRST in cut-cost tier (bigger impact, action 3)", order[2], 3, st)
58 chk("step 4 = insurance second in cut-cost tier (action 2)", order[3], 2, st)
59 chk("step 5 = attack debt (avalanche, action 4)", order[4], 4, st)
60 chk("step 6 = build buffer last (action 5)", order[5], 5, st)
61
62 let tot: i64 = co_total_impact(impact, n)
63 g_puts(" [info] total climb-out impact = "); g_putn(tot); g_puts("c\n")
64 chk("total climb-out impact = 1414921c ($14,149.21)", tot, 1414921, st)
65
66 // the single NEXT action (priority-ordered)
67 let done: *i64 = sys_mmap(8 * 8) as *i64
68 seti(done,0,0); seti(done,1,0); seti(done,2,0); seti(done,3,0); seti(done,4,0); seti(done,5,0)
69 chk("next action = pay overdue HOA (action 0)", co_next_action(order, done, n), 0, st)
70 seti(done,0,1)
71 chk("after step 1 done -> next = dispute overbilling (action 1)", co_next_action(order, done, n), 1, st)
72
73 // accommodation: an ADHD person sees ONE step (the right first one), not the wall of 6
74 chk("ADHD sees ONE step (load budget = 1)", ac_load_budget(AC_ADHD, 2, n), 1, st)
75 seti(done,0,0)
76 chk("...and it is the right one: pay overdue HOA (action 0)", co_next_action(order, done, n), 0, st)
77
78 g_puts("nx_climbout_gate: PASS="); g_putn(st[0]); g_puts(" FAIL="); g_putn(st[1]); g_puts("\n")
79 if st[1] == 0 { g_puts("SITUATION R5 nx_climbout: GREEN\n"); return 0 }
80 g_puts("SITUATION R5 nx_climbout: RED\n")
81 return 1
82}