Advertisement
Guest User

BF day of the week

a guest
Jun 14th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [
  2.  Day of the week calculator.
  3.  Takes in dates from the 2000s in DDMMYY format and outputs 0-6, where 0 is Sunday and 6 is Saturday.
  4.  
  5.  Junk = JX
  6. ]
  7.  
  8. [
  9.  Receives input while subtracting 1 from the month so it indexes properly into the month code array.
  10.  Tape:
  11.    00 00 00 00 DD 00 MM 00 YY 00
  12.             ^
  13. ]
  14.  
  15. >>>,[>>++++++[<++++++++>-]<[-<->],]<<[->++++++++++<]<<[->++++++++++<]>-<<<[->++++++++++<]
  16.  
  17. #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[
  18.  Computes leap year flag. (LY)
  19.  LY is 1 if YY is a leap year, and 0 if not.
  20.  Tape:
  21.    00 00 00 00 DD 00 MM 00 LY 00 YY
  22.                               ^
  23. ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  24.  
  25. >>>>>>>++++<<[>+>->+<[>]>[<+>-]<<[<]>-]>>[-]>[<<<<+>>>>[-]]<<[<<[->+<]+>[-<->]<[>+<-]>>[->+<]]
  26.  
  27. #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[
  28.  Computes month code (MC), then intermediate value (IM).
  29.  
  30.  The overall result should be (MC + DD + YC (year code)) % 7, so we can combine computing the month code
  31.  and adding it to the date in one step.
  32.  
  33.  The first line copies YY to a safe place.
  34.  
  35.  The second line writes an array of month codes (the first two affected by the leap year).
  36.  
  37.  The third line indexes into it, but adds the result at DD:
  38.  Tape:
  39.    00 00 00 00 IM YY 00 00 00 00 JX JX JX JX JX JX JX JX JX JX ...
  40.                ^
  41.  
  42.  The third line took 3 days of debugging because it's really really weird and the pointer flies everywhere
  43.  depending on if it's January or not and it's just a giant mess but it works so please respect this line
  44.  and don't mess with it. thanks.
  45. ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  46.  
  47. >[-<<<<<+>>>>>]
  48. +++++++>>+++<<<<<[->>>->>-<<<<<]>>>>>>>+++>>++++++>>+>>++++>>++++++>>++>>+++++>>+++++++>>+++>>+++++
  49. [[<]<]<<[->>>>>[>]+[<]<<<]>>>>>[>]<<[-]>>>>+<<<[-<<[<]>[<]<<<<<+>>>>>>[>]>>[<<]<]<<[[-]<]<<<[>]<<-
  50.  
  51. #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[
  52.  Computes year code (YC).
  53.  YC = (14 - ((YY - (YY % 4)) / 2) % 7) + (YY % 4)
  54.  ^ don't even ask how I got that
  55.  
  56.  On the first line we set n = YY and d = 4.
  57.  On the second we apply the (black magic) divmod algorithm which takes that section of the tape from
  58.  
  59.  n 00 d 00 00 00 00
  60.  ^
  61.  
  62.  to:
  63.  
  64.  00 n d-n%d n%d n/d 00 00
  65.  ^
  66.  
  67.  On the third line, we compute n-n%d and clear out the unused cells, while placing a 2 in the right spot,
  68.  and saving n%d for later.
  69.  
  70.  On the fourth line we divide by 2 with a variant of the divmod algorithm that takes the tape from:
  71.  
  72.  n%d n-n%d 02 00 00 00 00
  73.      ^
  74.  
  75.  to (y = n-n%d):
  76.  
  77.  n%d 00 2-y%2 y%2 y/2 00 00
  78.      ^
  79.  
  80.  On the fifth line, we modulo y/2 by 7, taking the tape from:
  81.  
  82.  n%d 00 2-y%2 y%2 y/2 00 00
  83.      ^
  84.  
  85.  to (b = y/2):
  86.  
  87.  n%d 00 00 7-b%7 b%7 00 00
  88.         ^
  89.  
  90.  On the sixth line, we subtract b%7 from 14 and add that to n%d.
  91.  
  92.  Tape:
  93.    00 00 00 00 IM YC 00 00 JX 00 00 00 JX JX JX JX JX ...
  94.                      ^
  95. ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  96.  
  97. >>>++++<<
  98. [->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]
  99. >>>[-<<<+>->>]>[-]<<[-]++<
  100. [->-[>+>>]>[+[-<+>]>+>>]<<<<<]
  101. >[-]>[-]+++++++>[-<<+>>]<<[>->+<[>]>[<+>-]<<[<]>-]
  102. ++[-<+++++++>]>>[-<<<->>>]<<<[-<+>]
  103.  
  104. #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[
  105.  Finally finishes everything. Just adds IM and YC and takes the mod 7 and prints it.
  106.  I am so exhausted
  107.  
  108.  First line does the addition and some easy setup for the mod algorithm.
  109.  Second line is the mod algorithm.
  110. ]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  111.  
  112. >>[-]<<<[-<+>]+++++++<
  113. [>->+<[>]>[<+>-]<<[<]>-]
  114. >[-]<++++++[->++++++++<]>[->+<]>.
  115.  
  116. WEW
  117. I AM
  118. NEVER
  119. DOING THAT
  120. AGAIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement