12
\$\begingroup\$

Write, in as few characters as possible, a program that takes zero or six command-line arguments

menorah
menorah YEAR MONTH DAY HOUR MINUTE SECOND

(Both forms must be supported. The zero-argument version shall be equivalent to calling the six-argument version with the current system date and time in the local timezone.)

and if the specified (Gregorian-calendar) date and time falls during Hanukkah, then output an ASCII art (or Unicode art) nine-branch menorah with the appropriate number of candles lit. If it is not during Hanukkah, then output a single newline. For example,

~$ ./menorah 2015 12 7 0 0 0

    *
    |   *
    |   |
    |   |
+++++++++
    |
   -+-

~$ ./menorah 2015 12 9 0 0 0

    *
    | ***
    | |||
    | |||
+++++++++
    |
   -+-

~$ ./menorah 2015 12 14 0 0 0

    *
****|****
|||||||||
|||||||||
+++++++++
    |
   -+-

~$ ./menorah 2015 12 15 0 0 0
~$

On the Nth day of the festival, N+1 candles are lit: The central shamash candle, and N of the 8 Hanukkah candles, placed in right-to-left order.

Allowed variations in the output format are:

  • Unused candles may be drawn unlit instead of omitted.
  • You may use non-ASCII characters to make the result more aesthetically pleasing. Like 🔥 (U+1F525) instead of *. Or box-drawing characters instead of +-|.

For the purpose of this challenge, a day on the Hebrew calendar may be assumed to start at 18:00.

Results must be correct for Gregorian years between 1900 and 2239, inclusive.


Hanukkah begins at sunset on the Gregorian dates

