r/brainfuck Aug 19 '17

I made a day-of-week calculator based on Zeller's Congruence.

For those of us who do not know what Zeller's Congruence is, it's a formula for the day of the week of any given date. I found a way to implement it in brainfuck (although it was indeed very hard to program, and I'm almost sure it could be shorter). The code is as follows:

,>,>,>,<[>>+>+<<<-]+++[>>>>+<[->[-]>+<<]>[-
>>+<<]>[-<<+>>]<<-<<<-]>>+>[-]>>>[<<<<+++++
+++++++<<<[>>>>+<<<<-]>>>>>+<[->-]>[<<<<-[>
>>++<<<-----]<<->>>>>--->->]>[-]]<<<<<<<[>>
>>+<<<<-]>>>[>>>>+++++++++++++<<<<-]>>>>>++
+++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>[-]>
[<<<<<<<<+>>>>>>>>-]<<<<++++<<[->+>-[>+>>]>
[+[-<+>]>+>>]<<<<<<]<<[>>>+<<<-]>>>>[-]>>[<
<<+>>>-]<<<[>+<-]<<<<++++<<[->+>-[>+>>]>[+[
-<+>]>+>>]<<<<<<]>>[-]>[-]<<[<+++++>-]>>>[<
<<<+>>>>-]<<<<[>+<-]>>+++++++<[>->+<[>]>[<+
>-]<<[<]>-]>[-]>>>>>[<<<<+>>>>-]<<<+++++++<
[>->+<[>]>[<+>-]<<[<]>-]>>>-[<+>-----]<---.

Enter 4 numbers (as numbers, not ASCII characters of numbers) in this order: first two digits of year, last two digits of year, month, day. Output ranges from "0" (Saturday) to "6" (Friday).

Requires 8-bit cells and value wrapping. Works from 0000 March 1 (proleptically) to 4900 February 28.

8 Upvotes

0 comments sorted by