In the Thai calendar the year 2017 corresponds to 2560. The Thai calendar is always 543 years ahead of the Gregorian calendar.

Observant coders will note that 2560 is equal to 2^9 * 5, in other words it has 10 prime factors. This will not happen again for another 896 years! We call a year tenacious if it has exactly ten prime factors.

Write a program which outputs a truthy value if the current year using the Thai calendar, based on the system clock, is tenacious, and a falsey value otherwise.

Test cases:

  • If the program is run during 2017, true
  • If the program is run during any of the years 2018 to 2912, false
  • If the program is run during 2913, true (2913+543 = 2^7 * 3^3)
  • \$\begingroup\$ If using a language or running in an environment without a system clock, is it acceptable to take the current time as input? \$\endgroup\$ – Tutleman Mar 25 '17 at 15:45

13 Answers 13


Bash + coreutils, 35 bytes

factor $[`date +%Y`+543]|awk NF==11

Output is either a non-empty string (truthy) or an empty string (falsy).

Try it online!

Alternate version: 37 bytes.

date -d 543year +%Y|factor|awk NF==11

Not as golfy, but I like this one.

Try it online!

How it works

The arithmetic expansion $[date +%Y+543] executes date +%Y to get the current (full) year and adds 543 to the year.

Factor takes the sum as an argument and prints it prime factorization: first the number to be factored, then a list of individual prime factors.

Finally, awk filters the input, printing only lines with exactly 11 fields (the number plus 10 prime factors).


05AB1E, 10 bytes


Try it online! or as a Test suite


      Òg     # the number of primefactors with duplicates of
žg           # the current year
  543+       # plus 543
        TQ   # equals 10

CJam, 13 bytes


Try it online!


et0=  e# Get current year.
543+  e# Add 543.
mf    e# Get prime factors with multiplicity.
,     e# Get length.
A=    e# Equals 10?

Mathematica, 37 31 bytes

5 bytes saved due to lanlock4.


Anonymous function. Takes no input and returns True or False as output.

  • \$\begingroup\$ Now is implicit. You can use DateValue@"Year". \$\endgroup\$ – Martin Ender Mar 24 '17 at 11:04
  • \$\begingroup\$ Do you need the & at the end? Also, Date[][[1]] is a couple of bytes shorter than DateValue@"Year" (if you don't mind that Date is obsolete). \$\endgroup\$ – Not a tree Mar 24 '17 at 11:35
  • 1
    \$\begingroup\$ You can save a byte with #&@@Date[] in place of Date[][[1]]. Also, I think "Mathematica + REPL environment" is a valid programming language here, for which you don't need the terminating &. \$\endgroup\$ – Greg Martin Mar 25 '17 at 2:09
  • \$\begingroup\$ @GregMartin Oh well, I've never been a big fan of that \$\endgroup\$ – LegionMammal978 Mar 25 '17 at 2:13

Pyth, 11 bytes


Online interpreter available here.


       .d3   get current year
   +543      add 543
  P          get prime factors of result
 l           count number of prime factors
q         T  check if equal to 10 (result is implicitly printed)

Japt, 18 14 13 bytes

543+Ki¹k l ¥A

Saved 4 bytes thanks to ETHproductions. Saved 1 byte thanks to obarakon.

Try it online!

  • \$\begingroup\$ Nice answer! You can save a byte if you move things around: A¥º543+Ki¹k l or 543+Ki¹k l ¥A \$\endgroup\$ – Oliver Mar 24 '17 at 15:24
  • \$\begingroup\$ @obarakon Thanks! Why is ¹ used, wouldn't ) do the same thing? \$\endgroup\$ – Tom Mar 24 '17 at 15:36
  • \$\begingroup\$ Yep, you can use ) instead. \$\endgroup\$ – Oliver Mar 24 '17 at 15:42

Python 2, 92 89 bytes

-3 bytes thanks to Jonathan Allan

import time
exec"i+=1\nwhile 1>y%i:y/=i;c-=1\n"*y

Try it online!
Iterate up to the year, extracting (and couting) the prime factors.
The exec line is equivalent to :

for i in range(2,y):
 while not(y%i):
  • \$\begingroup\$ A 3 byte save: c=i=1; c-=1; print-9==c. \$\endgroup\$ – Jonathan Allan Mar 24 '17 at 16:27

Octave, 31 bytes


Try it online!

Two tricks used here:

  • clock()(1) to index directly into the output of clock (clock(1) doesn't work)
  • nnz instead of numel, as all entries are guaranteed to be nonzero.

Alternate version, same byte count


This version can only be used for years exceeding 30, but obviously disregarding time travel this includes all years in which the program can be executed. It works in Matlab as well.


PHP, 111 68 66


directly counts the number of prime factors.

$a=date(Y)+543;             // current year
for($i=2;$i<$a;)            // while $i lower than the year
$b+=$a%$i?!++$i:!!$a/=$i;   // if $i divides $a: $a/=$i and ++$b | if not: ++$i
echo$b==9;                  // output if it has 10 prime factors

Old idea: 111 90


This doesn't use a prime factortoring builtin but basically a counting prime sieve to get the number of prime factors of a number < 10000. This maps to the 4 digit year that PHP provides using date('Y'):

for($i=1;++$i<1e3;)          // for each number smaller sqrt(1e4)
for($j=1;++$j<1e3;)          // do sqrt(1e4) times
${$i*$j}=($$i?:1)+($$j?:1);  // n_factors[i*j] = n_factors[i] + n_factors[j]
echo${date('Y')+543}==10;          // output 1 if the current year has 10 prime factors or nothing if it doesn't
  • 1
    \$\begingroup\$ -2 bytes: Y needs no quotes with -nr. \$\endgroup\$ – Titus Mar 24 '17 at 20:28
  • 1
    \$\begingroup\$ On Your old idea: why initialize? $a[$i*$j]=($a[$i]?:1)+($a[$j]?:1) saves 13 bytes. $j=++$i<1e4 saves one. And no quotes for Y two more. \$\endgroup\$ – Titus Mar 24 '17 at 20:47

MATL, 14 bytes


Try it online!

1&Z'   % Current year
543+   % Add 543
Yf     % Prime factor decomposition
n      % Number of elements
10=    % Equal to 10? Implicitly display

Batch, 123 bytes

@if %r%==0 set/ay/=d-=1,n+=1
@if %y% gtr 1 goto l
@if %n%==12 echo 1

You can fake out the script by manually overriding the date variable before running it.


J, 18 bytes

Program body:


Try it online!

10= is ten equal to

# the tally of

q: the prime factors of

543+ this number added to

{. the head (first item, i.e. the year) of

6!:0'' the date (as Y M D h m s)


JavaScript (ES6), 79 75 bytes


Port of my Batch answer. Pass in the Thai calendar year if you want to perform a specific test. Edit: Saved 4 bytes thanks to @dandavis.

  • \$\begingroup\$ how about new Date().getYear()+2443 \$\endgroup\$ – Matt Mar 25 '17 at 16:20
  • \$\begingroup\$ @Matt Ugh, that's not what MDN says it does... but it's deprecated, so I'm not sure I should be using it anyway. \$\endgroup\$ – Neil Mar 26 '17 at 0:44
  • \$\begingroup\$ passing 2017 == false? shortners: +Date().slice(11,15)+543 and y? instead of y>1 \$\endgroup\$ – dandavis Mar 27 '17 at 9:24
  • \$\begingroup\$ @dandavis y? is pointless, y is never zero. \$\endgroup\$ – Neil Mar 27 '17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.