12
\$\begingroup\$

During the 49 days between Passover and Pentecost, Jewish liturgy provides four numerical problems that I've here phrased as code golf problems.

Input/Arguments

These four, in any order, and by any means:

  • A text \$L\$ consisting of exactly 7 sentences.
    • The first and last sentences have 7 words each, the middle one has 11 words, and the remaining four have 6 words each.
    • The 11-word sentence has 49 letters in total.
    • The sentences may have commas, and they all have a trailing period.
    • You can take this as a 7-element list of strings or as a single string with spaces or line breaks after the inner periods, and optionally after the last one as well.
  • A text \$A\$ consisting of 7 sentences.
    • Each sentence has exactly 6 words.
    • The sentences may have commas, and they all have a trailing period.
    • You can take this as a 7-element list of strings or as a single string with spaces or line breaks after the inner periods, and optionally after the last one as well.
  • A list \$S\$ consisting of exactly 7 words.
    • These are all-lowercase.
    • These have no punctuation.
  • An integer \$N\$ in the inclusive range 1 though 49.
    • You are not allowed to substitute with 0 through 48.

Alternatively, you can use \$L\$, \$A\$, and \$S\$ as predefined variables, and only take \$N\$.

Output/Results

These four, in this precise order, though in any reasonable format, including with extra trailing whitespace:

  1. The text “\$N\$ days, namely \$N_1\$ weeks \$N_0\$ days”, where \$(N_1,N_0)_7\$ is \$N\$ in base seven, except for \$N=49\$ where \$N_1=7\$ and \$N_0=0\$.

    • You must omit the plural “s” after any number that is \$1\$.
    • You must omit any part that is \$0\$.
    • You must omit the second phrase (from and including the comma) if \$N≤6\$.
    • Examples:
      • \$N=1\$: “1 day
      • \$N=6\$: “6 days
      • \$N=7\$: “7 days, namely 1 week
      • \$N=8\$: “8 days, namely 1 week 1 day
      • \$N=13\$: “13 days, namely 1 week 6 days
      • \$N=14\$: “14 days, namely 2 weeks
      • \$N=15\$: “15 days, namely 2 weeks 1 day
  2. The text of \$L\$ but with the \$N\$th word highlighted, and the \$N\$th letter of the middle sentence highlighted.

    • The highlightings must consist of two distinct enclosures of your choice.
    • The enclosing characters must not be letters, nor space, comma, or period. All other visible characters are allowed.
    • For example, you can enclose the word in square brackets (“[word]”) and the letter in curly braces (“l{e}tter”), or you could enclose the word in double-asterisks (“**word**”) and the letter in single-asterisks (“l*e*tter”).
    • Spaces, commas, and periods must not be highlighted.
    • Be aware that there will be a value of \$N\$ for which the highlighted letter will appear inside the highlighted word (“[co{m}bo]” or (“**co*m*bo**” etc.).
  3. The text of \$A\$ but with one word or sentence highlighted.

    • If \$N=1\$ then highlight the first word.
    • Otherwise, if \$N\$ is evenly divisible by \$7\$ then highlight the entire \$N\over7\$th sentence.
    • Otherwise, highlight the word that follows immediately after the highlighting done for \$N-1\$.
    • Commas and periods must not be highlighted when highlighting a word.
    • For example, for \$N=8\$, highlight the first word of the second sentence.
  4. The text “\$S_0\$ in \$S_1\$”, where \$S_0\$ is the \$(M_0+1)\$th word of \$S\$ and \$S_1\$ is the \$(M_1+1)\$th word of \$S\$, and \$M=N-1\$.

    • For example, for \$N=8\$, \$M=N-1=7\$ which is \$(1,0)_7\$, and therefore \$S_0\$ is the second word of \$S\$ and \$S_1\$ is the first word of \$S\$.
    • The trailing period must also be highlighted when highlighting a sentence.

Examples

For these examples, [] is used to highlight words and sentences, {} is used to highlight letters, and \$L\$ is:

God bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk sing joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.

\$A\$ is:

Power please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

\$S\$ is:

kindness
might
beauty
victory
glory
groundedness
royalty

For \$N=1\$

1 day

[God] bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
{F}olk sing joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.
[Power] please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

kindness in kindness

For \$N=6\$

6 days

God bless grace, face shine [us] forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk s{i}ng joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.
Power please, great right, release [captive].
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

groundedness in kindness

For \$N=7\$

7 days, namely 1 week

God bless grace, face shine us [forever].
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk si{n}g joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.
[Power please, great right, release captive.]
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

royalty in kindness

For \$N=8\$

8 days, namely 1 week 1 day

God bless grace, face shine us forever.
[Know] earth ways, saves all nations.
Praise people Lord, all people praise.
Folk si{n}g joy, for judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.
Power please, great right, release captive.
[Accept] prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

kindness in might

For \$N=13\$

13 days, namely 1 week 6 days

God bless grace, face shine us forever.
Know earth ways, saves all [nations].
Praise people Lord, all people praise.
Folk sing joy, f{o}r judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome [purify].
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

groundedness in might

For \$N=14\$

14 days, namely 2 weeks

God bless grace, face shine us forever.
Know earth ways, saves all nations.
[Praise] people Lord, all people praise.
Folk sing joy, fo{r} judges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.
Power please, great right, release captive.
[Accept prayer, strengthen people, Awesome purify.]
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

royalty in might

For \$N=15\$

15 days, namely 2 weeks 1 day

God bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise [people] Lord, all people praise.
Folk sing joy, for {j}udges people justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
[Please] Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

kindness in beauty

For \$N=25\$

25 days, namely 3 weeks 4 days

God bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk sing joy, for judges [peop{l}e] justly, guide earth folk ever.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth ends.
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous [mercy], bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
Accept supplication, hear cry, thoughts knower.

victory in victory

For \$N=49\$

49 days, namely 7 weeks

God bless grace, face shine us forever.
Know earth ways, saves all nations.
Praise people Lord, all people praise.
Folk sing joy, for judges people justly, guide earth folk eve{r}.
Praise people Lord, all people praise.
Earth gives produce, bless our God.
Bless God, fear Him all earth [ends].
Power please, great right, release captive.
Accept prayer, strengthen people, Awesome purify.
Please Mighty, Oneness seekers, eye guard.
Bless cleanse, righteous mercy, bestow always.
Powerful Holy, abounding goodness, guide congregation.
Exalted One, people turn, remember holiness.
[Accept supplication, hear cry, thoughts knower.]

royalty in royalty

\$\endgroup\$
4
  • \$\begingroup\$ What happens when N=49? N in base 7 is 100, but do we take N₁ to be 7? What happens with N₁+1 for the S output? \$\endgroup\$ – Neil Apr 22 at 14:57
  • \$\begingroup\$ @Neil Thank you for that. My mathematical spec was wrong. Should be right now. \$\endgroup\$ – Adám Apr 22 at 15:25
  • \$\begingroup\$ With N=7 in your test case, my program highlights forever. instead of forever. Is that acceptable? \$\endgroup\$ – ophact Apr 23 at 9:32
  • 1
    \$\begingroup\$ @ophact No, that is explicitly prohibited by Spaces, commas, and periods must not be highlighted. \$\endgroup\$ – Adám Apr 23 at 9:36
5
\$\begingroup\$

Python 3, 365 bytes

import re
i=N=int(input())
p=print
Y=N//7
Z=N%7
p(N,"day"+"s"*(N>1)+(f", namely {Y} week{'s'*(N>13)}"+f" {Z} day{'s'*(Z>1)}"*(Z>0))*(N>6))
s="[]"
def a(x):global i;i-=1;x=x.group();return i and x or x.join(s)
b=re.sub
L=b("\w+",a,L).split("\n")
if Z:i=N-Y;A=b("\w+",a,A)
else:i=Y;A=b(".+",a,A)
s="{}"
i=N
L[3]=b("\w",a,L[3])
[*map(p,L)]
p(A)
p(S[~-N%7],"in",S[~-Y])

Try it online!

-27 bytes thanks to RootTwo
-6 bytes thanks to ovs

Accepts \$L,A,S\$ as pre-defined variables. These definitions are in the header, but I am reading from STDIN just to make testing easier.

\$\endgroup\$
6
  • \$\begingroup\$ b=re.sub and putting ,a in each call would save 10; p=print would save 9; Y=N//7 and Z=N%7 would save 11; i=N=int(input()) would save 2, \$\endgroup\$ – RootTwo Apr 23 at 2:49
  • \$\begingroup\$ @RootTwo Oh, nice golfs. Thank you :) \$\endgroup\$ – hyper-neutrino Apr 23 at 2:51
  • \$\begingroup\$ @ophact Not sure if this is what you meant, but this: tinyurl.com/3cwr3v32 is a net change of 0 bytes \$\endgroup\$ – hyper-neutrino Apr 23 at 10:16
  • \$\begingroup\$ Okay then, I thought it would have saved some bytes \$\endgroup\$ – ophact Apr 23 at 10:18
  • 1
    \$\begingroup\$ The last line can be shortened by passing multiple arguments to print: p(S[~-N%7],"in",S[~-Y]) (The same applies for the first print call) \$\endgroup\$ – ovs Apr 23 at 11:53
