code wiki / (root) / nx_climbout.nx

nx_climbout.nx source

↩ module page · 66 lines · 3036 B

1// nx_climbout.nx -- R5 of THE NISHI SITUATION-MANAGEMENT arc: the CLIMB-OUT PLAN engine -- the capstone that 2// fuses the whole system into ONE prioritized, dollar-impact path from crisis to peace, then shows an 3// overwhelmed person just the next step. Each candidate ACTION comes from an engine already built this arc: 4// stabilize overdue bills (nx_bills) · recover overcharges (nx_fin_audit dispute) · cut the rate 5// (nx_fin_finance) · attack highest-APR debt (nx_debt avalanche) · build a buffer. 6// Ordered by the FINANCIAL ORDER OF OPERATIONS (a real framework): tier ascending = stabilize < recover-what- 7// is-owed-to-you < cut-ongoing-cost < attack-debt < build-buffer; within a tier, biggest dollar impact first. 8// Then `ac_load_budget` (nx_accommodate) decides HOW MANY steps to surface -- so an ADHD/low-energy person 9// sees ONE next step worth $X, not the whole wall. Exact no-float (nx_money). Advisory, no auto-action. 10// license_tier: ORIGINAL 11import "nx_syscalls.nx" 12import "nx_money.nx" 13import "nx_accommodate.nx" 14 15// order-of-operations tiers (DATA convention). 16const CO_STABILIZE: i64 = 0 // overdue bills / keep the lights on -- do first regardless of $ 17const CO_RECOVER: i64 = 1 // money owed to YOU -- overbilling disputes 18const CO_CUTCOST: i64 = 2 // cut ongoing cost -- refinance, cheaper insurance 19const CO_ATTACKDEBT:i64 = 3 // attack the highest-APR debt 20const CO_BUILD: i64 = 4 // build the emergency buffer 21 22// order n actions by (tier ascending, then dollar impact DESCENDING within a tier). writes the sorted 23// action indices into out_order[]; returns n. 24func co_plan(tiers: *i64, impacts: *i64, n: i64, out_order: *i64) -> i64 { 25 var i: i64 = 0 26 while i < n { out_order[i] = i; i = i + 1 } 27 i = 1 28 while i < n { 29 let cur: i64 = out_order[i] 30 var j: i64 = i - 1 31 var go: i64 = 1 32 while go == 1 { 33 if j < 0 { go = 0 } 34 else { 35 let a: i64 = out_order[j] 36 var after: i64 = 0 37 if tiers[a] > tiers[cur] { after = 1 } 38 else { if tiers[a] == tiers[cur] { if impacts[a] < impacts[cur] { after = 1 } } } 39 if after == 1 { out_order[j + 1] = a; j = j - 1 } else { go = 0 } 40 } 41 } 42 out_order[j + 1] = cur 43 i = i + 1 44 } 45 return n 46} 47 48// total dollar impact of the plan = the size of the climb-out (recovered + saved). 49func co_total_impact(impacts: *i64, n: i64) -> i64 { 50 var s: i64 = 0 51 var i: i64 = 0 52 while i < n { s = mny_add(s, impacts[i]); i = i + 1 } 53 return s 54} 55 56// the single NEXT action to do = the first not-done action in plan order. returns the ACTION index, or -1. 57// done[] is indexed by action index. This is what an ADHD/low-energy person sees (ac_load_budget = 1). 58func co_next_action(out_order: *i64, done: *i64, n: i64) -> i64 { 59 var i: i64 = 0 60 while i < n { 61 let a: i64 = out_order[i] 62 if done[a] == 0 { return a } 63 i = i + 1 64 } 65 return 0 - 1 66}