1900-12-16  1901-12-05  1902-12-24  1903-12-13  1904-12-02  1905-12-22
1906-12-11  1907-11-30  1908-12-18  1909-12-07  1910-12-25  1911-12-15
1912-12-04  1913-12-23  1914-12-12  1915-12-01  1916-12-19  1917-12-09
1918-11-28  1919-12-16  1920-12-05  1921-12-25  1922-12-14  1923-12-02
1924-12-21  1925-12-11  1926-11-30  1927-12-18  1928-12-07  1929-12-26
1930-12-14  1931-12-04  1932-12-23  1933-12-12  1934-12-01  1935-12-20
1936-12-08  1937-11-28  1938-12-17  1939-12-06  1940-12-24  1941-12-14
1942-12-03  1943-12-21  1944-12-10  1945-11-29  1946-12-17  1947-12-07
1948-12-26  1949-12-15  1950-12-03  1951-12-23  1952-12-12  1953-12-01
1954-12-19  1955-12-09  1956-11-28  1957-12-17  1958-12-06  1959-12-25
1960-12-13  1961-12-02  1962-12-21  1963-12-10  1964-11-29  1965-12-18
1966-12-07  1967-12-26  1968-12-15  1969-12-04  1970-12-22  1971-12-12
1972-11-30  1973-12-19  1974-12-08  1975-11-28  1976-12-16  1977-12-04
1978-12-24  1979-12-14  1980-12-02  1981-12-20  1982-12-10  1983-11-30
1984-12-18  1985-12-07  1986-12-26  1987-12-15  1988-12-03  1989-12-22
1990-12-11  1991-12-01  1992-12-19  1993-12-08  1994-11-27  1995-12-17
1996-12-05  1997-12-23  1998-12-13  1999-12-03  2000-12-21  2001-12-09
2002-11-29  2003-12-19  2004-12-07  2005-12-25  2006-12-15  2007-12-04
2008-12-21  2009-12-11  2010-12-01  2011-12-20  2012-12-08  2013-11-27
2014-12-16  2015-12-06  2016-12-24  2017-12-12  2018-12-02  2019-12-22
2020-12-10  2021-11-28  2022-12-18  2023-12-07  2024-12-25  2025-12-14
2026-12-04  2027-12-24  2028-12-12  2029-12-01  2030-12-20  2031-12-09
2032-11-27  2033-12-16  2034-12-06  2035-12-25  2036-12-13  2037-12-02
2038-12-21  2039-12-11  2040-11-29  2041-12-17  2042-12-07  2043-12-26
2044-12-14  2045-12-03  2046-12-23  2047-12-12  2048-11-29  2049-12-19
2050-12-09  2051-11-28  2052-12-15  2053-12-05  2054-12-25  2055-12-14
2056-12-02  2057-12-21  2058-12-10  2059-11-29  2060-12-17  2061-12-07
2062-12-26  2063-12-15  2064-12-03  2065-12-22  2066-12-12  2067-12-01
2068-12-18  2069-12-08  2070-11-27  2071-12-16  2072-12-04  2073-12-24
2074-12-13  2075-12-01  2076-12-20  2077-12-10  2078-11-29  2079-12-17
2080-12-06  2081-12-26  2082-12-15  2083-12-04  2084-12-22  2085-12-11
2086-11-30  2087-12-19  2088-12-07  2089-11-27  2090-12-16  2091-12-05
2092-12-23  2093-12-13  2094-12-02  2095-12-20  2096-12-09  2097-11-29
2098-12-18  2099-12-06  2100-12-26  2101-12-16  2102-12-05  2103-12-23
2104-12-12  2105-12-02  2106-12-21  2107-12-10  2108-11-28  2109-12-17
2110-12-06  2111-12-25  2112-12-13  2113-12-03  2114-12-22  2115-12-10
2116-11-29  2117-12-19  2118-12-08  2119-12-26  2120-12-15  2121-12-04
2122-12-23  2123-12-12  2124-12-01  2125-12-21  2126-12-10  2127-11-29
2128-12-17  2129-12-06  2130-12-24  2131-12-14  2132-12-03  2133-12-22
2134-12-11  2135-11-30  2136-12-18  2137-12-07  2138-12-26  2139-12-15
2140-12-04  2141-12-23  2142-12-12  2143-12-01  2144-12-20  2145-12-09
2146-11-27  2147-12-17  2148-12-05  2149-12-24  2150-12-13  2151-12-03
2152-12-22  2153-12-11  2154-11-30  2155-12-19  2156-12-07  2157-12-25
2158-12-15  2159-12-05  2160-12-23  2161-12-12  2162-12-01  2163-12-20
2164-12-09  2165-11-28  2166-12-16  2167-12-06  2168-12-24  2169-12-13
2170-12-02  2171-12-22  2172-12-10  2173-11-28  2174-12-18  2175-12-08
2176-12-26  2177-12-14  2178-12-04  2179-12-24  2180-12-12  2181-12-01
2182-12-20  2183-12-09  2184-11-28  2185-12-17  2186-12-06  2187-12-25
2188-12-14  2189-12-03  2190-12-21  2191-12-11  2192-11-29  2193-12-17
2194-12-07  2195-12-27  2196-12-15  2197-12-03  2198-12-23  2199-12-13
2200-12-02  2201-12-20  2202-12-10  2203-11-30  2204-12-18  2205-12-07
2206-12-26  2207-12-15  2208-12-03  2209-12-22  2210-12-11  2211-12-01
2212-12-19  2213-12-08  2214-12-27  2215-12-17  2216-12-05  2217-12-23
2218-12-13  2219-12-02  2220-12-20  2221-12-09  2222-11-29  2223-12-18
2224-12-05  2225-12-25  2226-12-15  2227-12-04  2228-12-21  2229-12-11
2230-12-01  2231-12-20  2232-12-08  2233-12-27  2234-12-16  2235-12-05
2236-12-23  2237-12-12  2238-12-02  2239-12-21
\$\endgroup\$
  • 9
    \$\begingroup\$ For those of us who are not Jewish (and for those who are but don't know how to calculate the Jewish calendar) please explain how the start of Hanukkah is calculated. You should also explain the sequence of lighting the candles (it seems to be one per day, but does it matter which candle you light? ) \$\endgroup\$ – Level River St Nov 18 '15 at 5:18
  • \$\begingroup\$ Are we required to support both zero and six command-line arguments, or can we choose? \$\endgroup\$ – lirtosiast Nov 18 '15 at 5:27
  • \$\begingroup\$ @ThomasKwa: Both. The difference is that the zero-argument version uses the current date and time. \$\endgroup\$ – dan04 Nov 18 '15 at 5:39
  • 1
    \$\begingroup\$ the option to draw unused candles as unlit means the dynamic ascii art portion of this is just one row of toggled asterisks, which is not interesting at all. not that I find the larger ascii art drawing particularly interesting to begin with. \$\endgroup\$ – Sparr Nov 19 '15 at 2:07
  • 1
    \$\begingroup\$ @Sparr the ascii art portion is far from the most challenging part of this challenge at end, the conversion from gregorian to hebrew Date and checking if we're within the Holidays or not is far more interesting IMO \$\endgroup\$ – Tensibai Nov 19 '15 at 13:32
3
\$\begingroup\$

Mathematica, 376 338 334 bytes

a=Rest@$ScriptCommandLine;b=CalendarConvert[If[a=={},Now~TimeZoneConvert~0,DateObject[FromDigits/@a,TimeZone->0]],j="Jewish"];c=Floor@DateDifference[DateObject[{b[[1,1]],9,25},CalendarType->j,TimeZone->0],b][[1]];d=If[#<=c,"*"," "]&;0<=c<8&&Print["    *
"<>{d/@{7,6,5,4},"|",d/@{3,2,1},"*
|||||||||
|||||||||
+++++++++
    |
   -+-"}]

Runs in a script.

\$\endgroup\$
3
\$\begingroup\$

R, 467 bytes

With a little doubt if using a library for the Calendar conversion is allowed or not.

library(ConvCalendar)
f='%Y %m %d %H %M %S'
g='hebrew'
s=' '
if(length(n<-scan())!=6)n=format(Sys.time(),f)
if(n[4]>17)n[3]=n[3]+1
d=strptime(paste(n,collapse=s),f)
h=as.OtherDate(d,g)
i=OtherDate(25,3,h$year,g)
j=round(difftime(d,as.Date(i),,"days"))+1
N=ifelse(j>0&j<10,(1:9)[j],0)
if(!N)write('')else{l='**||+|+'
z=matrix(strsplit(l,'')[[1]],9,7,T)
z[c(1:4,6:9),c(1,6:7)]=s
z[c(4,6),7]='-'
if(N<8)z[1:(9-N),2:4]=s
z[5,2:4]='|'
write(z,'',9,,'')}

Example for input 2015 12 07 00 00 00:

    *    
    |   *
    |   |
    |   |
+++++++++
    |    
   -+-   
\$\endgroup\$
  • \$\begingroup\$ My eyes........ :) \$\endgroup\$ – David Arenburg Nov 19 '15 at 11:21
1
\$\begingroup\$

APL (Dyalog), 193 bytes

Prompts for input from STDIN and prints to STDOUT.

Uses box drawing characters and an actual lamp symbol!

⎕USING←'System'
→3×(c←+/i≥((⎕NEW Globalization.HebrewCalendar).(ToDateTime 7↑3 23 18,⍨GetYear)i←⎕NEW DateTime(6↑⍎∊⍞'⎕TS')).AddDays¨⍳9)∊⍳8
¯5↑'⍝'
'⍝'@(10-r+5≤r←⍳c)⊢9↑s←¯5↑'│'
9/⍪'││┴'
s
'   ─┴─'

⎕USING←'System' Use .NET

⍳8 first eight ɩntegers
()∊ Boolean for whether the following is a member of that:
⍳9 first nine integers
().AddDays¨ for each, add that many days to:
  ⎕NEW DateTime() a new DateTime .NET object with the value of:
   ⍞'⎕TS' STDIN and expression for current Time Stamp
   ϵnlist (flatten)
    execute (evaluate) that (gives six- or seven-element numeric list)
   6↑ take the first six elements (Y M D h m s)
  i← store as i (for input)
  (⎕NEW Globalization.HebrewCalendar).() in a new HebrewCalendar object:
   GetYear get the (Hebrew) year of the input
   3 23 18,⍨ append these (3 month, 23th day, 18th hour — one night before Hanukkah)
   7↑ take the first seven elements, padding with 0s (minutes, seconds)
   ToDateTime convert that Hebrew point in time to normal DateTime object
i≥ Boolean whether the input is equal to or after each of those
+/ sum the Booleans
c← store as c (for count)
 multiply by three
 go to that line (3, i.e. next, if Hanukkah; 0, i.e. quit, if not)

¯5↑'⍝' implicitly print the last five characters of the lamp symbol (padding with spaces)

¯5↑'│' last five characters of the middle-candle symbol (padding with spaces)
s← store as s (for stem)
9↑ take the first nine characters from that (padding with spaces)
 yield (separates the above from the below
'⍝'@() implicitly print with lamps placed at the following indices:
⍳c as many ɩntegers as count of begun Hanukkah days
r← store in r (for range)
5≤ Booleans for those larger than or equal to five (to skip the middle candle)
r+ add to the range of indices
10- subtract those from ten (to begin at the right)

⍪'││┴' make this string into a column matrix
9/ implicitly print nine horizontal copies of that

s implicitly print the stem

' ─┴─' implicitly print this string

Example run:

      menorah
2015 12 7 0 0 0
    ⍝
    │   ⍝
│││││││││
│││││││││
┴┴┴┴┴┴┴┴┴
    │
   ─┴─
      menorah
2015 12 9 0 0 0
    ⍝
    │ ⍝⍝⍝
│││││││││
│││││││││
┴┴┴┴┴┴┴┴┴
    │
   ─┴─
      menorah
2015 12 14 0 0 0
    ⍝
⍝⍝⍝⍝│⍝⍝⍝⍝
│││││││││
│││││││││
┴┴┴┴┴┴┴┴┴
    │
   ─┴─
      menorah
2015 12 15 0 0 0
\$\endgroup\$

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.