3
\$\begingroup\$

Retina 0.8.2, 323 bytes

^.+
$*
^(1(1{7})*(1)*[\w\W]*¶¶)(?=(?<-3>.+¶)*(.+))(?<-2>.+¶)*(.+)(¶.+)*
$1$4 in $5
^((1{7})*(1)?(1)*¶(¶.+)+¶(?<-2>.*¶)*)(?(3)(.*¶(?<-4>\w+\W+)*)(\w+)|(.+))
$1$6<$7$8>
^(1(1)*¶¶(?<-2>\w+\W+)*)(\w+)
$1<$3>
^(1(1)*¶¶(.+¶){3}<?(?<-2>\w\W*)*)(\w)
$1{$4}
^(1{7})*(1)*
$.& days, namely $#1 weeks $#2 days
(,.*y)? 0.*|\b(1 \w+)s
$2

Try it online! Takes N, L, A and S as input, double-spaced from each other. Explanation:

^.+
$*

Convert N to unary.

^(1(1{7})*(1)*[\w\W]*¶¶)(?=(?<-3>.+¶)*(.+))(?<-2>.+¶)*(.+)(¶.+)*
$1$4 in $5

Divmod N-1 by 7, capturing the appropriate words from S and replacing S with the desired phrase.

^((1{7})*(1)?(1)*¶(¶.+)+¶(?<-2>.*¶)*)(?(3)(.*¶(?<-4>\w+\W+)*)(\w+)|(.+))
$1$6<$7$8>

