-3

Is there a way to find out if a given number is a total of both Hijri[1] and Gregorian[2] of the same year?

Example: 3452 = 2015 + 1437

[1] Hijri - Islamic Calendar. https://en.wikipedia.org/wiki/Islamic_calendar

[2] Gregorian Calendar. https://en.wikipedia.org/wiki/Gregorian_calendar

Paolo Maresca
  • 7,396
  • 4
  • 34
  • 30
KaliE
  • 1
  • Given that the [Hijri year](https://en.m.wikipedia.org/wiki/Hijri_year) is 354 days long ("*The year 2015 ce corresponds to the Islamic years ah 1436 – 1437.*") one Gregorian year will correspond to *at least* two Hijri years. How would you deal with that? Would 2015+1436 and 2015+1436 **both** be acceptable? – Wai Ha Lee Oct 16 '15 at 23:06
  • ... In fact, since they *don't/can't* change on the same day, I think that any number greater than 622 (622 ce = ah 1) will be representable as the sum of the years **for at least one day**. – Wai Ha Lee Oct 16 '15 at 23:09
  • 1
    I'm voting to close this question as off-topic because it has no practical purpose nor was any existing code provided. As asked, it is a code puzzle and would fit better on [codegolf.SE](http://codegolf.stackexchange.com/) – Matt Johnson-Pint Oct 16 '15 at 23:39
  • Wai, as you asked in 2015 later portion of 1436 exists, while in Oct 15 a new 1437 starts, and overlap with the rest of 2015, so yes both answer should be correct. – KaliE Oct 17 '15 at 01:57

1 Answers1

0

This perhaps is a bit of a brute force approach, that will require you to pre-populate two lists with dates (but it's not that bad, only around 2000 elements each):

 // Fill this up with all Hijri dates witin your range
 List<int> hijriDates = new List<int>() { 1,2, 1437 };

 // Fill this up with all gregorian dates within your range
 List<int> gregorianDates = new List<int>() { 3,2, 2015 };

 int number = 3452;

 var result = 
       from i in hijriDates                           
       from j in gregorianDates
       where i + j == number
       select new { Hijri = i  , Gregorian = j};

After you've filtered down the lists of possible matches, you can then work out which of those are the same year. And you can do this using one of the answers from here:

Converting Gregorian date to Hijri date

Community
  • 1
  • 1
Leigh Shepperson
  • 1,043
  • 5
  • 13