# The Tenacious Thai Calendar

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)
• If using a language or running in an environment without a system clock, is it acceptable to take the current time as input? – Tutleman Mar 25 '17 at 15:45

# 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).

• – seshoumara Mar 24 '17 at 12:09

# 05AB1E, 10 bytes

žg543+ÒgTQ


Try it online! or as a Test suite

Explanation

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


## CJam, 13 bytes

et0=543+mf,A=


Try it online!

### Explanation

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


# Mathematica, 37 31 bytes

5 bytes saved due to lanlock4.

PrimeOmega[#&@@Date[]+543]==10&


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

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

# Pyth, 11 bytes

qlP+543.d3T


Online interpreter available here.

## Explanation

       .d3   get current year
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!

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

# Python 2, 92 89 bytes

-3 bytes thanks to Jonathan Allan

import time
y=time.gmtime()+543
c=i=1
exec"i+=1\nwhile 1>y%i:y/=i;c-=1\n"*y
print-9==c


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):
y=y/i
c=c-1

• A 3 byte save: c=i=1; c-=1; print-9==c. – Jonathan Allan Mar 24 '17 at 16:27

# Octave, 31 bytes

nnz(factor(clock()(1)+543))==10


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

nnz(factor(max(clock)+543))==10


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, 11168 66

$a=date(Y)+543;for($i=2;$i<$a;)$b+=$a%$i?!++$i:!!$a/=$i;echo$b==9;  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 for($i=1;++$i<1e3;)for($j=1;++$j<1e3;)${$i*$j}=($$i?:1)+($$j?:1);echo${date('Y')+543}==10;  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  • -2 bytes: Y needs no quotes with -nr. – Titus Mar 24 '17 at 20:28 • 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. – Titus Mar 24 '17 at 20:47

# MATL, 14 bytes

1&Z'543+Yfn10=


Try it online!

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


## Batch, 123 bytes

@set/ay=%date:~-4%+543,n=d=2
:l
@set/ar=y%%d,d+=1
@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:

10=#q:543+{.6!:0''

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

f=(y=+Date().slice(11,15)+543,d=2,n=10)=>y>1?y%d?f(y,d+1,n):f(y/d,d,n-1):!n


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.

• how about new Date().getYear()+2443 – Matt Mar 25 '17 at 16:20
• @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. – Neil Mar 26 '17 at 0:44
• passing 2017 == false? shortners: +Date().slice(11,15)+543 and y? instead of y>1 – dandavis Mar 27 '17 at 9:24
• @dandavis y? is pointless, y is never zero. – Neil Mar 27 '17 at 9:37