Divmod N by 7. If the remainder was zero, then capture the N/7th line of A, otherwise capture the N%7-1th word on the following line. Surround it with <>s.

^(1(1)*¶¶(?<-2>\w+\W+)*)(\w+)
$1<$3>

Capture the Nth word of L and surround it with <>s.

^(1(1)*¶¶(.+¶){3}<?(?<-2>\w\W*)*)(\w)
$1{$4}

Capture the Nth letter of the middle line of L and surround it with {}s.

^(1{7})*(1)*
$.& days, namely $#1 weeks $#2 days

Divmod N by 7 again. Convert N back to decimal, as well as N/7 and N%7, as the desired phrase, assuming all values exceed 1.

(,.*y)? 0.*|\b(1 \w+)s
$2

Fix up 0 and 1 values.

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

JavaScript (Node.js), 539... 431 bytes

(L,A,S,N,B=N%7,J=N/7,u=D=>D>1?'s':'',z=/[. ,]/,g=w=>`[${w.replace(z,'')}]${z.test(w)?w.slice(-1):''}`)=>[N+` day${u(N)}${N>6?`, namely ${H=J|0} week${u(H)} ${B?B+` day`+u(B):''}`:''}`,(t=0)||(L[3]=L[3].replace(/[a-zA-Z]/g,c=>++t==N?`{${c}}`:c))&&L.join` `.split` `.map((e,i)=>i==N-1?g(e):e).join` `,A.map((e,i)=>N%7?i==~~J?((E=e.split` `)[--B]=g(E[B]))&&E.join` `:e:i==J-1?`[${e}]`:e).join`
`,S[N%7?B:6]+' in '+S[N<8?0:N>48?6:J|0]]

Try it online!

This is long. Like REALLY long.

Takes L, A and S as arrays of strings.

I also love how the code breaks the syntax highlighter.

How does it work?

Declares a huge amount of default arguments to save on bytes, as many of these arguments are referred to later. The first four arguments are simply the texts.

B and J are simply values derived from N which are used extensively in the code.

u is a helper function which returns an s depending on the value of the input.

z is simply a regular expression characterized by a single character class containing all forbidden characters for highlighting: space, period and comma.

g is a helper function called twice which highlights a word without forbidden characters being caught up in the word.

In the function body, we return an array of four strings:

  • using rudimentary ternaries, get the formatted "days" string.
  • the L-string. Procedure: first, replace the fourth sentence with the same sentence but with one letter highlighted. Then do the word highlighting using the g function.
  • the A-string. Frankly, even I can't read my own code, but essentially highlights one word or one sentence. Can't go into detail on this one.
  • the S-string. A bunch of simple ternaries based on the value of N.
\$\endgroup\$
6
  • \$\begingroup\$ Doesn't work for me in FF. Also, surely you can remove the spaces in (L, A, S, N), no? \$\endgroup\$ – Adám Apr 23 at 10:30
  • \$\begingroup\$ Oh, I see. I tried using the SE button ;-) \$\endgroup\$ – Adám Apr 23 at 10:39
  • \$\begingroup\$ Maybe you could add a link to run it? Check out tio.run/#javascript-node \$\endgroup\$ – Adám Apr 23 at 13:27
  • \$\begingroup\$ I think adding a helper function somewhere like H=u=>u>1?'s':'' might save two bytes? Or would that be disallowed, since you're currently using an anonymous function as an answer? \$\endgroup\$ – Adalynn May 4 at 18:03
  • \$\begingroup\$ @Adalynn well I could do that but at least judging by my rough counting (at a glance) it doesn't seem to make much of a difference. \$\endgroup\$ – ophact May 4 at 18:05

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.