Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- Day of the week calculator.
- Takes in dates from the 2000s in DDMMYY format and outputs 0-6, where 0 is Sunday and 6 is Saturday.
- Junk = JX
- ]
- [
- Receives input while subtracting 1 from the month so it indexes properly into the month code array.
- Tape:
- 00 00 00 00 DD 00 MM 00 YY 00
- ^
- ]
- >>>,[>>++++++[<++++++++>-]<[-<->],]<<[->++++++++++<]<<[->++++++++++<]>-<<<[->++++++++++<]
- #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[
- Computes leap year flag. (LY)
- LY is 1 if YY is a leap year, and 0 if not.
- Tape:
- 00 00 00 00 DD 00 MM 00 LY 00 YY
- ^
- ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- >>>>>>>++++<<[>+>->+<[>]>[<+>-]<<[<]>-]>>[-]>[<<<<+>>>>[-]]<<[<<[->+<]+>[-<->]<[>+<-]>>[->+<]]
- #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[
- Computes month code (MC), then intermediate value (IM).
- The overall result should be (MC + DD + YC (year code)) % 7, so we can combine computing the month code
- and adding it to the date in one step.
- The first line copies YY to a safe place.
- The second line writes an array of month codes (the first two affected by the leap year).
- The third line indexes into it, but adds the result at DD:
- Tape:
- 00 00 00 00 IM YY 00 00 00 00 JX JX JX JX JX JX JX JX JX JX ...
- ^
- The third line took 3 days of debugging because it's really really weird and the pointer flies everywhere
- depending on if it's January or not and it's just a giant mess but it works so please respect this line
- and don't mess with it. thanks.
- ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- >[-<<<<<+>>>>>]
- +++++++>>+++<<<<<[->>>->>-<<<<<]>>>>>>>+++>>++++++>>+>>++++>>++++++>>++>>+++++>>+++++++>>+++>>+++++
- [[<]<]<<[->>>>>[>]+[<]<<<]>>>>>[>]<<[-]>>>>+<<<[-<<[<]>[<]<<<<<+>>>>>>[>]>>[<<]<]<<[[-]<]<<<[>]<<-
- #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[
- Computes year code (YC).
- YC = (14 - ((YY - (YY % 4)) / 2) % 7) + (YY % 4)
- ^ don't even ask how I got that
- On the first line we set n = YY and d = 4.
- On the second we apply the (black magic) divmod algorithm which takes that section of the tape from
- n 00 d 00 00 00 00
- ^
- to:
- 00 n d-n%d n%d n/d 00 00
- ^
- On the third line, we compute n-n%d and clear out the unused cells, while placing a 2 in the right spot,
- and saving n%d for later.
- On the fourth line we divide by 2 with a variant of the divmod algorithm that takes the tape from:
- n%d n-n%d 02 00 00 00 00
- ^
- to (y = n-n%d):
- n%d 00 2-y%2 y%2 y/2 00 00
- ^
- On the fifth line, we modulo y/2 by 7, taking the tape from:
- n%d 00 2-y%2 y%2 y/2 00 00
- ^
- to (b = y/2):
- n%d 00 00 7-b%7 b%7 00 00
- ^
- On the sixth line, we subtract b%7 from 14 and add that to n%d.
- Tape:
- 00 00 00 00 IM YC 00 00 JX 00 00 00 JX JX JX JX JX ...
- ^
- ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- >>>++++<<
- [->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]
- >>>[-<<<+>->>]>[-]<<[-]++<
- [->-[>+>>]>[+[-<+>]>+>>]<<<<<]
- >[-]>[-]+++++++>[-<<+>>]<<[>->+<[>]>[<+>-]<<[<]>-]
- ++[-<+++++++>]>>[-<<<->>>]<<<[-<+>]
- #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[
- Finally finishes everything. Just adds IM and YC and takes the mod 7 and prints it.
- I am so exhausted
- First line does the addition and some easy setup for the mod algorithm.
- Second line is the mod algorithm.
- ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- >>[-]<<<[-<+>]+++++++<
- [>->+<[>]>[<+>-]<<[<]>-]
- >[-]<++++++[->++++++++<]>[->+<]>.
- WEW
- I AM
- NEVER
- DOING THAT
- AGAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement