diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-12-02 07:20:02 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-12-02 07:20:02 -0500 |
commit | 01407692c113b24083342fe08dd31d5767a1c925 (patch) | |
tree | 51f21f1233fc9157a5292b74b4a5c31cc699c5a0 | |
parent | e20eb4c7a83d354d8f3ad44207d1ef0e9f597004 (diff) |
day2: cleaner approach
-rw-r--r-- | day2/both-clean.forth | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/day2/both-clean.forth b/day2/both-clean.forth new file mode 100644 index 0000000..38f27b7 --- /dev/null +++ b/day2/both-clean.forth @@ -0,0 +1,35 @@ +1 constant rock +2 constant paper +3 constant scissors + +: is-win ( them us -- yes ) - dup <0 swap 2 = or ; + +: get-score ( them us -- score ) + 2dup is-win if 6 + else + 2dup = if 3 + + then then nip ; + +: get-loser ( them -- us ) 2 - 3 mod 1+ ; +: get-winner ( them -- us ) 3 mod 1+ ; + +: A rock ; +: B paper ; +: C scissors ; +: X rock get-score + ; +: Y paper get-score + ; +: Z scissors get-score + ; + +0 +include input +. cr + +: X dup get-loser get-score + ; +: Y dup get-score + ; +: Z dup get-winner get-score + ; + +0 +include input +. cr + +bye + |