13
\$\begingroup\$

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 \times 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 \times 3^3\$)
\$\endgroup\$
1
  • \$\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\$ Mar 25, 2017 at 15:45

13 Answers 13

6
\$\begingroup\$

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

\$\endgroup\$
1
5
\$\begingroup\$

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
\$\endgroup\$
4
\$\begingroup\$

CJam, 13 bytes

et0=543+mf,A=

Try it online!

Explanation

et0=  e# Get current year.
543+  e# Add 543.
mf    e# Get prime factors with multiplicity.
,     e# Get length.
A=    e# Equals 10?
\$\endgroup\$
0
4
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ Now is implicit. You can use DateValue@"Year". \$\endgroup\$ Mar 24, 2017 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, 2017 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\$ Mar 25, 2017 at 2:09
  • \$\begingroup\$ @GregMartin Oh well, I've never been a big fan of that \$\endgroup\$ Mar 25, 2017 at 2:13
3
\$\begingroup\$

Pyth, 11 bytes

qlP+543.d3T

Online interpreter available here.

Explanation

       .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)
\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
3
  • \$\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, 2017 at 15:24
  • \$\begingroup\$ @obarakon Thanks! Why is ¹ used, wouldn't ) do the same thing? \$\endgroup\$
    – Tom
    Mar 24, 2017 at 15:36
  • \$\begingroup\$ Yep, you can use ) instead. \$\endgroup\$
    – Oliver
    Mar 24, 2017 at 15:42
2
\$\begingroup\$

Python 2, 92 89 bytes

-3 bytes thanks to Jonathan Allan

import time
y=time.gmtime()[0]+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
\$\endgroup\$
1
  • \$\begingroup\$ A 3 byte save: c=i=1; c-=1; print-9==c. \$\endgroup\$ Mar 24, 2017 at 16:27
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

PHP, 111 68 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
\$\endgroup\$
2
  • 1
    \$\begingroup\$ -2 bytes: Y needs no quotes with -nr. \$\endgroup\$
    – Titus
    Mar 24, 2017 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, 2017 at 20:47
0
\$\begingroup\$

MATL, 14 bytes

1&Z'543+Yfn10=

Try it online!

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

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.

\$\endgroup\$
0
\$\begingroup\$

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)

\$\endgroup\$
0
\$\begingroup\$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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