-2

I need to alternate between 2 tasks every day, and I need a simple algorithm to know which task I need to do.

I need to be able to run this algorithm by head, using simple general knowledge (like day of week, day of month, etc), and it must not rely of which task has been done the previous day (because I have a crappy memory).

I have tried checking for parity in a combination of day of week / day of month / # of month, etc, but couldn't find a suitable system: day of week have 2 consecutive odd numbers, same goes for day of month every so often.

Thierry J.
  • 2,148
  • 16
  • 23
  • I didn't get this - _day of week have 2 consecutive odd numbers_ – nice_dev May 30 '22 at 07:10
  • _it must not rely of which task has been done the previous day (because I have a crappy memory)._ Can you genuinely give some simple examples? – nice_dev May 30 '22 at 07:18
  • _I need to be able to run this algorithm by head_ In that case, you can randomly apply any non-sensical logic. You don't need to think like a computer scientist. – nice_dev May 30 '22 at 07:20
  • 1
    @nice_dev: yep, that sounds odd. –  May 30 '22 at 07:32
  • 1
    Many calendars number the weeks since the beginning of the year. If you have access to such a calendar, you can just take the parity of `week number + day of week`. – Stef May 30 '22 at 07:48
  • @Stef Problem at the end of the year, sometime it will switch parity, sometimes not... – Jean-Baptiste Yunès May 30 '22 at 11:43
  • 1
    @nice_dev If I start my week at day #1, then I end it at day #7, and restart to #1, so I have 7 followed by 1, and that makes two consecutive odd numbers, so task 2 done twice in a row – Thierry J. May 31 '22 at 06:22

4 Answers4

2

I am afraid that this is impossible: if you can't remember what you did the day before, any other procedure will require more mnemonic effort.

  • remember what you did on January first (or another date),

  • remember the parities of the cumulated months: oeoeoeooeoe or ooeoeoeeoeo for a leap year,

  • add the cumulated parity of the month before* to the parity of the day,

  • add that to the parity of the first task.

E.g. if A on January 1st 2022, then on March 17, 2022: e + o = o gives B.


*In January, use even.

You can also state the month parity rule as: until August inclusive, use the co-parity of the month number; then use the parity. But for a leap year, change that parity after February (excluded).

  • Rather than remember the parity of the number of days per month, you can count them on your knucklebones: https://en.wikipedia.org/wiki/Knuckle_mnemonic#/media/File:Month_-_Knuckles_(en).svg ; lows are even and highs are odd. (This doesn't account for leap years) – Stef May 30 '22 at 07:53
  • @Stef: quite right, I missed that. –  May 30 '22 at 08:13
  • Why use the parity of the month _before_ ? What's wrong with using the parity of the current month? – Thierry J. May 31 '22 at 06:28
  • @ThierryJ.: come on, it's the cumulated parities, i.e. the parity of the number of days in the fully elapsed months. –  May 31 '22 at 06:36
  • That seem overly complicated, and would achieve the same result with simply using `parity of the month # + parity of the day` from January to August, and `co-parity of the month # + parity of the day` from August to December. In any case, I'm not a fan of having to switch the algo in the middle of the year :/ – Thierry J. Jun 03 '22 at 06:57
0

Just count the number of days in between your date and a given "zero" one...then use parity.

Take number of seconds (or milli, or whatever) since EPOCH (common zero for date and time), divide (integer division) by 60x60x24 (or 1000x60x60x24, or what is appropriate), you then get the number of days since EPOCH.

----EDIT----

Example: Got 1653910695 seconds since EPOCH (at the time of my experience). Dividing it by 60x60x24 give 19142 days. To morrow it will give 19143, etc.

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
0
<?php
     $day = Date('j');
     $previous_day = date('j', strtotime("-1 days"));
     if($day%2==0 OR $previous_day%2!=0)
          echo "Task 1";
     }else{
          echo "Task 2";
     }
   ?>
0

I need to be able to run this algorithm by head

So, you don't need to take help of Computer science. You can use cognitive human ability to map a thing to another thing.

Note: This need not make sense to everybody though, if you are thinking out of the box.

  • Map task 1 as God's day.
  • Map task 2 as Devil's day in your brain.
  • This should be simple just like day and night.
  • Now, remember that devil's evil karma is always burnt by God the next day and that devil never learns his lesson. So this way, alternating would be easy.

Friends Episode snippet on Youtube

nice_dev
  • 17,053
  • 2
  • 21
  • 35
  • That would sound good, if I didn't have such bad memory and could actually remember what happened the previous day consistently.. – Thierry J. May 31 '22 at 06:21
  • @ThierryJ. You just have to memorize those 2 things and then it comes a habit as time passes by(max 4-7 days). Eventually, it becomes a [`muscle memory`](https://en.wikipedia.org/wiki/Muscle_memory_(strength_training)) and you will do it correctly even if you aren't paying enough conscious attention. – nice_dev May 31 '22 at 07:04