Created
March 10, 2023 15:59
-
-
Save kspalaiologos/faa398b02e1dd706afa245809e21b3ed to your computer and use it in GitHub Desktop.
5165 Jelly answers from CodeGolf StackExchange site.
We can't make this file beautiful and searchable because it's too large.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Author,Code | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>Ḥ‘$3СẒḄ=ʋƇ13 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjiWPGmaoGB@ecGjhw12THu5osT3Vfazd0Pi/zuF2b5WsRw1zFGztFB41zNWM/P/f0EBHwdDUAEQaAAEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>Ḥ‘$3СẒḄ=ʋƇ13 - Main link. Takes an integer n on the left | |
ʋ 13 - Last 4 links as a dyad f(i, 13): | |
$ - Last 2 links as a monad g(i): | |
Ḥ - 2i | |
‘ - 2i+1 | |
3С - Collect [i, g(i), g(g(i)), g(g(g(i)))] | |
Ẓ - Is prime? | |
Ḅ - Convert from binary | |
= - Does that equal 13? I.e. is the pattern [prime, prime, composite, prime]? | |
Ƈ - Filter 1 ≤ i ≤ n by f(i, 13) | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>OḂo-ẆSÐḟẈṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9//4Y6mfN2Hu9qCD094uGP@w10dD3c2/D/c/qhpzf//SpoaQKippKOgpIHMglBKAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>OḂo-ẆSÐḟẈṀ - Main link. Takes a string S on the left | |
O - Ord; ( -> 40, ) -> 41 | |
Ḃ - Bit; ( -> 0, ) -> 1 | |
o- - Or -1; ( -> -1, ) -> 1 | |
Ẇ - All contiguous subsets | |
SÐḟ - Keep those with a zero sum | |
Ẉ - Length of each | |
Ṁ - Maximum | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 12 </s> 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>B«\)LÐṀFS)Ṁ | |
</code></pre> | |
<p>A monadic Link that accepts <span class=""math-container"">\$n\$</span> and yields the largest binary area when arranging the numbers <span class=""math-container"">\$1\$</span> to <span class=""math-container"">\$n\$</span> inclusive.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/p0OoYTZ/DEx7ubHAL1gSS/w@3P2pa8/@/mTEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>B«\)LÐṀFS)Ṁ - Link: positive integer, n | |
) - for each (i in [1..n]): | |
) - for each (j in [1..i]): | |
B - convert (j) to binary | |
\ - cumulative reduce by: | |
« - minimum (i.e. zero any bits after the first 0) | |
ÐṀ - keep those maximal under: | |
L - length (e.g. j = 27 -> [zeroed(binary(16))..zeroed(binary(27))]) | |
F - flatten | |
S - sum | |
Ṁ - maximum | |
</code></pre> | |
" | |
"96039","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 1 byte</h1> | |
<pre><code>B | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/p////hkbGJgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Lmao my first answer in Jelly. Just a builtin.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 4 </s> 2 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ỤỤ | |
</code></pre> | |
<p>A monadic Link that accepts a bitmask identifying the high watermarks and yields a permutation.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///h7iVA9P///2hDHQUDMDIEIwjbIBYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///h7iVA9P9w@6OmNf//R0cb6iiAUKyOAoypo2AARFABAzBCCKPLYBMAsWNjAQ"" rel=""nofollow noreferrer"">test-suite</a>.</p> | |
<h4>How?</h4> | |
<pre><code>ỤỤ - Link: bitmask e.g. [1,0,0,1,0,0] | |
Ụ - grade-up (indices of sorted values) [2,3,5,6,1,4] | |
Ụ - grade-up (indices of sorted values) [5,1,2,6,3,4] | |
</code></pre> | |
<hr /> | |
<h3>Previous at 4 bytes (not using a bitmask):</h3> | |
<pre><code>ReÞỤ | |
</code></pre> | |
<p>A dyadic Link that accepts the number on the left and the high watermark indices on the right and yields a permutation.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z8o9fC8h7uX/P//3@J/tKGOiY5pLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/z8o9fC8h7uX/D@83EH/UdOa//@jo6MNdRSMdBSMY8GYSwFZwBQuYALmKFhABVDkQBJmQF4sAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h4>How?</h4> | |
<pre><code>ReÞỤ - Link: n; I e.g. n=6; I=[1,4] | |
R - range (n) [1,2,3,4,5,6] | |
Þ - sort by: | |
e - exists in (I)? [2,3,5,6,1,4] | |
Ụ - grade-up (indices of sorted values) [5,1,2,6,3,4] | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>1ḟ1# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/w4Y75hsr/D7drRv7/H22oo2Cko2Acq6MQbayjYKKjoAsUMQRxzXUULHQULIE8kIgRSEjXFCgPUgNUqmsEUWsAlISYoaMAlAbqMjQAqQWrN4SqN48FAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> 1# Find the first integer | |
1 starting from 1 | |
ḟ which is not empty with elements of the list filtered out. | |
</code></pre> | |
" | |
"110951","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ṀŻ‘ḟ³Ṃ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzoajux81zHi4Y/6hzQ93Nv3//z9a11BHQdcEiM1jAQ"" rel=""nofollow noreferrer"">Try it online</a></p> | |
<h3>Explanation</h3> | |
<pre><code>ṀŻ‘ḟ³Ṃ # | [-1, 0, 1, 4] | |
Ṁ # Maximum | 4 | |
Ż # Range from 0 | [0, 1, 2, 3, 4] | |
‘ # Increment | [1, 2, 3, 4, 5] | |
ḟ # Filter out items | | |
³ # In the input | [2, 3, 5] | |
Ṃ # Minimum | 2 | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>11</s> 9 bytes</h1> | |
<pre><code>;DẒ;ŒQẠµ# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/a5eGuSdZHJwU@3LXg0Fbl//8NLQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <span class=""math-container"">\$1 \le n \le 18\$</span> on STDIN and returns the first <span class=""math-container"">\$n\$</span></p> | |
<h2>How it works</h2> | |
<pre><code>;DẒ;ŒQẠµ# - Main link. Takes no arguments | |
µ - Previous chain as a monad f(k): | |
D - Digits of k, D | |
; - Prepnd k | |
Ẓ - Prime? | |
ŒQ - Unique sieve; Cast k to digits, replace a digit with a 1 if it hasn't appeared before, else 0 | |
; - Concatenate the two lists | |
Ạ - All truthy? | |
# - Read n from STDIN. Starting k=0, count up until n k's return true under f(k) | |
</code></pre> | |
<p>The way <code>ŒQ</code> works can be shown e.g. with <span class=""math-container"">\$k = 75523\$</span>:</p> | |
<pre><code> [7, 5, 5, 2, 3] | |
ŒQ:[1, 1, 0, 1, 1] | |
</code></pre> | |
<p>It auto-casts <span class=""math-container"">\$k\$</span> to digits, then replaces all but the first occurence of each element with <code>0</code>.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>æRḟ, | |
</code></pre> | |
<p>A dyadic Link that accepts the one bound on the left and the other bound on the right and yields a list of primes strictly between the bounds.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wsqCHO@br/P//3/S/oTkA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>æRḟ, - Link: integer, A; integer, B | |
æR - inclusive prime range -> list of primes between A and B, inclusive | |
, - pair -> [A, B] | |
ḟ - filter discard -> list of primes between A and B, exclusive | |
</code></pre> | |
" | |
"114446","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 2 <a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>DS | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/98l@P///4ZGxgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>D digits | |
S sum | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>EƙẠ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/12MyHuxb8P7xc/1HTGiBy//8/GgiMdRSAyExHwSRWRyHaVEcBiExAvFgdLgWF6GhLHQVDHQUjkKQJqgxICMY2BHEM4TyoBiOgXrAYCEPsAgoZg9WCLTJD1gEWQdYKFgMJw1RZ6ChAEUgJhAl0nyWSKSAE1W@M5FZDuHEISZh8bCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Uses the same input format as <a href=""https://codegolf.stackexchange.com/a/163379/85334"">Dennis's solution</a>, and does almost exactly the same thing. Considering that <a href=""https://github.com/DennisMitchell/jellylanguage/commit/0fe21609e36c2d25fbf8f04a7c0f03d981482457"" rel=""nofollow noreferrer""><code>ƙ</code> had been implemented for half a year at that point</a>, the only conclusion I can draw is that even he couldn't remember how the damn thing works :P</p> | |
<p>Stumbled on this because I thought of <a href=""https://tio.run/##y0rNyan8///opIc71wQ/3Lng2MT/UaGH2zUfNa1x//8/GgiMdRSAyExHwSRWRyHaVEcBiExAvFgdLgWF6GhLHQVDHQUjkKQJsoxydDRIDKbMEMQxhPOgOoyAmsFiIAyxDChkDFYLtskMWQdYBFkrWAwkDFNloaMARSAlECbQgZZIpoAQVL8xkjcM4cYhJGHysbEA"" rel=""nofollow noreferrer""><code>ŒṬSṠƑ</code></a>, which is way funnier (directly implements the classic "vertical line test") but unfortunately errors given any empty lists.</p> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>~cŻÄÆmA | |
</code></pre> | |
<p>This calculates <code>abs(mean(cumsum(choose(-n-1, [0..n]))))</code>.</p> | |
<p><a href=""https://tio.run/##y0rNyan8/78u@ejuwy2H23Id/wMZ7Y@a1vz/b2gAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>The "negative binomial coefficients" are defined as <span class=""math-container"">$$\binom{-a}{b} = (-1)^b \binom{a+b-1}{b}.$$</span> | |
And they are supported by Jelly's <code>c</code>. So we can rewrite the closed form as:</p> | |
<p><span class=""math-container"">\begin{align} | |
F_n&=\frac{1}{n+1}\sum_{k=0}^n(-1)^k(k+1)\binom{2n-k}{n-k} \\ | |
& \color{gray}{\text{(introduce negative binomials:)}} \\ | |
&=\frac{1}{n+1}\sum_{k=0}^n(-1)^k(k+1) \color{#0bf}{(-1)^{n-k} \binom{-n-1}{n-k}} \\ | |
& \color{gray}{\text{(factor out powers of $-1$:)}} \\ | |
&=(-1)^n \frac{1}{n+1} \sum_{k=0}^n (k+1) \binom{-n-1}{n-k} \\ | |
& \color{gray}{\text{(substitute $j=n-k$:)}} \\ | |
&=(-1)^n \frac{1}{n+1} \sum_{j=0}^n (n+1-j) \binom{-n-1}{j} | |
\end{align}</span></p> | |
<p>The <code>~cŻ</code> generates the negative binomials <span class=""math-container"">\$\binom{-n-1}{0}\$</span> through <span class=""math-container"">\$\binom{-n-1}{n}\$</span>.</p> | |
<p>Then we use an obscure trick: we can calculate <span class=""math-container"">\$\sum_{j=0}^n (n+1-j) \cdot z_j\$</span> as <code>sum(cumsum(z))</code>, or <code>ÄS</code> in Jelly parlance. But then because we want to divide by <span class=""math-container"">\$n+1\$</span> immediately after, and our list has <span class=""math-container"">\$n+1\$</span> elements, we can write <code>Æm</code> (mean) instead of <code>S</code> (sum).</p> | |
<p>Here's an example of why this works: | |
<span class=""math-container"">\begin{align} | |
& \textrm{sum}(\textrm{cumsum}([a,b,c,d])) \\ =~& (a) + (a+b) + (a+b+c) + (a+b+c+d) \\ =~& 4a+3b+2c+d | |
\end{align}</span></p> | |
<p>Finally we still have to multiply by <span class=""math-container"">\$(-1)^n\$</span> to fix the sign. But because we know the Fine numbers are never negative, we can just take the absolute value with <code>A</code>.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>Œɠ>2i1œPŒgFµÐL | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opJML7IwyDY9ODjg6Kd3t0NbDE3z@uxxuf7ijRzPy/39DHQVjQ0MjIyNDYx0FExNTEDAxMTHTUTA0BorCsSFQoSGIMDe3sLS0tLAwNwcA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input as a list of digits, outputs as a list. Outputs <code>[]</code> if the result is empty. The TIO footer converts to/from numbers to lists (and converts <code>[]</code> to <code>0</code>)</p> | |
<h2>How it works</h2> | |
<pre><code>Œɠ>2i1œPŒgFµÐL - Main link. Takes a list of digits D on the left | |
µÐL - Until a fixed point is reached, do the following: | |
Œɠ - Run lengths of equal adjacent elements | |
>2 - Greater than 2? | |
i1 - Find the first truthy index, i | |
Œg - Group equal adjacent elements | |
œP - Split, removing the element at the index i | |
F - Flatten | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>12</s> 11 bytes</h1> | |
<pre><code>ḤrcµJNÐeḋ:L | |
</code></pre> | |
<p><a href=""https://tio.run/##ASUA2v9qZWxsef//4bikcmPCtUpOw5Bl4biLOkz/xbvDh@KCrFn//zEw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of emanresu A's golf to <a href=""https://codegolf.stackexchange.com/a/258124/85334"">mathcat's Vyxal solution</a>.</p> | |
<pre><code>Ḥrc Each of [2n .. n] choose n. | |
µ ḋ Take the dot product of that with | |
J [1 .. n+1] | |
NÐe with every other element negated, | |
: and (floor) divide that by | |
µ L n+1. | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 18 bytes</h1> | |
<pre><code>o2µḤœcµṬ-*ÄAƑ×ṂḂ)S | |
</code></pre> | |
<p><a href=""https://tio.run/##ATQAy/9qZWxsef//bzLCteG4pMWTY8K14bmsLSrDhEHGkcOX4bmC4biCKVP/xbvDh@KCrFn//zEw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Haven't actually tried any closed form or recursive formulae, but ignoring the special case fix for <span class=""math-container"">\$n=0\$</span> this brute-force enumeration feels elegant enough to post, <s>especially considering how the current golflang closed form solutions are</s>. Leverages the "even number of leading up-steps" interpretation--or rather, "first down-step at an odd 1-index", hence the special case.</p> | |
<pre><code>o2µ If n is 0, from here on out, pretend it's 2. | |
œc Get every combination of n elements from | |
Ḥ [1 .. 2n], | |
µ ) then for each combination: | |
Ṭ-* Produce a list of -1 at those indices and 1 elsewhere, | |
Ä take its cumulative sums, | |
AƑ and check that none of those is negative. | |
× Multiply that result by | |
Ṃ the smallest element of the combination. | |
Ḃ S How many are odd? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 30 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>A lot of bytes, and extra computation, to effectively break on the first found solution :(</sup></p> | |
<pre><code>×Ṛ_+⁸ṪṠ | |
ŒRṗ2çⱮS¬ȧẠƲ¥Ƈ | |
1ç1#Ṫç⁸Ḣ | |
</code></pre> | |
<p>A monadic Link that accepts a list of the coordinates that yields a pair of integers, <span class=""math-container"">\$[m, b]\$</span>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///w9Ic7Z8VrP2rc8XDnqoc7F3AdnRT0cOd0o8PLH21cF3xozYnlD3ctOLbp0NJj7VyGh5cbKgOVAeWAyncs@v//f7SGgY6Bpo6GIZCMBQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>×Ṛ_+⁸ṪṠ - Link 1 side of the line: L=[m, b]; P=[x, y] | |
× - (L) multiply (P) -> [mx, by] | |
Ṛ - reverse (that) -> [by, mx] | |
_ - subtract (P) -> [by-x, mx-y] | |
⁸ - chain's left argument = L | |
+ - add -> [by-x+m, mx-y+b] | |
Ṫ - tail -> mx-y+b = (mx+b)-y | |
Ṡ - sign -> 1 (below), 0 (on), or -1 (above) | |
ŒRṗ2çⱮS¬ȧẠƲ¥Ƈ - Link 2 find solutions: integer k, coordinates C | |
ŒR - span-range -> [-abs(k)..abs(k)] | |
ṗ2 - second Cartesian power -> all [m,b] using values from -k to k | |
Ƈ - filter keep those for which: | |
¥ - last two links as a dyad - f(L=[m,b], C) | |
Ɱ - map (across each coordinate pair, P, in C) with: | |
ç - call Link 1 - f(L, P) -> side of the line | |
Ʋ - last four links as a monad - f(A=that): | |
S - sum (A) | |
¬ - logical NOT (that) | |
Ạ - all (A)? | |
ȧ - logical AND | |
1ç1#Ṫç⁸Ḣ - Link: coordinates C | |
1 - set the left argument to one | |
1# - find the first one integers, k (incrementing), for which: | |
ç - call Link 2 - f(k, C) -> empty lists are falsey | |
Ṫ - tail -> get the k value found | |
⁸ - chain's left argument = C | |
ç - call Link 2 - f(found k, C) | |
Ḣ - head (that) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>1bŻĠṫʋ# | |
</code></pre> | |
<p>A dyadic Link that accepts the base on the left and the number of pan-digital numbers to find on the right and yields a list.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/98w6ejuIwse7lx9qlv5////Jv8NDQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>1bŻĠṫʋ# - Link: integer, B; integer, N | |
1 - set the left argument to one (k=1) | |
# - increment (k), yielding the first (N) for which: | |
ʋ - last four links as a dyad - f(k, B): e.g. k=23, B=3 | |
b - convert (k) to base (B) [2,1,2] | |
Ż - prefix with a zero [0,2,1,2] | |
Ġ - group indices by their values - [[1],[3],[2,4]] | |
ṫ - tail (that) from index (B) - [[2,4]] | |
- (the empty list is falsey, other lists are truthy) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>>“Þœ&08PXp“¤‘§ḂS‘²Ḥ | |
</code></pre> | |
<p>A monadic Link that accepts an integer from <span class=""math-container"">\$[1,118]\$</span> and yields the rule, <span class=""math-container"">\$2\$</span>, <span class=""math-container"">\$8\$</span>, or <span class=""math-container"">\$18\$</span>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/uUcOcw/OOTlYzsAiIKAByDi151DDj0PKHO5qCQYxND3cs@X@4/VHTmv//DQ0tAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>>“...“¤‘§ḂS‘²Ḥ - Link: Atomic number, A e.g. 48 | |
“...“¤‘ - lists of code-page indices -> [[20,30,38,48,56,80,88,112],[3]] | |
> - (A) greater than? (that) [[ 1, 1, 1, 0, 0, 0, 0, 0],[1]] | |
§ - sums [3,1] | |
Ḃ - mod two [1,1] | |
S - sum 2 | |
‘ - increment 3 | |
² - square 9 | |
Ḥ - double 18 | |
</code></pre> | |
" | |
"114446","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>İCP÷@ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///IBueAw9sd/h9erq8Z@f9/dLSxjoKJjoJZrI6CoQGQiI42AjFNwEyQqDFEFKjGGMgwgvBMdRQsdBTMgWxLiB4gA2yORSxIGAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of Sean's Raku answer.</p> | |
<h4>Explanation</h4> | |
<pre class=""lang-python prettyprint-override""><code>İCP÷@ # Implicit input | |
İ # Reciprocal (1 / z) | |
C # Complement (1 - z) | |
P # Product | |
÷@ # Divide | |
# Implicit output | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>23</s> <s>20</s> 18 bytes</h1> | |
<pre><code>œ-œlLɗÐƤ€ØDoṚ$ż"¹Ġ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///oZN2jk3N8Tk4/POHYkkdNaw7PcMl/uHOWytE9Sod2Hlnw/3D70UkPd86weLi72x@IHzXMcQ8BEj4gwjXwUcNcHW@g8iwgT8HWTgHI14z8/z86WikxKVlJRwFIVSjF6nBFgxlgfjIaHy6PJg3hGhrA@IYGUAMt4TosK2CKoLoMTcEihmZJUL4Z2BiQMJhvYWoE4ltCZXUMDAyQ@XqofCMDPUNTPUOwFhDbEsTGkDHTs7QEIpgDsg0tIVaWwxRbloMFoB4xhNhQDvWDoZExWNbIOBEioowQUYaIGOuC7THWNYTqgboy0QDON0TjQ@Sh6g0qEkFcgwqYEwziIY4wiDeBCOiDeFpKsbEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes a list of two inputs, and returns <code>[[1], [2]]</code> for LT, <code>[[1, 2]]</code> for EQ, and <code>[[2], [1]]</code> for GT. (The test footer converts these because my brain couldn't handle checking the test cases otherwise.)</p> | |
<p>A band-aid fix to a solution that otherwise always compares digits as greater than non-digits.</p> | |
<pre><code> ÐƤ For every prefix (largest first) of | |
€ each of the inputs, | |
L get the length of | |
œ- the multiset difference of the suffix and | |
œl ɗ ØD the suffix with leading digits removed. | |
o Replace zeroes in either result with | |
Ṛ$ corresponding elements of the other result, | |
ż"¹ then zip each result with the corresponding input. | |
Ġ Group indices, sorted by value. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>3Ḷ+)ÆNḋ-,.,. | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/44Y5t2pqH2/we7ujW1dHT0fv//7@hAQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>This <em>has</em> to be possible in 11 bytes if a hardcoded dot product ties everything else I've come up with...</p> | |
<pre><code>3Ḷ [0, 1, 2] | |
+ plus | |
) each [1 .. n], individually. | |
ÆN Get the x'th prime for each x in that matrix, | |
ḋ then return each row's dot product with | |
-,.,. [-1, 0.5, 0.5]. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>ṢƝQ⁺€FċⱮ=2PṢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzkXH5gY@atz1qGmN25HuRxvX2RoFAAX/H27XjPz/Pzo6Vocr2lDHSMdYxxDCBHGMwEyoFEwFnGmsYwKExiAhuG4gI78gNU9DXS85PyVVryQzX11Tryg1MSUnMy9VQ1OvuKQos0BDPSZPXTMWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Inspired by <a href=""https://codegolf.stackexchange.com/a/257530/85334"">AndrovT's port of my original solution</a>, and come to think of it, basically ports <a href=""https://codegolf.stackexchange.com/revisions/257542/3"">Kevin Cruijssen's solution from before porting that</a>. While Vyxal and 05AB1E have a nice single-byte palindromize builtin, Jelly's is a digraph, and flanking the program with <code>Œ</code> would effectively comment the whole thing out (though it is still nominally <a href=""https://tio.run/##y0rNyan8///opIc7WnSOzQ10O9L9aOM6W5OAo5P@Gx7Zrxn5/390dKwOV7ShjpGOsY4hhAniGIGZUCmYCjjTWMcECI1BQnDdQEZ@QWqehrpecn5Kql5JZr66pl5RamJKTmZeqoamXnFJUWaBhnpMnrpmLAA"" rel=""nofollow noreferrer"">accessible as a function</a>, for the same byte count).</p> | |
<pre><code> Ɲ For each pair of adjacent elements in the input, | |
Ṣ yield it sorted. | |
Q Uniquify the list of pairs | |
⁺ then do it again | |
€ to each pair. | |
Ɱ P For every element of the input, | |
ċ is its number of occurrences in that list | |
F flattened | |
=2 equal to 2? | |
Ṣ Sort the result (no-op). | |
</code></pre> | |
<p>My original solution, for posterity:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>14</s> 13 bytes</h1> | |
<pre><code>¹ŒḄ,ƝQFċⱮ=4P¹ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///QzqOTHu5o0Tk2N9DtSPejjetsTQIO7fx/uF0z8v//6OhYHa5oQx0jHWMdQwgTxDECM6FSMBVwprGOCRAag4TguoGM/ILUPA11veT8lFS9ksx8dU29otTElJzMvFQNTb3ikqLMAg31mDx1zVgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 porting AndrovT's Vyxal answer back</em></p> | |
<pre><code> ŒḄ Palindromize the input, making all adjacencies bidirectional. | |
,ƝQ Find the unique pairs of adjacent elements. | |
Ɱ P For every element of the input, | |
ċ is its number of occurrences in that list | |
F flattened | |
=4 equal to 4? | |
¹ ¹ No-ops. | |
</code></pre> | |
" | |
"59487","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>Ẇḋ`ṫċ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASUA2v9qZWxsef//4bqG4biLYOG5q8SL/@G4isOH4oKsVOKAmP//MTAw"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Ẇḋ`ṫċ – link, we call the argument n | |
Ẇ – all contiguous sublists of [1, ..., n] | |
ḋ – dot product (vectorized) with... | |
` ... itself (` makes a monad from a dyad by repeating the argument) | |
ṫ – discard the first n-1 (for n>1, n^2 ≠ n, so it's ok) | |
ċ – count the occurences of n in this list | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<p>A port of <a href=""https://codegolf.stackexchange.com/a/257442/53748"">ais523's Brachylog answer</a> - do upvote that.</p> | |
<pre><code>ẈƲ¡Ṫ | |
</code></pre> | |
<p>A monadic Link that accepts <span class=""math-container"">\$n\$</span> and yields:</p> | |
<p><span class=""math-container"">$$a(n) = | |
\begin{cases} | |
\lfloor n \log_{10} \rfloor + 1 & \text{if $n$ is a perfect square} \\ | |
n & \text{otherwise} | |
\end{cases}$$</span></p> | |
<p><strong><a href=""https://tio.run/##AR8A4P9qZWxsef//4bqIw4bCssKh4bmq/8OH4oKs//8xMDI1//8xMDI1"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>A byte saved over the naive <code>DL$Ʋ¡</code>.</p> | |
<pre><code>ẈƲ¡Ṫ - Link: integer, n | |
¡ - repeat... | |
Ʋ - ...times: is square? (using integer only arithmetic) | |
Ẉ - ...action: length of each (implicit range [1..n], implicit cast to digits) | |
Ṫ - tail (for the list this is the length of digits of n, otherwise it's just n) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 7 </s> 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-1 thanks to Unrelated String (square after getting sublists of <code>[1..n]</code> avoiding <code>€</code>).</p> | |
<pre><code>Ẇ²ḊƇ§ċ | |
</code></pre> | |
<p>A monadic Link that accepts an integer and yields the count of ways it is partitionable into consecutive (positive) squares (<code>0</code> is falsey while non-zero integers are truthy).</p> | |
<p><strong><a href=""https://tio.run/##ARsA5P9qZWxsef//4bqGwrLhuIrGh8KnxIv///8zNjU"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##ASAA3/9qZWxsef//4bqGwrLhuIrGh8KnxIv/w4figqxU//81MA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Ẇ²ḊƇ§ċ - Link: integer, n | |
Ẇ - all contiguous sublists of [1..n] | |
² - square (vectorises) | |
Ƈ - filter keep those for which: | |
Ḋ - dequeue (i.e. remove the singleton lists) | |
§ - sums | |
ċ - count occurrence of (n) | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>’ḋḂ | |
</code></pre> | |
<p><a href=""https://tio.run/##VZGxDgFBEIZ7T3GthHCzsxOVx/AGGvECuqNR6KgkVKJTkpxQEQ9y@yLLzJ7faeTPv/vNt3Mm4@l0FmMotlW5qspFrG7nx@W1qa6HUOyy7jALxf61HoXF6bkM8/vj2GvHmHeyXM/6rU8iJKeJNDE6r4k1SeoILIElsASWwBJYV7OkiZBcuudq1jpjRZOkjuFleBlehpfhZXh9zbImQnLJ4WvWOmMHmiR1Aq/AK/AKvAKv/O2LVfRhsOvLcaIfHHP879rAlobf2bUcC7vm6L@1qck0Bub2zKT77eAMIDug5r8h38qn3zTiDQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>’ Decrement each number, | |
Ḃ and take each number mod 2. | |
ḋ Return the dot product of both vectors of results. | |
</code></pre> | |
" | |
"114446","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>BṙRḄṂ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/p4c6ZQQ93tDzc2fT//39Dc3MA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h4>Explanation</h4> | |
<pre class=""lang-python prettyprint-override""><code>BṙRḄṂ # Implicit input (n) | |
B # Convert n into binary | |
ṙ # Rotate this string this many times: | |
R # Each of the numbers in [1..n] | |
# (this will generate some duplicates, but that's fine) | |
Ḅ # Convert each one back from binary | |
Ṃ # Get the minimum of this list | |
# Implicit output | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 121 bytes</h1> | |
<pre><code>“wỴḅKṭḞ2Ṅðȧ¤[Ạ⁺©iṆȦẉ&ŒÐḷ<⁸Ṛ⁵Ƙ#A½Ƈ'¥ṚPċṢSḥSQUmṘẉL>²XɼNĠ¥ṆỊẋi¥@ȯ⁺CḲKSḌȮC²ß5LṂJṁȮr]zƬe§^YVœX<ḃç%ƝṪƬṣ$¹Ṗa?⁵ḤẠÐẈ}ƬỊhR=zḢɱ¿z’œ? | |
</code></pre> | |
<p><a href=""https://tio.run/##PVRbbxw1FP4rK3F7KS9IvBVKsmm3STZhu5NETRBIZ2YPM05m7K3HznZXQmq4tNDygIgEBXGpSkMEKgUiEDsJF2nTRMnP8P6RcI696Yu/z8f25@Nz8Trmef/sbHzrm547@MMNP5p31S9u@N0rrvrw8LeT3dGjt9z@g/HW/ugn4arbJz@6/U9ePPr88DM3/OvieGvoqq/HW38e339uavTP8Z2XRjtkaD2956qHkRvuRNeWC1fdpzPN10d710//Xnz6gLfcdgd33f49Mdp54@RXEq@74d48Hfj05El9tHf4/atNV70/56qtkyf67cHxYxztvrO6crR9/aIbfnC4@8Lxt676@fixq354flS56gu4RE644SNylTzb//g9Wju4m7VfG7jhw9PfR/8Nxre@Otq@dHa0TWcO76yffjne@vdC7exsKra1mQxicaE29W6agRSlAUmTPCYOTFLUEyJQl0RkqnI26BSlEZKpLY2GXJxTJtOQQQGlJxqEZCLTHDpYZsx1DB3Fy0jCtvBEDJBR@t2oC9thocx6l6ZVLja9stISFaMpe8D3T2sYiJzQ5imE260uAljZocfVoUCtlGQmgWXrtDGOEbypX3jMoMOjyNEDS9dVropYeEYPZ6AI1doiYZNGw1ttzJN@V1t6UH2ASabKXG3CBp@bgUwV2CeCsgC9QWRdxMoacutyYikKmkja7xqCvBZBvjmxcbgkeXTZZEJ1WeuKWBc8yrBwRYNMkBFlktUaVvhwNCDmlzYgON6gSIIkBxpZWNaIfIpxItSwUPjRYAGcXJKS@AxfnhZlCZanfS9xFQS7f1XJjtWcZGJpbZ4GolZSEui62QSD@iylADwoiaWnmuNN4w0ez7eVGpCyOGsgp@NzVD4@ynPQ5d1zSncY56Ho2iRj7@ZR9hmU9jPbI7cu1JrAddVEqmAOQxNLZTLKXFPEoZSJ9D1QogzK0iAXXNPexILyoukNC1QiKZQJaOYZ6TPm0BMB@/4VxMLc@InVwoSmWcCbIqEbF5SECVLP@BWlVRJMA07PDUvKi1AIn6lF7ELO0HuWAOZrCCFCixQPDallu6C@nIA/qnQPKGpv@kpuUemFRm5BjiV1KTKVwE3RChq0uYWaktpSQb2ltLEpO9CyqI3iIidPr4HhMLSxa@NcJLUZVQhJjpB4WxXhwW1b@oi0qR@5uSKQtTnLWyKwHUF/BfgHRoky4bIIJfq7IvpVNFCWFPsYkaIPVNT1f0akBeVTbrDF@vRHtgD6bJho6lAq26jH3R9Ue9hB3tQTZoB6Yuz7CC2B6LHAEshB8Hopg8m5pQwp0iYLR8pgaNFHILpdih2V5rmdaohKbEnFwJ/BkvIjVXPZp7YNqpY@0UD0Bvf9chqCsiyFwU4tMtRlJLWsbcjCCoViYJHbbkWg8W9axYLfsWpT@knAf3trILgM1yZdvSaKGOIe/g8"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Boring, but it's not clear what further logic could bring it down. The program is just a giant compressed integer representing a permutation, and a builtin to apply it.</p> | |
" | |
"114446","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>38</s> 36 <a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>75s15Ẋ€ḣ€5Z“ƝM»€3¦€3¦“BINGO”ṭṚK€Y⁷Ṅ) | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/ctNjQ9OGurkdNax7uWAwkTaMeNcw5Ntf30G4gx/jQMijZMMfJ08/d/1HD3Ic71z7cOcsbKB75qHH7w50tmv///zcGAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Most of the credit goes to <em>@cairdcoinheringaahing</em> and <em>@UnrelatedString</em> for helping me <a href=""https://chat.stackexchange.com/rooms/57815/jelly-hypertraining"">in chat</a>.</p> | |
<ul> | |
<li>-2 thanks to UnrelatedString</li> | |
</ul> | |
<p>This can probably be a bit shorter, though.</p> | |
<h4>Explanation</h4> | |
<pre class=""lang-python prettyprint-override""><code>75 # 75 (implicit range) | |
s15 # Split into 15 parts | |
Ẋ€ # Random permutation of each | |
ḣ€5 # First 5 elements of each | |
Z # Transpose | |
“ƝM» # Replace ↓ with "free" | |
€3¦€3¦ # The third item in the third item (1-indexed) | |
“BINGO” # Push "BINGO" | |
ṭṚ # Append and reverse (i.e. prepend) | |
K€ # Join each by spaces | |
Y⁷ # Join by newlines and append a newline | |
Ṅ # Print | |
) # Repeat input number of times | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>⁹p`ạỤ€Ƒ¥ƇOỌ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9R486ChIe7Fj7cveRR05pjEw8tPdbu/3B3z//D7ZqR//9Hq6eYqesoqKeByXRj9VgdBaCYCYgHkUk1h4glG4PVGYHIJCP1WAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Sidesteps actually generating knight moves by just checking them with good old brute force.</p> | |
<pre><code>⁹p` Generate the Cartesian product of [1 .. 256] with itself. | |
⁹p` 256 is Jelly's smallest single byte constant >= 108, | |
O the character code of 'h'. | |
Ƈ Filter that list of pairs to the single one for which | |
ạ ¥ the list of its element-wise absolute differences from each of | |
O the input pairs converted to character codes | |
Ƒ is equal to itself with | |
€ each difference pair | |
Ụ graded up (converted to a list of indices sorted by their values). | |
Ụ Ƒ Every list of length 2 grades up to either [1, 2] or [2, 1]. | |
Ọ Convert the surviving pair from character codes. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>19</s> 15 bytes</h1> | |
<pre><code>ḲḢ€K$}⁵⁼$¡€KɓẊ€ | |
</code></pre> | |
<p><a href=""https://tio.run/##PZA7TsNAEIavMloh0UTcA9HSRSnG9iQ7eL1r7ewmckERSlpOADUVElKEqOg4RnIRsw8LydJ88/r/WT@QMdM8n08f59Pb5en97urxcvy8HL@vfl5z@vty/npOMM@zuoWg2fbAAQbe6QANwehEuDEEwcGAPQFakCbAweM4ks9lNMYd8lLitBGFOjhw0C4GQBCdLriBe41JldBKMknIVgJhB24LGvdsd3nbYLStTgNUPFpnxSVrwlzkgVYwuXhtTLbB5ahktwwPA9pOQILHcv3Wu6FoLS0wbOlGzWslIY7cqRUoiSJTAY1dBfLsopiasFkADba5XpLJp4OpCtCePJqCbdIgu/UUO1KbFaxV47ntc6/BHks0kUrkXQmEvrbTWys0xa/JDumrQwZDciuKgSjoXM2vtMtEcNGzBKlMSxy5reR5dF2tTfK/WwltL2ozpz/4Bw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-4 bytes and fixed thanks to lyxal :P</em></p> | |
<p>Full program taking the text, wordlists, and acronym as successive command line arguments.</p> | |
<pre><code>Ḳ Split the text on spaces | |
ɓẊ€ and shuffle the wordlists. | |
€ For each word in the split text: | |
⁵⁼$¡ If it's equal to the acronym, | |
Ḣ€ } destructively take the head of each wordlist | |
K$ and join the words on spaces. | |
K Join the results on spaces. | |
</code></pre> | |
<p>I might have gotten too caught up earlier in thinking of a vectorization trick for checking if a word (right) matches the acronym as reconstructed from the wordlists (left), which also incorrectly replaces prefixes of the acronym:</p> | |
<pre><code>a Apply vectorized logical AND | |
" to corresponding elements (leaving excess unchanged) of the lists and | |
W€} the word with each letter wrapped in its own list. | |
¥Ƒ Are the wordlists unchanged by this? | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ZQż¹ƙɗ@/ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z8q8OieQzuPzTw53UH//@F270dNayL//69Wcs6pTElVslJQSsopTVXSUVAKTixKzEAWcCtKTQHx04tSU/OUavUyS1JzizU0AQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Input as a list of <code>[key, value]</code> pairs, output as a list of <code>[value, keys]</code> pairs.</p> | |
<pre><code>Z ɗ@/ With the keys on the right and the values on the left: | |
ż Zip | |
Q the unique values with | |
¹ƙ the keys grouped by value, in order of the value's first appearance. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>EÐḟZ$ÐL | |
</code></pre> | |
<p>A monadic Link that accepts a matrix and yields an empty list if possible (falsey) or a non-empty list if not (truthy).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/18ISHO@ZHqRye4PP/cPvRSQ93zvj/PzraUAcCzWJ1uBSizXWMdczhPCMgzwTKiwUA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>EÐḟZ$ÐL - Link: matrix, M | |
ÐL - loop while distinct, applying: | |
$ - last two links as a monad - f(current): | |
Ðḟ - filter discard those for which: | |
E - all equal? | |
Z - transpose | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Employs the team identification trick from <a href=""https://codegolf.stackexchange.com/a/256965/53748"">Arnauld's JavaScript ES6 answer</a>.</p> | |
<pre><code>Ḣ×)ḅ-3SṠ | |
</code></pre> | |
<p>A monadic Link that accepts a list of triples, <code>[team, hits, time]</code> with teams represented as <code>-1</code> and <code>1</code>, and yields the losing team or <code>0</code> for a draw (i.e. <code>-1</code> if <code>1</code> won and vice versa).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjkWHp2s@3NGqaxz8cOeC////R0cb6igY6yiYGcTqKETrAjmWOgoWcI6pjoIJmANkgxQaxMYCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hjkWHp2s@3NGqaxz8cOeC/4fbHzWt@f8/Ojpa11BHwVRHwdDAIFZHIRrIMdJRsDSNjdXhUoBIGgCFwHIgDhAZwxSa6SiYIGkCKkJoMgYaCtcENN4cphBomrEpkmlGpggTzGCKTMAmg00DErEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Ḣ×)ḅ-3SṠ - Link: list of [team, hits, time] triples | |
) - for each triple: | |
Ḣ - head -> removes team and yields it | |
× - multiply by ([hits, time]) -> [team * hits, team * time] | |
ḅ-3 - convert (each) from base -3 -> -3 ** 1 * team * hits + -3 ** 0 * team * time | |
= team * (time - 3 * hits) | |
S - sum | |
Ṡ - sign | |
</code></pre> | |
<hr /> | |
<p>Equivalently, <code>Ḣ×ḅ-3)SṠ</code>.</p> | |
<p>Similarly, <code>Ḣ)ḋḅ-3$Ṡ</code> (using a dot-product).</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>>⁵Ḷ÷¤»⁻A$ị“¢€:“&Ɠ’Ọ | |
</code></pre> | |
<p>A monadic Link that accepts a double precision floating point number and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##ATgAx/9qZWxsef//PuKBteG4tsO3wqTCu@KBu0Ek4buL4oCcwqLigqw64oCcJsaT4oCZ4buM////MC40MQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/uUePWhzu2Hd5@aMmh3Y8adzuqPNzd/ahhzqFFj5rWWAEZascmP2qY@XB3z/@jexwOtwNFvYE48v//aN3MvDQdBV0jAwMdIAHEQI4hEBvomYJYqbrGRsY6CgY6CnCmnoEpiDQEEWCWBZgwQAFGIDFLMAEkgWoN9QyAJFAYaIkCyDYFsMV5iXmxAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>>⁵Ḷ÷¤»⁻A$ị“¢€:“&Ɠ’Ọ - Link: double D | |
¤ - nilad followed by link(s) as a nilad: | |
⁵ - ten | |
Ḷ - lowered range -> [0, 1, 2, ..., 9] | |
÷ - divided by (ten) -> [0, 0,1, 0.2, ..., 0.9] | |
> - (D) greater than (that) (vectorised) -> G | |
$ - last two links as a monad - f(D): | |
A - absolute value (D) | |
⁻ - (D) not equal to (that)? -> K (K = (x<0 or x is nan)?) | |
» - (G) maximum (K) (vectorised) | |
-> L = list with 1 at blue and 0 at white | |
“¢€:“&Ɠ’ - list of base 250 compressed numbers = [128309, 9898] | |
ị - (L) index into (that) (vectorised) | |
Ọ - cast to characters | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>O+€Ø+pḤUƬẎ¤f/Ọ | |
</code></pre> | |
<p>A monadic Link that accepts a list of the three distinct, pairs of characters and yields a list of one pair of characters representing the destination square. When run as a full program the destination is printed.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/99f@1HTmsMztAse7lgSemzNw119h5ak6T/c3fP///9o9WRjdR0F9TQjEJlkpB4LAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>The square on which the knight may fork is the square all three pieces could move to <em>if</em> they were all knights. The code finds those three sets of squares (including off-board ones*) and finds the intersection.</p> | |
<pre><code>O+€Ø+pḤUƬẎ¤f/Ọ - Link: list of lists of characters, C | |
O - cast (C) to ordinals | |
¤ - nilad followed by link(s) as a nilad: | |
Ø+ - [-1, 1] | |
Ḥ - double -> [-2, 2] | |
p - cartesian product -> [[1,2],[1,-2],[-1,2],[-1,-2]] | |
Ƭ - collect while distinct applying: | |
U - reverse each -> [[[1,2],[1,-2],[-1,2],[-1,-2]],[[2,1],[-2,1],[2,-1],[-2,-1]]] | |
Ẏ - tighten -> [[1,2],[1,-2],[-1,2],[-1,-2],[2,1],[-2,1],[2,-1],[-2,-1]] | |
+€ - add to each ordinal pair (vectorises) | |
/ - reduce by: | |
f - filter keep | |
Ọ - cast to characters | |
</code></pre> | |
<hr /> | |
<p><sup>* Even though off-board positions may be present in the three sets I believe that this will yield the single destination square if possible or an empty list if not possible. (The three inputs just need to be distinct!)</sup></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ŒDµẒ¬ṛ¦ⱮJḊċ | |
</code></pre> | |
<p>A monadic Link that accepts a matrix of ones and zeros and yields <code>1</code> if it's a shift matrix or <code>0</code> otherwise.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///oJJdDWx/umnRozcOdsw8te7RxndfDHV1Huv///x8dbaCjAEWxOlwK0YaoXCDDEIzgXAMoNxYA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///oJJdDWx/umnRozcOdsw8te7RxndfDHV1Huv8fbn/UtOb//2iu6GjD2FgdLiBtoKNgCGQpgBgGCDEwDyRsiMQGqUVRZYhDlQF2VRAZJJsNcNiMZiyayWjGIXQbwvxiiGKLIYaJhmg@Qg4DYv0IUxULAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>Constructs all diagonalised representations of shift matrices of the same dimensions as the input and counts occurrences of a diagonalised version of the input.</p> | |
<pre><code>ŒDµẒ¬ṛ¦ⱮJḊċ - Link: matrix of [0,1], M e.g. [[0,1,0],[0,0,1],[0,0,1]] | |
ŒD - diagonals (main first) [[0,0,1],[1,1],[0],[0],[0,0]] | |
µ - start a new monadic chain - f(D=those diagonals) | |
Ẓ - is prime? (D) (used as a zero-all entries function) | |
J - (set the right argument to) range of length (D) | |
Ɱ - map with: | |
¦ - sparse application (to elements of D)... | |
ṛ - ...at indices: right argument (i.e. one of [1..length(D)]) | |
¬ - ...apply: logical NOT (making that single diagonal all ones) | |
Ḋ - dequeue (removing the only non-shift matrix (main diagonal one)) | |
ċ - count occurrences of (D) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 27 </s> 25 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>¬ẆZṡLƊ€Ẏ.ị$€JṖḊƊ¦FS>ʋÐḟẈṀ | |
</code></pre> | |
<p>A dyadic Link that accepts the matrix, <span class=""math-container"">\$M\$</span>, on the left and the maximal toggle count, <span class=""math-container"">\$n\$</span>, on the right and yields the side length of the largest attainable square.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///Qmoe72qIe7lzoc6zrUROQ06f3cHe3CpDp9XDntIc7uo51HVrmFmx3qvvwhIc75j/c1fFwZ8P///@jow11DMAQSMdy6USDGQgunKNjiOCCBKBcQwgHptgQWTEWo6ACyFywUbH/LQE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///Qmoe72qIe7lzoc6zrUROQ06f3cHe3CpDp9XDntIc7uo51HVrmFmx3qvvwhIc75j/c1fFwZ8P/o5Mf7lz8qHHfoW2Htj3cvQWo@tDWhztXhR1e7hAG5ACR5v//BoYGhoYGXAZgmssQRBlwGQKFDAy5gCIgORMuiDQXTBKiEsQ2AKuzACkwQMVcIEPAGMSEaAbThiAuQrMBxCRDiKAhxHSIJRBNUH0GBlDXQVQCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>Toggles all bits of <span class=""math-container"">\$M\$</span> and extracts all possible square sub-matrices. Filters out any which have more than <span class=""math-container"">\$n\$</span> ones in their border, and then gets the length of the longest remaining one (or zero).</p> | |
<pre><code>¬ẆZṡLƊ€Ẏ.ị$€JṖḊƊ¦FS>ʋÐḟẈṀ - Link: list of lists of 1s and 0s; M, integer, n | |
¬ - logical NOT (M) -> toggle all bits of M | |
Ẇ - get all contiguous sublists of rows of that | |
€ - for each (sublist, s, of rows): | |
Ɗ - last three links as a monad - f(s): | |
Z - transpose (s) | |
L - length (s) | |
ṡ - all sublists of (transposed s) of length (length (s)) | |
-> all full height square sub-matrices from s | |
Ẏ - tighten to a list of all square-submatrices | |
Ðḟ - filter discard those for which: | |
ʋ - last four links as a dyad - f(sub-matrix, n) | |
€ ¦ - sparse application... | |
Ɗ - ...to indices: last three links as a monad - f(sub-matrix): | |
J - range of length | |
Ṗ - pop | |
Ḋ - dequeue -> [2,3,...,length-1] | |
$ - ...action: last two links as a monad - f(sub-matrix): | |
. - 0.5 | |
ị - index into (sub-matrix) -> last and first entries | |
F - flatten | |
S - sum | |
> - is greater than (n)? | |
Ẉ - length of each (remaining sub-matrix) | |
Ṁ - maximum (or 0 if empty) | |
</code></pre> | |
<hr /> | |
<p>Note: the second <code>€</code> is necessary, even though all of the test cases pass without it (e.g. <a href=""https://tio.run/##y0rNyan8///Qmoe72qIe7lzoc6zrUROQ06f3cHe3itfDndMe7ug61nVomVuw3anuwxMe7pj/cFfHw50N////j4421DHQMYzl0kFlGMRyxf43AgA"" rel=""nofollow noreferrer"">this</a> should return <code>2</code> not <code>3</code>).</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>Ṭẋ)ST | |
</code></pre> | |
<p><a href=""https://tio.run/##AR4A4f9qZWxsef//4bms4bqLKVNU/8OHxZLhuZgpWf//MTI"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> ) For each x in 1 .. n: | |
Ṭ Create a list containing 1 at index x and 0s before it, | |
ẋ and repeat it x times. | |
S Sum the results element-wise, | |
T and yield the indices of non-zeros in the result. | |
</code></pre> | |
" | |
"106844","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 41 bytes</h1> | |
<pre><code>ØẠẊs5Ḣ | |
“http://i.imgur.com/”;¢;“.png”ṄƲÐḶ | |
</code></pre> | |
<p>How?</p> | |
<pre><code>ØẠẊs5Ḣ : Helper Link | |
ØẠ : Upper and Lowercase Alphabet | |
Ẋ : Shuffle | |
s5 : Split Into Lengths of 5 | |
Ḣ : Head; pop from front of list | |
----------------------------------------------------------------------------------------- | |
“http://i.imgur.com/”;¢;“.png”ṄƲÐḶ : Main Link | |
“http://i.imgur.com/” : String Literal | |
¢ : Previous link as a nilad. | |
“.png” : String Literal | |
; ; : Concat | |
Ṅ : Print with a linefeed | |
Ʋ : Last four links as a monad | |
ÐḶ : Loop; Repeat until the results are no longer unique. | |
</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FjftD894uGvBw11dxaYPdyzietQwJ6OkpMBKXz9TLzM3vbRILzk_V_9Rw1zrQ4usgZJ6BXnpQN7DnS3HNh2e8HDHtiXFScnFUMNghgIA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>Jṗ2r/ị³S=ʋƇḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATUAyv9qZWxsef//SuG5lzJyL@G7i8KzUz3Ki8aH4bii////WzEsMiwzLDQsNSw2LDcsOCw5Xf8xNQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Full program, that takes a list of digits and an integer <span class=""math-container"">\$n\$</span>, and outputs the 1-indexed indices, or <code>0</code> if there's no solution.</p> | |
<h2>How it works</h2> | |
<pre><code>Jṗ2r/ị³S=ʋƇḢ - Main link. Takes a list of digits D on the left, and n on the right | |
J - Indices; [1, 2, ..., len(D)] | |
ṗ2 - Cartesian square | |
ʋƇ - Filter the indices on the dyad f([i, j], n): | |
r/ - Range; [i, i+1, ..., j-1, j] | |
ị³ - Index into D | |
S - Sum | |
= - Does that equal n? | |
Ḣ - Take the first pair, or zero if there's no solution | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒPṬSṠṢƑƲƇ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of positive integers and yields a list of the valid lists of lists for which the union forms a continuous range.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opICHO9cEP9y54OHORccmHtt0rP3/4fajkx7unPH/f3S0kY6CSayOQrSJjoKRMYhhoaNgaABjGIEYlkAGWMrQAKbI0BAoZhIbCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///opICHO9cEP9y54OHORccmHtt0rP2/zuH2o5Me7pzxqGlN1qOGOQq2dgqPGuZqRv7/Hx0dbaijYKSjYBwbq8OlAOYZx@ooRAOFTKBCYCZQyASoECxnoaNgaABjGIEYlkAGWMrQAKbIEGiSoQk2U4G0qY45iDLTsUAoMDSHqIBoN9YxMYJYChE3BZpgCbHMDKQnFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ŒPṬSṠṢƑƲƇ - Link: list of lists of positive integers, A | |
ŒP - powerset (of A) | |
Ƈ - keep those for which: | |
Ʋ - last four links as a monad: | |
Ṭ - untruth - e.g. [[2], [2, 5, 7]] -> [[0, 1], [0, 1, 0, 0, 1, 0, 1]] | |
S - sum (columns of that) -> [0, 2, 0, 0, 1, 0, 1] | |
Ṡ - sign -> [0, 1, 0, 0, 1, 0, 1] | |
Ƒ - is invariant under?: | |
Ṣ - sort -> 0 | |
</code></pre> | |
<hr /> | |
<p>If we may also identify the empty set (as producing a continuous range | |
of zero positive integers) then <span class=""math-container"">\$8\$</span> bytes: <code>ŒPFṬṢƑƊƇ</code> - <a href=""https://tio.run/##y0rNyan8///opAC3hzvXPNy56NjEY13H2v/rHG4/OunhzhmPmtZkPWqYo2Brp/CoYa5m5P//0dHRhjoKRjoKxrGxOlwKYJ5xrI5CNFDIBCoEZgKFTIAKwXIWOgqGBjCGEYhhCWSApQwNYIoMgSYZmmAzFUib6piDKDMdC4QCQ3OICoh2Yx0TI4ilEHFToAmWEMvMQHpiAQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test suite</a>.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>Æṃ'LÞḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9w28Odzeo@h@c93LHo/8PdWw63///vAZTK11Eozy/KSeFC4XgqZJUWlyik55colOQrFCdWKmSW6ChkgJRAVbjn56ckVabq4OUCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>For some reason, Jelly's mode atom insists on vectorising over a list of lines, so we need <code>'</code></p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>10</s> <s>9</s> <s>7</s> 5 bytes</h1> | |
<pre><code>ZḢ«/ƙ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/q4Y5Fh1brH5v5/3C7u2bWo8Z9XFz//0drKPkklmTmKekoKDkqaeooKGgouRWl5iVngEW0oEK@iSVgAScQH1kLUEGsjgKFpjhhGqJFtCnoKhAKnIHGAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> ƙ Group pairs by | |
ZḢ their first elements, | |
ƙ and for each group | |
/ reduce by | |
« recursively vectorizing minimum. | |
</code></pre> | |
<p>The vectorizing minimum leaves the shared subject name unchanged while taking the minimum of the letter grades, and the vectorization mechanism's length mismatch handling adds an asterisk if any of the grades for that subject has an asterisk.</p> | |
" | |
"60693","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 23 bytes</h1> | |
<pre><code>n⁶ŒṪŒ!ạƝ§$ÞḢfœẹ”*$ṭ@Ṃ$’ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/vUeO2o5Me7lx1dJLiw10Lj809tFzl8LyHOxalHZ38cNfORw1ztVQe7lzr8HBnk8qjhpn///@PVlLQ0tVSAAIlHSWFGoUaEAUSUdJRUFKAAqVYAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>This is a monadic link that accepts an array of lines as input and produces a 2D array (which the interpreter prints in the correct format) as output. The solution always starts with the first non-space character, which must be an asterisk.</p> | |
<p>Note that this solution is very slow, so the only valid input that will terminate within a minute on TIO is a 3x3 square. However, this program should work for any input where the non-space characters form a Hamiltonian cycle and the first non-space is an asterisk.</p> | |
<h2>Explanation</h2> | |
<p>List all permutations of the non-space characters' coordinates:</p> | |
<p><code>ŒṪ</code> and <code>Œ!</code> order their results lexicographically (according to the input's order in <code>Œ!</code>'s case), so this step's output is ordered lexicographically.</p> | |
<pre><code>n # Not equal | |
⁶ # " " | |
ŒṪ # Multidimensional indices of truthy values | |
Œ! # Permutations (ordered lexicographically according to the input) | |
</code></pre> | |
<p>Find the valid permutation starting with the first non-space character:</p> | |
<p>Listing all permutations and then finding a valid one is a similar idea to step 4 in <a href=""https://codegolf.stackexchange.com/a/256274/60693"">@KevinCruijssen's answer</a>, although the details are very different.</p> | |
<p>Consider the list of Manhattan distances of adjacent elements of a permutation. (The Manhattan distance from (a, b) to (c, d) is |a-b| + |c-d|). No coordinate is repeated, so each distance is positive. Thus, the lexicographically minimum possible distance list is [1, 1, ..., 1]. This distance list means two adjacent points in the permutation have distance 1, so this permutation is valid or reverse-valid (i.e. the counterclockwise version of a valid permutation). Thus, sorting the permutations by their distance lists puts all of the (reverse-)valid permutations at the beginning.</p> | |
<p><code>Þ</code> is implemented using Python's <code>sorted</code> function, which is guaranteed to be stable, so among the (reverse-)valid permutations, the lexicographically minimum one still comes first. This will be one that starts with the first two non-space characters in order. These characters are the first and second non-space characters on the top row (excluding space-only rows), so the first permutation must be clockwise, making it valid.</p> | |
<pre><code>ạƝ§$ÞḢ | |
ạ # Absolute-value difference | |
Ɲ # Apply to each adjacent pair | |
§ # Sum | |
$ # Group ạƝ§ as a monad | |
Þ # Sort | |
Ḣ # First item | |
</code></pre> | |
<p>Filter non-asterisk coordinates:</p> | |
<pre><code>fœẹ”*$ | |
f # Filter | |
œẹ # Multidimensional indices of | |
”* # "*" | |
$ # Group œẹ”* as a monad | |
</code></pre> | |
<p>Repeat the first coordinate (which is also the minimum coordinate in lexicographic order) and switch to 0-based indexing:</p> | |
<pre><code>ṭ@Ṃ$’ | |
ṭ # Tack | |
@ # Transpose arguments | |
Ṃ # Minimum | |
$ # Group ṭ@Ṃ as a monad | |
’ # Decrement | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>Ẉẹ5ịœc5FQƑ$Ƈ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hro6Hu3aaPtzdfXRysqlb4LGJKsfa/x9u937UtCby//9opbSs/KIUJR0FpbLMpNQKEKM8MaekCsTIq8wtyAAx0kuTs4vBDKAImJGcUZqXDWIkJiWnpEIZIKqiskopFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Outputs the sets of words. <a href=""https://tio.run/##y0rNyan8///hro6Hu3aaPtzd/XDndFO3wGMTVY61/z/c7v2oaU3k///RSmlZ@UUpSjoKSmWZSakVIEZ5Yk5JFYiRV5lbkAFipJcmZxeDGUARMCM5ozQvG8RITEpOSYUyQFRFZZVSLAA"" rel=""nofollow noreferrer"">-1 byte</a> to output all permutations.</p> | |
<h2>How it works</h2> | |
<pre><code>Ẉẹ5ịœc5FQƑ$Ƈ - Main link. Takes a list of words W on the left | |
Ẉ - Lengths of each word | |
ẹ5 - Indexes of 5s | |
ị - Index into W | |
œc5 - All combinations without replacement of 5 words | |
$Ƈ - Filter by the following: | |
F - when flattened... | |
Ƒ - ...the list is unchanged after... | |
Q - ...only keeping unique elements | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 bytes</h1> | |
<pre><code>f€ØcØėṁȯ"Œl⁺i$}¡" | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/tUdOawzOSD884Mv3hzsYT65WOTsp51LgrU6X20EKl/4fbgdKR//8rOeenpCq45@ekKSp4KuTkl6UqwEX0FDxLFDKLFUoyUhWSUotL9JR0FJRCMoAiQJSoUAIUUlSA8VMrEnMLclIV8kpzk1KLFErK8/WUAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Was originally <code>e€ØcÄịØėa@Ʋo⁸O|O&32ƊỌ</code>, but that eventually turned into this with some inspiration from caird's answer.</p> | |
<pre><code> € For each character of the input, | |
f Øc filter it to AEIOUaeiou, producing a mix of empty and length-1 strings. | |
Øėṁ Mold AEIOU to the same shape as that. | |
ȯ" Replace empty strings with corresponding characters from the input. | |
" For each pair of such corresponding elements: | |
Œl lowercase the result | |
¡ if | |
⁺ } the original lowercased (and wrapped in a string) | |
i$ contains the original. | |
</code></pre> | |
" | |
"60693","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>12</s> 10 bytes</h1> | |
<pre><code>Ṃ,ṀƊ×þFɗ/Ṁ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hziadhzsbjnUdnn54n9vJ6fpAzv///6OjDXWMdAxidYC0MZDUNdUxj40FAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-2 from using Ɗ and ɗ for grouping instead of separate lines</em></p> | |
<p>This submission is a monadic link. For input, use a list of the vectors (i.e. <code>[[1,2,0],[1,3],[-5,7]]</code>) as the first argument. This assumes <code>[]</code> is not valid input.</p> | |
<p>This is similar to <a href=""https://codegolf.stackexchange.com/a/256295/60693"">@l4m2's algorithm</a>, but it starts with the first vector instead of <code>(1, 1)</code>.</p> | |
<p>Explanation:</p> | |
<p>This works by taking the (min, max) of the first vector and finding all products of either with elements of the second vector. The same thing happens with the result and the third vector, then that result and the fourth, etc. Then, the answer is the max of the last result.</p> | |
<pre><code>Ṃ,ṀƊ×þFɗ/Ṁ | |
Ṃ # List Minimum | |
, # Pair | |
Ṁ # List Maximum | |
Ɗ # Group the last 3 links ("Ṃ", ",", and "Ṁ") as a monad | |
×þ # Outer product | |
F # Flatten | |
ɗ # Group the last 3 links ("Ṃ,ṀƊ", "×þ", and "F") as a dyad | |
/ # Reduce | |
Ṁ # List Maximum | |
</code></pre> | |
<p>This is my first time using Jelly, so there is probably still room for further golfing.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>ØẠżŒs¤œṣF¥ƒ$ÐLṆ | |
</code></pre> | |
<p><a href=""https://tio.run/##VZU3rizHGYXzuw5tpKq99zarrvbeu5ABlQpUolCApIwhE0qK@PC0j6eNXP1FAgSEAWaCnurfnHO@aou@fz4/v/zl2z//@vXfX3/Yfvn71z9/@/lv4i//@M8Pf/jyJ/3bz99/fvvXT1/@@N/vfkw@PxH54FCGCf0gOEMfPCIUES7nCKKYwxklKPtA7uos7hocoVyf/p48fJ48guauXRFE10E@kNY5i1CEJxa86NqKxFmeGGd3eNpzdPm71oWy3keXCSXImCTPU0eXoKbBYY5vmzxYdxZn6QWpKrJCsPXe39N3Do7iTF9vy2JPqrbg0Hu5DpzlsGc5OMSy9tNXaXapEhHB7oqzLIlva@JTn8/3NzzjOzhyubbCcwqOWOvuBwuF3mdiqXVyXYaIOIuMiNpafD6FZ@1t6Wuk72DPMfQ53jgLDs@Dury75uYYHJvKK01wKE3OsU6Ngeo9b1vTnPtC4SwcEvzdHJOnkILDFsTS26JLrgvoLpsrjlrQdQ27pZMg4qwsiAhdUE4Uy9IcqSSW1d4aYXBoiHSn1sU3rMEY9sESSzaAtyXpq8d3/8Bcrp2@/j6vrIS7wsJmqTIGUISX69zlaHCsiTlqHO2eLlbbO7oCb1NbrdN7rTtwhjNriq7oYvPYfI4zjkYyfIslBW1xpvdPeMLLpUooLo7WTPCL7UooZhs@Tnynr1jqUnxXvTmmb8Lnz8JRLYrvK76dJfb3uxNL7HmIbL5Ygp5bLFW3t@k9aJC@sAiO0jg8k@f2lcaaMAizc6GzsHakCpHTWbSOt2fN5@gOXsvpCZJF1nTp1tQvoTGcKSIyM6k910rjat2q969oWNMAQsHYSnMbA0hnyPVQmv6uNFrn8bm/b@Ep1yMipheefnCAavG9SXDmhuHAZMdcmfAYIWsiRGlkta3DU@9BWzabt4Gj1bbDmTmGp5BwVCwNWapqnA3mKBSqv7dqG8HGnsKMLuglTZ7XmvLRcJYhPDnqLBANif2XOa0Kz0CqIAUZn4en0iBECJjc0fhcKDqooffQruTBi3LQfd5sjs4V246zmNY06r3S6L3aLjYidnyDL@bk4SAlNac0FLk4WwmNwQOxAPYKDqlK5frFEKwTwlNCbMFqptaN0YXZuzK2Y3N0vW31hILZ0Zo2PX1Td4Vz/g5ysuBaWjftrFwPAPjAFH0gzPGAEYI@IOaYZgCQ32FCOMT/DhKy/4aS/yMJYiARWJLMsZBrvUdKI1VE4OKbqm36FqpYhrDOXOvOJLoeX213eIZMpRlJHF039aNrD47oMgYfZ2GkNCKDTvqWFyQEnHtG6XtpnZAIBfPp44FLheJ2lYbJECHi76w4NliswEUZJMQO7VmyZ5Dn5PMZVgnQAINsLGsoPEnOSljpO3WSysXAiy2@bxXOKE2VvuADvbcm011He6aMLm2ltibPpoy0Djw5etvFiELHBEtV9qje1tqz0hgD@3jmGIUnjKA4ix7L9e3b8943mzUVoMOeGAND7KOBx8VyAGaAoTdOUlvIZZxAG210OczXC2z6Fks@R8Q1R7Vd6Q55T99acBZjKDjKXMJSByEH6dfkiS6P2XFTral1pCoCWOCsAdosatuy9Yi2MfA5KGpNCzvC22o7Q95gdhDqjILjquaIoyaMfpVBzNH0VVvg0AEbCo7DlSq5Xj0H3gf@Mgx/HyCnDHz8r0ttveBABKiWPB2gGQaFL3bJQBjS1JpenL3GkHL0TR6pUrytcZY5hsTHtwAjuSsC9wAWLamahpTN/jJ5MFMz83eGQBemkipdbcEd8MumCY5feaaCcgGgMoalXcjfCbA3PKErbzOGFSMi6H0hYV0s@wzGyBSxbHBmz/5vFtN05G3EV5On3RltGWmh0@iCGyvV@8DfAcIs8UrzMh/r/s5bjIETwK/v4daBdnq4VskB00No2RIPXiwR0c3wBOzAXZgbA2aXi9KE7ipBaGHPVRRD@ZOtFOzBBQcNGVr0PjzF8nRXY3i8jc@zXeHSF6RRTA@WzzuIxNMNigBDlzx9Rz5nhDekamjAryPiKGMXATumb2Adlx@eSG1hRqhcMSBaxuCucI26646g5GkMRDHHhpfg4psqd4VUAuvF8gGZ/T08rclSmilnx9FNvE2qoBD5Hw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Outputs <code>1</code> if the picture will fall, and <code>0</code> if not</p> | |
<h2>How it works</h2> | |
<pre><code>ØẠżŒs¤œṣF¥ƒ$ÐLṆ - Main link. Takes a string S on the left | |
$ - Group the previous 2 links into a monad f(S): | |
¤ - Group previous links into a nilad, A: | |
ØẠ - Alphabet; "ABC...XYZabc...xyz" | |
Œs - Swapcase; "abc...xyzABC...XYZ" | |
ż - Zip; ["Aa", "Bb", ..., "Yy", "Zz", "aA", "bB", ..., "yY", "zZ"] | |
¥ - Group previous 2 links into a dyad g(S, p), where p is some pair of letters: | |
œṣ - Split S at this pair | |
F - Flatten | |
ƒ - Reduce the nilad A by g(S, p), initialising with S on the left | |
ÐL - Repeatedly apply f(S) until a fixed point (empty list if fall, non-empty if not) | |
Ṇ - Logical NOT | |
</code></pre> | |
" | |
"78850","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ÆE¹ƇṢU | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wm@uhncfaH@5cFPr//38LYwsLMwMLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A port of my vyxal answer.</p> | |
<h2>Explained</h2> | |
<pre><code>ÆE¹ƇṢU | |
ÆE # Prime exponents of the input - contains 0s | |
¹Ƈ # so filter out those 0s | |
Ṣ # sort the list | |
U # and reverse it | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ỤƑḤ_=JSƊ | |
</code></pre> | |
<p>A monadic Link that accepts a permutation of <code>[1, 2, 3, 4]</code> and yields:</p> | |
<div class=""s-table-container""> | |
<table class=""s-table""> | |
<thead> | |
<tr> | |
<th style=""text-align: center;"">classification</th> | |
<th style=""text-align: center;"">output</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td style=""text-align: center;""><span class=""math-container"">\$e\$</span></td> | |
<td style=""text-align: center;"">-2</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">rest of <span class=""math-container"">\$K_4\$</span></td> | |
<td style=""text-align: center;"">2</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">rest of <span class=""math-container"">\$A_4\$</span></td> | |
<td style=""text-align: center;"">-1</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">rest of <span class=""math-container"">\$S_4\$</span></td> | |
<td style=""text-align: center;"">0</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///h7iXHJj7csSTe1iv4WNf//woQ8D/aWEfBREfBUEfBKBYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see <a href=""https://tio.run/##VVCxDQIxDOyZwgOkceKWBWgprYiKBv0CtDRIdFAxwJcMAKJE/B7/i4QktmURpYidO9/5DvthOJYyv8fpOj/H3XqznS7lc15Oj3q/t/l1LyCnMDMGiAFSAMo5rIC5VrVHtZcDcOrPBmoVdWRDKBiFqt/Ci0qVsa2nlbBRx4owaSXfqCIy1iTFUXLJ6P7QHJEbMGq0QeR2TCTaXsnt2BrJJMkTiH/mbEWy8NDT6VlVq/kH"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">all cases</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ỤƑḤ_=JSƊ - Link: list of integers from [1..4], P | |
Ƒ - is (P) invariant under the application of: | |
Ụ - grade-up -> 1-indexed indices sorted by value | |
Ḥ - double -> X = 2 or 0 | |
Ɗ - last three links as a monad - f(P): | |
J - range of length -> [1,2,3,4] | |
= - (P) equals (that) (vectorises) | |
S - sum -> Y | |
_ - (X) minus (Y) | |
</code></pre> | |
" | |
"110951","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 1 byte</h1> | |
<h5>Program A, 1 byte</h5> | |
<pre><code>Ṇ | |
</code></pre> | |
<h5>Program B, 0 bytes</h5> | |
<pre><code></code></pre> | |
<h5>Outputs</h5> | |
<p>Falsy = accepting; truthy = rejecting</p> | |
<ul> | |
<li><a href=""https://tio.run/##y0rNyan8///hzrb/YBIA"" rel=""nofollow noreferrer"">A inputted into A</a>: <code>0</code> (falsy)</li> | |
<li><a href=""https://tio.run/##y0rNyan8///hzrb///8DAA"" rel=""nofollow noreferrer"">B inputted into A</a>: <code>1</code> (truthy)</li> | |
<li><a href=""https://tio.run/##y0rNyan8DwIPd7YBAA"" rel=""nofollow noreferrer"">A inputted into B</a>: <code>Ṇ</code> (truthy as it is a non-empty string)</li> | |
<li><a href=""https://tio.run/##y0rNyan8DwIA"" rel=""nofollow noreferrer"">B inputted into B</a>: <code> </code> (falsy as it is an empty string)</li> | |
</ul> | |
<h5>Explanation</h5> | |
<ul> | |
<li>The string <code>Ṇ</code> (program A) is truthy as it is a non-empty string</li> | |
<li>The string <code> </code> (program B) is falsy as it is an empty string</li> | |
<li>In Jelly, an empty program just outputs exactly what was input. So program B produces a truthy output when program A is inputted, and a falsy output when it is given itself as input</li> | |
<li>In Jelly, <code>Ṇ</code> is the logical NOT operator. It outputs a falsy output (<code>0</code>) when a truthy input is given, but a truthy output (<code>1</code>) when a falsy input is given. Therefore, it produces a falsy output when given itself as input, and a truthy output when program B is inputted</li> | |
</ul> | |
" | |
"114446","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<h3>Program A, 4 <a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h3> | |
<pre><code>0ŒṘe | |
</code></pre> | |
<h3>Program B, 4 <a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h3> | |
<pre><code>1ŒṘe | |
</code></pre> | |
<h3>Test cases</h3> | |
<ul> | |
<li><a href=""https://tio.run/##y0rNyan8/9/g6KSHO2ek/oezAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Program A, Input A</a></li> | |
<li><a href=""https://tio.run/##y0rNyan8/9/g6KSHO2ek/v//3xDCAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Program A, Input B</a></li> | |
<li><a href=""https://tio.run/##y0rNyan8/9/w6KSHO2ek/v//3wDCAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Program B, Input A</a></li> | |
<li><a href=""https://tio.run/##y0rNyan8/9/w6KSHO2ek/oezAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Program B, Input B</a></li> | |
</ul> | |
<h3>Explanation</h3> | |
<p><code>0ŒṘe</code> checks whether 0 is in the input, and <code>1ŒṘe</code> checks whether 1 is in the input.</p> | |
" | |
"116074","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code><>ƭ"Ạ¥þUSṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/G7thapYe7FhxaenhfaPDDnQ3///@P1jDUUTDV1FHQMNJRsADRZjoKliDaVEfBHESb6CiYacYCAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>The goal is to find the passenger that whose journey overlaps with the most other passengers. The result is that number +1.</p> | |
<pre><code><>ƭ"Ạ¥þUSṀ | |
þU - outer product with itself with reversed elements | |
<>ƭ"Ạ¥ - takes [a, b], [c, d] and returns a<c && b>d | |
S - sum rows | |
Ṁ - maximum | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ĠZṫɗƇ3 | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of characters and yields the filtered list.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///IgqiHO1efnH6s3fj/4Xbv//@j1VNzUnNT80rUdRTUCzLyS/KLM/ILQJz0/PwUEJ2RWFBQCWIk5@fkF6WV5oDYOaXp6YnpqSBmUWpaalFqXjKYU5Kfm19UlF8OYackVqrHAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ĠZṫɗƇ3 - Link: words | |
3 - set the right argument to three | |
Ƈ - filter (words) keeping those for which: | |
ɗ - last three links as a dyad - f(word, 3): | |
Ġ - group indices by value - e.g. "aardvark" -> [[1,2,6],[4],[8],[3,7],[5]] | |
Z - transpose [[1,4,8,3,5],[2,7],[6]] | |
ṫ - tail from index (3) [[6]] | |
- (an empty list is falsey) true (the third "a" gives the 6) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>r/ṖṬ)SṀ | |
</code></pre> | |
<p>A monadic Link that accepts a list of pairs of station numbers for the passengers and yields the minimum seat count.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/79I/@HOaQ93rtEMfriz4f///9EahjoKppo6ChpGOgoWINpMR8ESRJvqKJiDaBMdBTPNWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>r/ṖṬ)SṀ - Link: list of pairs of positive integers, P | |
) - for each (board, alight) in P: | |
/ - reduce by: | |
r - inclusive range -> [board, board+1, ..., alight] | |
Ṗ - pop (the passenger does not need their seat at their destination) | |
Ṭ - untruth - e.g. [3,4,5] -> [0,0,1,1,1] | |
S - sum (the columns of that) | |
Ṁ - maximum | |
</code></pre> | |
" | |
"116074","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>‘r"FĠẈṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw4wiJbcjCx7u6ni4s@H////RhjoKQGQMRLH/o43BLDMgigUA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-2 bytes: Takes start stations and end stations as separate lists.</em></p> | |
<pre><code>‘r"FĠẈṀ | |
‘ - increment | |
r" - vectorized range | |
F - flatten | |
Ġ - group indices by value | |
Ẉ - lengths | |
Ṁ - maximum | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ĠẈ>2ẸµƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///Igoe7OuyMHu7acWjrsfb/h9u9NSP//49WT81JzU3NK1HXUVAvyMgvyS/OyC8AcdLz81PUY3UUotUzEgsKKkFCyfk5@UVppTkgdk5penpieipERVFqWmpRal5yKkimJD83v6govxzCTkmsVI8FAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>ĠẈ>2ẸµƇ - Main link. Takes a list of words L on the left | |
µƇ - Filter L by the following: | |
Ġ - Group the indices of identical letters | |
Ẉ - Length of each group | |
>2 - Greater than 2? | |
Ẹ - Any true? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Œgċ”0ȯƊ€ | |
</code></pre> | |
<p>A full program that accepts a string of digit characters and prints the result.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opPQj3Y8a5hqcWH@s61HTmv///6sbGhmbmBoYGJsZGcCBiYk6AA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Œgċ”0ȯƊ€ - Main Link: list of characters, S | |
Œg - group runs | |
€ - for each group: | |
Ɗ - last three links as a monad - f(group): | |
”0 - literal '0' character | |
ċ - count occurrences | |
ȯ - logical OR (group) | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 13 </s> 11 <a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Jelly has no built-in standard hex string conversion functions :/</sup></p> | |
<pre><code>ØHiⱮ’ṣ-ḅ⁴ḅ⁴ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters (as defined) and yields an integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wDI/MRxvXPWqY@XDnYt2HO1ofNW6BkP///1c3BAIrEKEOAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ØHiⱮ’ṣ-ḅ⁴ḅ⁴ - Link: list of characters, S | |
ØH - hex-characters -> "0123456789ABCDEF" | |
Ɱ - map across c in S with: | |
i - first 1-indexed index of c in the hex-characters or 0 | |
’ - decrement (vectorises) | |
- - literal -1 | |
ṣ - split the ØHiⱮ’ result at -1's (this is what ':' will have mapped to) | |
ḅ⁴ - convert from base sixteen (vectorises) | |
ḅ⁴ - convert from base sixteen | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>Ḥ1,¹ƇƲ¡ | |
</code></pre> | |
<p><a href=""https://tio.run/##AR4A4f9qZWxsef//4bikMSzCucaHxrLCof/Dh8WS4bmY/zc"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-2 bytes thanks to caird coinheringaahing (use STDIN to avoid needing the leading <code>0</code>, and a shorter way of filtering the <code>0</code>)</p> | |
<pre><code>Ḥ1,¹ƇƲ¡ Main Link (input in STDIN, so argument starts at 0) | |
¡ repeat N times | |
Ḥ double the current list | |
1, pair with 1 | |
¹Ƈ filter by identity; remove falsy elements (filter out the 0 in the first step) | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 23 bytes</h1> | |
<pre><code>ØciⱮðḟ0ØėṁŒs>5$}¡"Ɗż@œp | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wjOTMRxvXHd7wcMd8g8Mzjkx/uLPx6KRiO1OV2kMLlY51Hd3jcHRywf/D7Y@a1kT@/6/knJ@SquCen5OmqOCpkJNflqoAF9FT8CxRyCxWKMlIVUhKLS7RU9JRUArJAIoAUaJCCVBIUQHGT61IzC3ISVXIK81NSi1SKCnP11MCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Jelly isn't great at <a href=""/questions/tagged/string"" class=""post-tag"" title=""show questions tagged 'string'"" aria-label=""show questions tagged 'string'"" rel=""tag"" aria-labelledby=""string-container"">string</a> challenges. Full program, as we take advantage of Jelly's smash printing.</p> | |
<h2>How it works</h2> | |
<pre><code>ØciⱮðḟ0ØėṁŒs>5$}¡"Ɗż@œp - Take a string S on the left | |
Øc - Yield "AEIOUaeiou" | |
Ɱ - For each character C in S: | |
i - Get the index of C in "AEIOUaeiou", or 0 if not found | |
ð - Begin new dyadic chain, with vowel indices V on the left and S on the right | |
ḟ0 - Remove zeros from V, call that V' | |
Ɗ - Group the previous 3 links into a monad f(V'): | |
Øė - Uppercase vowels; "AEIOU" | |
ṁ - Repeat to the same length as V' | |
" - For each pair (v, i) with v a vowel and i an index in V': | |
¡ - Repeat: | |
$ - Iteration count: | |
} - Is i... | |
>5 - ...greater than 5? | |
Œs - Action: Swapcase | |
œp - Partition S at the the indices in V | |
ż@ - Zip the partition and the vowels, with reversed @rguments | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>I salvaged a previous blunder so this is now almost certainly beatable!</sup></p> | |
<pre><code>eⱮÐƤƤŒP€}SSÐṂḢ€ị | |
</code></pre> | |
<p>A dyadic Link that accepts the sentence on the left and the pair of words on the right and yields a list of words.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/10cZ1hyccW3JsydFJAY@a1tQGBx@e8HBn08Mdi4C8h7u7/x9e7v3/f1l@fnppXnFBelFlelF@EpD5P1odyMovq1TXUVAHSaUmZicm5aSqxwIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Effectively greedily consumes the longest prefix of the remaining sentence that is a substring of one of the words and then adds that word to the, initially empty, result. The actual implementation analyses every sublist of the sentence and identifies the ends of the words and which one each is and then constructs the result.</p> | |
<pre><code>eⱮÐƤƤŒP€}SSÐṂḢ€ị - Link: Sentence, Words | |
} - using the right argument, Words: | |
€ - for each word: | |
ŒP - powerset -> all substrings of the word | |
Ƥ - for prefixes of Sentence: | |
ÐƤ - for suffixes of that prefix: | |
Ɱ - map across the pair of word substring lists with: | |
e - exists in? | |
S - sum the columns -> list of pairs [n,0] or [0,n] where n is | |
the distance to the next word boundary. | |
ÐṂ - keep those pairs with minimal: | |
S - sum (i.e the [1,0] and [0,1] entries marking ends of words.) | |
Ḣ€ - head each -> 1 if word 1, 0 if word 2 | |
ị - index (1-based and modular) into (Words) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Œue€ØḄ<ƝŻTƲ¦ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lowercase characters and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opNLUR01rDs94uKPF5tjco7tDjm06tOz///9JSYlJiUCUBCJBBBgkJQEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Œue€ØḄ<ƝŻTƲ¦ - Link: list of lowercase characters, S | |
¦ - sparse application (to S)... | |
Ʋ - ...to indices: last four links as a monad - f(S): | |
ØḄ - lowercase consonants | |
€ - for each (character in S): | |
e - exists in? -> 1 if a consonant else 0 | |
Ɲ - for neighbours: | |
< - less than? -> 1 if [0,1] else 0 | |
Ż - prepend a zero | |
T - truthy indices -> indices of consonants directly after a vowel | |
Œu - ...action: convert to uppercase | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>D0ÐoS | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/F4PCE/OD/h9s1I///NzTQUTA0AEJDHQVTEwtLQ1NjCyDTEgx0FIwMTcxNLIzNTMxhYkAAAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Also 5 bytes</p> | |
<pre><code>DŻm2S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/l6O5co@D/h9s1I///NzTQUTA0AEJDHQVTEwtLQ1NjCyDTEgx0FIwMTcxNLIzNTMxhYkAAAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Also also 5 bytes</p> | |
<pre><code>Ds2SṪ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9@l2Cj44c5V/w@3a0b@/29ooKNgaACEhjoKpiYWloamxhZApiUY6CgYGZqYm1gYm5mYw8SAAAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h3>How they work</h3> | |
<pre><code>D0ÐoS - Main link. Takes an integer on the left | |
D - Digits | |
Ðo - To digits in odd positions: | |
0 - Set them to 0 | |
S - Sum | |
</code></pre> | |
<p> | |
<pre><code>DŻm2S - Main link. Takes an integer on the left | |
D - Digits | |
Ż - Prepend a zero | |
m2 - Take every second element | |
S - Sum | |
</code></pre> | |
<p> | |
<pre><code>Ds2SṪ - Main link. Takes an integer on the left | |
D - Digits | |
s2 - Slice into pairs | |
S - Sums | |
Ṫ - Tail | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒPS⁼¥ƇṀŒPFṢ⁼ɗƇṢṪ | |
</code></pre> | |
<p>A monadic Link that accepts a list of integers and yields a list of lists of integers representing the present rows, or the integer <code>0</code> if not possible.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opIDgR417Di091v5wZwOQ5/Zw5yKgwMnpIIFFD3eu@v//f7SpjoKhjoKljoKxjoKJjoIZmA1kGAFRLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ŒPS⁼¥ƇṀŒPFṢ⁼ɗƇṢṪ - Link: list of integers, Widths | |
ŒP - power-set (Widths) (results are ordered by length, ascending) | |
Ṁ - maximum (Widths) | |
Ƈ - filter (the sets) keeping those for which: | |
¥ - last two links as a dyad - f(set, max_width): | |
S - sum (set) | |
⁼ - (that) equals (max_width)? | |
ŒP - power-set (those) | |
Ṣ - sort (Widths) | |
Ƈ - filter (the sets of valid-sum sets) keeping those for which: | |
ɗ - last three links as a dyad - f(set_of_sets, sorted_widths): | |
F - flatten (the set_of_sets) | |
Ṣ - sort (that) | |
⁼ - (that) equals (sorted_widths)? | |
Ṫ - tail | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>1BŒHw/ḂƲ# | |
</code></pre> | |
<p>A full program that accepts an integer, <span class=""math-container"">\$k\$</span>, and prints a Jelly representation of the list of the first <span class=""math-container"">\$k\$</span> entries.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/Q6egkj3L9hzuajm1S/v//v6UJAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>1BŒHw/ḂƲ# - Main Link: integer, k | |
1 # - starting with j=1, count up and yield the first k integers for which: | |
Ʋ - last four links as a monad - f(j): | |
B - binary digits (j) | |
ŒH - split into halves - e.g. [1,0,0,1,1] -> [[1,0,0],[1,1]] | |
/ - reduce by: | |
w - first index of sublist (right) in (left) | |
0 : does not exist | |
1 : at the start -> a "left equals right" number | |
2 : exists but is the second sublist of that length | |
(other outputs not possible as only two sublists of that length exist) | |
Ḃ - modulo two -> 1 if j is a "left equals right" number else 0 | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>1BŒHṛ"Ƒ/Ɗ# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/Q6egkj4c7Zysdm6h/rEv5////liYA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Full program outputting the first <code>k</code> numbers in the sequence given <code>k</code> as a command-line argument. (It's worth noting that the less-fun <code>1BŒHZE€P$Ʋ#</code> is shorter if 0 is included in the sequence.)</p> | |
<pre><code>1 Ɗ# Take the first k integers counting up from 1 which satisfy: | |
B Get the binary digits of the candidate | |
ŒH and split them in half, with the middle going to the left. | |
Ƒ/ Is the left half unchanged by | |
ṛ" replacing its elements with corresponding elements of the right? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>’ßWƊR‘?;` | |
</code></pre> | |
<p>A recursive, monadic Link that accepts a non-negative integer (0-indexed) and yields the nested list. (Replace <code>‘</code> with <code>¹</code> to use 1-indexed input.)</p> | |
<p><strong><a href=""https://tio.run/##ASEA3v9qZWxsef//4oCZw59XxopS4oCYPztg/8OHxZLhuZj//zI"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>’ßWƊR‘?;` - Link: integer, n | |
? - if... | |
‘ - ...condition: increment (i.e. n != -1?) | |
Ɗ - ...then: last three links as a monad - f(n): | |
’ - decrement (n) -> n-1 | |
ß - call this Link with n-1 | |
W - wrap that in a list | |
R - ...else: range (n = -1) -> [] | |
` - use as both arguments of: | |
; - concatenate | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>WŒœ€ẎQƊƬE€Ạ$€¬S | |
</code></pre> | |
<p>A monadic Link that accepts a list and yields the maximal number of uninterleavings required to separate the items (works for more than just two categories).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/86KSjkx81rXm4qy/wWNexNa5g9gIVIHVoTfD/h7u3hAGZh9tBApH//6urq8dwGXIZGoAhhAZThgYgbAiiwQwIE6gcAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>WŒœ€ẎQƊƬE€Ạ$€¬S - Link: list, A | |
W - wrap (A) | |
Ƭ - collect up (starting with that) while distinct applying: | |
Ɗ - last three links as a monad: | |
€ - for each: | |
Œœ - odd-even (e.g. [1,0,1,0,0] -> [[1,1,0],[0,0]]) | |
Ẏ - tighten | |
Q - deduplicate | |
€ - for each: | |
$ - last two links as a monad: | |
€ - for each: | |
E - all equal? | |
Ạ - all? | |
¬ - logical NOT | |
S - sum | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 39 bytes</h1> | |
<p><sup>Maybe there is a clever string replacement or complex number algorithm that'll crush this score?</sup></p> | |
<pre><code>NÑN | |
=ḞḢH‘ɓ+0¦ | |
ṚÇṚ | |
Ṛ1ĿṚ | |
⁹Ŀ | |
O:5%6çƒØ0AṀ«1 | |
</code></pre> | |
<p>A full program which accepts the string and prints <span class=""math-container"">\$0\$</span> (standing at the origin), <span class=""math-container"">\$\frac{1}{2}\$</span> (covering the origin, but laying down), or <span class=""math-container"">\$1\$</span> (neither).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/v8EQ/LtuHO@Y93LHI41HDjJOTtQ0OLeN6uHPW4XYgAWIYHtkPYj1q3HlkP5e/lamq2eHlxyYdnmHg@HBnw6HVhs7///9XCnJz83ELAkInHycQCnLycVMCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Starts at <span class=""math-container"">\$[0,0]\$</span> and executes the string as instructions tracking coordinates of the centre of the block (i.e. executing <code>F</code> would lead to <span class=""math-container"">\$[0,1.5]\$</span>) then inspects the resulting position.</p> | |
<p>Note, right and left are actually mirrored to make the code slightly shorter, so executing <code>R</code> would lead to <span class=""math-container"">\$[-1.5, 0]\$</span>.</p> | |
<pre><code>NÑN - Link 1 (B): [x, y] | |
N - negate | |
Ñ - call the next Link (Link 2) as a monad | |
N - negate | |
=ḞḢH‘ɓ+0¦ - Link 2 (F): [x, y] | |
Ḟ - floor -> [floor(x), floor(y)] | |
= - ([x, y]) equals? (that) (vectorises) | |
Ḣ - head -> x eqauls floor(x)? | |
H - halve | |
‘ - increment -> 1 if rolling or 1.5 if toppling or erecting | |
ɓ - start a new chain with swapped arguments | |
0¦ - apply to index 0 (the y of [x, y]) | |
+ - add | |
ṚÇṚ - Link 3 (L): [x, y] | |
Ṛ - reverse | |
Ç - call the last Link (Link 2) as a monad | |
Ṛ - reverse | |
Ṛ1ĿṚ - Link 4 (R): [x, y] | |
Ṛ - reverse | |
Ŀ - monadic call to Link: | |
1 - 1 | |
Ṛ - reverse | |
⁹Ŀ - Link 5 (call correct function): location [x, y]; instruction N | |
Ŀ - monadic call to Link: | |
⁹ - chain's right argument = N | |
- ...i.e. call Link N with argument [x, y] | |
O:5%6çƒØ0AṀ«1 - Main Link: list of characters, S | |
O - ordinals (S) e.g. "BFLR" ->[66,70,76,82] | |
:5 - integer divide by five ->[13,14,15,16] | |
%6 - mod six ->[ 1, 2, 3, 4] | |
į0 - starting with [x,y]=[0,0] reduce that using: | |
ç - call the last Link (Link 5) as a dyad | |
A - absolute values (that) | |
Ṁ - maximum | |
«1 - minimum of that and one | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>BŒgSḢ=ð#` | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/p6KT04Ic7Ftke3qCc8P//f7P/RgYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Full program taking <code>n</code> and <code>k</code> as successive command line arguments, outputting the first <code>k</code> elements of the sequence for <code>n</code>. A fun 11-byte alternative is <code>BIAS:2‘ð#`</code>.</p> | |
<pre><code> ð#` Count up the first k integers from n, which satisfy, given n: | |
Œg Group runs in the | |
B binary representation of the candidate. | |
S Sum the runs column-wise. | |
Ḣ= Is the first sum equal to n? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ZẆ$⁺€ẎFQL;LN$Ʋ$ÞṪ | |
</code></pre> | |
<p>A monadic Link that accepts the matrix as a list of lists and yields the/a smallest sub-matrix which contains all of the distinct values.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/q4a42lUeNux41rXm4q88t0Mfax0/l2CaVw/Me7lz1////6GgFYx0FENa1BNIGIHYslw5cVMEQKGMBosGiBlA1IGwBkoGrtYBihAkGqKK6lrFcsQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ZẆ$⁺€ẎFQL;LN$Ʋ$ÞṪ - Link: rectangular matrix, M | |
$ - last two links as a monad - f(X=M): | |
Z - transpose | |
Ẇ - all non-empty contiguous sub-lists (includes X itself (transposed)) | |
€ - for each (such "strip" of columns): | |
⁺ - repeat the last link - i.e. f(X=strip) | |
Ẏ - tighten (to a flat list of the sub-matrices) | |
Þ - sort (these submatrices, S) by: | |
$ - last two links as a monad - g(S): | |
F - flatten (S) -> Elements | |
Ʋ - last four links as a monad - g(Elements): | |
Q - deduplicate -> distinct elements | |
L - length -> number of distinct elements | |
$ - last two links as a monad - h(elements): | |
L - length -> total number of elements | |
N - negate -> -1 * total number of elements | |
; - concatenate -> [number of distinct elements, -1 * total number of elements] | |
Ṫ - tail | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>J&’‘rƲị⁸§ | |
</code></pre> | |
<p>A monadic Link that accepts a list of positive integers and yields another.</p> | |
<p><strong><a href=""https://tio.run/##ATIAzf9qZWxsef//SibigJnigJhyxrLhu4vigbjCp////1sxLDIsMyw0LDUsNiw3LDgsOSwxXQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Much like many others, uses the same bitwise trick that <a href=""https://codegolf.stackexchange.com/a/255276/53748"">xnor used</a>.</p> | |
<pre><code>J&’‘rƲị⁸§ - Link: list of positive integers, A | |
J - range of length (A) -> [1..length(A)] | |
Ʋ - last four links as a monad - f(X=that): | |
’ - decrement (X) | |
& - (X) bitwise AND (that) | |
‘ - increment (that) | |
r - inclusive range -> [[startIndexForSum, endIndexForSum] for each element] | |
⁸ - chain's left argument -> A | |
ị - (ranges) index into (A) | |
§ - sums | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 21 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒcżU$œcⱮŻ}y@ƒ€€R{Ṛḟ/Q | |
</code></pre> | |
<p>A dyadic Link that accepts <span class=""math-container"">\$n\$</span> on the left and <span class=""math-container"">\$k\$</span> on the right and yields a list of those permutations of <span class=""math-container"">\$[1,n]\$</span> which require a minimum of <span class=""math-container"">\$k\$</span> pairwise swaps to sort.</p> | |
<p><strong><a href=""https://tio.run/##ATEAzv9qZWxsef//xZJjxbxVJMWTY@KxrsW7fXlAxpLigqzigqxSe@G5muG4ny9R////NP8z"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Starting with the sorted deck the code performs all possible (up to rearrangement) swap sequences of lengths <span class=""math-container"">\$j \leq k\$</span> then takes those reachable with exactly <span class=""math-container"">\$k\$</span> swaps and removes any that were reachable with less.</p> | |
<pre><code>ŒcżU$œcⱮŻ}y@ƒ€€R{Ṛḟ/Q - Link: integer, n; integer, k | |
Œc - unordered pairs (n) (e.g. n=3 -> [[1,2],[1,3],[2,3]]) | |
$ - last two links as a monad - f(x=that): | |
U - reverse each pair | |
ż - (x) zip with (that) -> P = [[[a,b],[b,a]],...]) | |
} - with chain's right argument: | |
Ż - zero range (k) -> [0,1,2,...,k] | |
Ɱ - map (across j in that) with: | |
œc - (P) combinations (j) -> all (ordered) length j pair-tuples | |
{ - with chain's left argument: | |
R - range (n) -> [1,2,3,...n] | |
€ - for each (list of pair-tuples): | |
€ - for each pair-tuple: | |
ƒ - reduce (pair-tuple) starting with (range(n)) using: | |
@ - with swapped arguments: | |
y - translate (e.g. [3,1,2] y [[2,3],[3,2]] -> [2,1,3]) | |
Ṛ - reverse | |
/ - reduce by: | |
ḟ - filter-discard | |
Q - deduplicate | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>19</s> <s>18</s> 17 bytes</h1> | |
<pre><code>Z5ƤẎ5Ƥ€Ẏ;¬$¬Ðe€§Ṃ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/K9NiSh7v6gOSjpjVAhvWhNSqH1hyekArkHlr@cGfT/6OTH@5c/KhxHxfXoa0Pd2x6uGPRw91bbB81zA063K4Z@f9/kDsQcoEIdy4MtoKtnYIBF1AkCMgBC7sDCXcwmwsiAhOFsNxBuiEsoBFQeZBpMHmQwWAlYFGwUWAmWB1YLdROmMkQN0F5YMUwHkihERcXVCgIZg3YXog97mA1hiAfgAAuEqzIaAC8aQkA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 thanks to Jonathan Allan</em></p> | |
<p>Expects a binary matrix. Feels... inelegant.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 20 bytes</h1> | |
<pre><code>ẆZẆ$€ẎØ.p¤œịœ|ƑɗƇṪFS | |
</code></pre> | |
<p><a href=""https://tio.run/##LU5BCsIwEPyMF2GjNklT8wE/4ElDj16kB6@CJw96EATpQR8gCOIHrDdLCz4jfiTONhKymdnNzOxyURTrEHy1m@P2vtuHr471ZbB6X5vSvw5NuWlPn3O798/7ZBrq27A/C8E5Z8iSyEjl5MYkEhKGhAaR3M1QgNHWwDaPeMwjycThW8pMQ8dDvJIkjSKFm8Y8IyaKOsvoD24YQh59LBnOAE5ZreATN9Is6pIzBNsIHaxltzMqyb97kneZCgfwBw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Dyadic link taking <span class=""math-container"">\$M\$</span> on the left and <span class=""math-container"">\$L\$</span> on the right.</p> | |
<pre><code>Ẇ Get all contiguous sublists of the matrix, | |
Ẇ get all contiguous sublists of | |
Z the transpose of | |
$€ each sublist, | |
Ẏ and concatenate into a single list of submatrices. | |
ɗƇ Filter by: | |
œị Multidimensional-index into the submatrix with | |
p the Cartesian product of | |
Ø. [0, 1] | |
¤ with itself; | |
Ƒ is it unchanged by | |
œ| multiset union with L? | |
Ṫ Keep only the largest passing submatrix, | |
FS and flatten and sum it. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 24 23 </s> 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>c×>ɗþḶZæ*-ṪŻN-¦ | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer, <span class=""math-container"">\$n\$</span>, and yields the coefficients in ascending order.</p> | |
<p><strong><a href=""https://tio.run/##ASQA2/9qZWxsef//Y8OXPsmXw77huLZaw6YqLeG5qsW7Ti3Cpv///zU"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>c×>ɗþḶZæ*-ṪŻN-¦ - Link: positive integer, n | |
Ḷ - lowered range (n) -> [0 .. n-1] | |
þ - (i in [1 .. n]) table (j in [0 .. n-1]) with operator: | |
ɗ - last three links as a dyad f(i,j): | |
c - (i) choose (j) | |
> - (i) greater than (j)? | |
× - multiply -> iCj if i>j else 0 | |
Z - transpose | |
- - -1 | |
æ* - matrix power | |
Ṫ - tail | |
Ż - prepend a zero | |
¦ - sparse application... | |
- - ...to indices: -1 (penultimate) | |
N - ...action: negate | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 23 </s> 17 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>-3 by using <code>ṃ</code> - I really should know to use this since I actually implemented this atom! >.<<br /> | |
-1 altering valid move generation code.<br /> | |
-2 compressing in a way so as not to need valid move construction.</sup></p> | |
<pre><code>;N“©Ȯṅ!ı|⁺⁸’ṃs2+\ | |
</code></pre> | |
<p>A monadic Link that accepts the pair <code>[Y, X]</code> and yields a list of coordinates.</p> | |
<p><strong><a href=""https://tio.run/##ATAAz/9qZWxsef//O07igJzCqciu4bmFIcSxfOKBuuKBuOKAmeG5g3MyK1z///9bMiwgMV0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or try it with a <a href=""https://tio.run/##AU8AsP9qZWxsef//O07igJzCqciu4bmFIcSxfOKBuuKBuOKAmeG5g3MyK1z/w4fCqy9DK8aKxZLhuazigqzDlyJKJFN6MFpv4oCdLkf//1s1LDJd"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">formatted output</a>.</p> | |
<h3>How?</h3> | |
<pre><code>;N“©Ȯṅ!ı|⁺⁸’ṃs2+\ - Link: pair of integers, [Y, X] (1 < X < Y) | |
N - negate -> [-Y, -X] | |
; - concatenate -> [-Y, -X, Y, X] | |
“©Ȯṅ!ı|⁺⁸’ - base 250 number = 477042125414097387 | |
ṃ - (that) base decompress ([-Y, -X, Y, X]) | |
-> convert to base 4 using [-Y, -X, Y, X] as digits [1, 2, 3, 0] | |
s2 - split into twos | |
\ - cumulative reduce by: | |
+ - addition (vectorises) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>,ZạƝ€§NŒM | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists and yields a list of all possible minimal cuts, each of which is a pair of numbers, the (1-indexed) index to cut before (an integer, two or greater) and a direction indicator which is <span class=""math-container"">\$1\$</span> if the index is counting rows or <span class=""math-container"">\$2\$</span> if counting columns - e.g. <code>[5,2]</code> means to cut after the fifth column.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/18n6uGuhcfmPmpac2i539FJvv8Ptx@d9HDnjP//o6MVLHQUFAyB2EhHQdc4lksnWsEMyALxzIHYBCSiC5TXBYlaAtUB1cQCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>,ZạƝ€§NŒM - Link: list of lists, M | |
Z - transpose (M) | |
, - (M) paired with (that) | |
€ - for each: | |
Ɲ - for neighbours: | |
ạ - (left) absolute difference (right) (vectorises) | |
§ - sums (vectorises at depth 1) | |
N - negate | |
ŒM - maximal multi-dimensional indices | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>_ⱮṂ‘PḤ_SƲ€S;ṂÄ | |
</code></pre> | |
<p>A monadic Link that accepts a list of two integers, the base dimensions, and yields a pair of integers, <code>[dark, white]</code>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/@0cZ1D3c2PWqYEfBwx5L44GObHjWtCbYGCh1u@f//f7ShgY6hQSwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<hr /> | |
<h2>16 bytes</h2> | |
<p><sup><s> Probably </s> beatable with a constructive method, but I like it.</sup></p> | |
<pre><code>Ṃð‘c3×4+²×IAʋ;⁸Ä | |
</code></pre> | |
<p>A monadic Link that accepts a list of two integers, the base dimensions, and yields a pair of integers, <code>[dark, white]</code>.</p> | |
<p><strong><a href=""https://tio.run/##AS0A0v9qZWxsef//4bmCw7DigJhjM8OXNCvCssOXSUHKizvigbjDhP///1sxMCwxMF0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ṃð‘c3×4+²×IAʋ;⁸Ä - Link: Dimensions | |
Ṃ - minimum (Dimensions) | |
ð - start a new dyadic chain - f(M=that, Dimensions) | |
‘ - increment (M) | |
c3 - choose three -> (M-1)th triangular pyramidal number | |
×4 - times four (call this Q) | |
ʋ - last four links as a dyad - f(M, Dimensions): | |
² - square (M) | |
I - forward differences (Dimensions) -> [Height-Width] | |
× - multiply -> [M*M*(Height-Width)] | |
A - absolute value -> [M*M*|Height-Width|] | |
+ - (Q) add (that) -> [dark piece count] | |
⁸ - chain's left argument -> M | |
; - (dark piece count) concatenate (M) -> [dark piece count, M] | |
Ä - cumulative sums -> [dark piece count, white piece count] | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 39 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ỊTḤ>þ“©©©Çð ‘S+Ɗạþ`Ff“£µ¿‘ | |
17Ż%⁵⁵;ẊÇ¿ | |
</code></pre> | |
<p>A niladic Link that yields a flat list of the tokens to be placed in row-major order.</p> | |
<p>The mapping from question values to the outputted tokens is:</p> | |
<pre><code>Catan (Question): 2 3 4 5 6 8 9 10 11 12 . | |
Token (code): 9 3 4 5 0 1 2 6 7 8 10 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///h7q6QhzuW2B3e96hhzqGVIHi4/fAGBQWFRw0zgrWPdT3ctfDwvgS3NJD04kNbD@0HinMZmh/drfqocSsQWT/c1XW4/dD@//8B"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> Or see a <strong><a href=""https://tio.run/##y0rNyan8///h7q6QhzuW2B3e96hhzqGVIHi4/fAGBQWFRw0zgrWPdT3ctfDwvgS3NJD04kNbD@0HinMZmh/drfqocSsQWT/c1XW4/dD@/4cWPdzdDVRlYWlsYuro5GykZ/aoYS5I29JD6w63HZ4O1Hh08sOd07wfNa2xdlB61Lg34NB@l4e7uh0eNW47tCTyPwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">formatted version</a></strong> (translates tokens to Catan values and pretty-prints as a hexagon).</p> | |
<p>(Also <a href=""https://tio.run/##y0rNyan8///h7q6QhzuW2B3e96hhzqGVIHi4/fAGBQWFRw0zgrWPdT3ctfDwvgS3NJD04kNbD@0HinMZmh/drfqocSsQWT/c1XW4/dD@/4cWPdzdDVRloQcDZo8a5oK0LT207nDb4elAjUcnP9w5zftR0xprB6VHjXsDDu13ebir2@FR47ZDSyL/AwA"" rel=""noreferrer"">here</a> is version that only prints the sixes and eights.)</p> | |
<h3>How?</h3> | |
<pre><code>ỊTḤ>þ“©©©Çð ‘S+Ɗạþ`Ff“£µ¿‘ - Helper Link, is invalid?: list of tokens | |
Ị - insignificant? (abs(x)<=1 - i.e. is Catan 6 or 8?) (vectorises) | |
T - truthy, 1-indexed indices | |
Ḥ - double (vectorises) | |
Ɗ - last three links as a monad f(X=that): | |
“©©©Çð ‘ - code-page indices = [6,6,6,14,24,32,32,32] | |
þ - (X) table with (that) using: | |
> - greater than? | |
S - (column-wise) sum | |
+ - add (X) (vectorises) | |
` - use (that) as both arguments of: | |
þ - table using: | |
ạ - absolute difference | |
F - flatten | |
“£µ¿‘ - code-page indices = [2,9,11] | |
f - filter keep | |
-> nonempty list (truthy) if invalid | |
empty list (falsey) if valid | |
17Ż%⁵⁵;ẊÇ¿ - Link, get random Catan Distribution: no arguments | |
17 - seventeen | |
Ż - zero range -> [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] | |
⁵ - ten | |
% - modulo -> [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7] | |
⁵ - ten | |
; - concatenate -> [10,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7] | |
¿ - while... | |
Ç - ...condition: call the Helper Link (above) | |
Ẋ - ...action: shuffle | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>1DS=ÆdƲ# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/QJdj2cFvKsU3KQLYBAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <span class=""math-container"">\$n\$</span> on STDIN, and outputs the first <span class=""math-container"">\$n\$</span> values.</p> | |
<h2>How it works</h2> | |
<pre><code>1DS=ÆdƲ# - Main link. Takes no arguments | |
Ʋ - Group the previous 4 links into a monad f(k): | |
D - Digits of k | |
S - Sum | |
Æd - Divisor count of k | |
= - Are they equal? | |
1 # - Read n from STDIN and find the first n k≥1 such that f(k) is true | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ÆfÆC߀;¹? | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9wW9rhNufD8x81rbE@tNP@v87h9qOTHu6coZL1qGGOgq2dwqOGuZqR//9HG@ooGOkoGOsomOgomOoomOkoGBoAMVDAyBTINzczjQUA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>A monadic Link that accepts a positive integer and yields a ragged list of ones - that is, a list of <code>1</code>s where inner nesting is the prime counting and adjacency is multiplication.</p> | |
<hr /> | |
<p>A full program that prints that without the outer <code>[]</code> is <span class=""math-container"">\$15\$</span> bytes:</p> | |
<pre><code>ÆfÆC߀;¹? | |
ÇŒṘṖḊ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9wW9rhNufD8x81rbE@tNOe63D70UkPd854uHPawx1d/3UOt2c9apijYGun8Khhrmbk///RhjoKRjoKxjoKJjoKpjoKZjoKhgZADBQwMgXyzc1MYwE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ÆfÆC߀;¹? - Helper Link: positive integer, I | |
Æf - prime factors | |
ÆC - number of primes up to (vectorises across that) | |
? - if... | |
¹ - ...condition: no-op | |
߀ - ...then: call this Link for each | |
; - ...else: concatenate (I) - N.B. Only 1 has no prime factors, so concatenate 1. | |
ÇŒṘṖḊ - Main Link: positive integer, I | |
Ç - call the Helper Link (with I) | |
ŒṘ - get the Python representation (of that) | |
Ṗ - pop | |
Ḋ - dequeue | |
- implicit print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>Œ!cþþ`ẎṠ | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer and yields a list of the binary matrices.</p> | |
<p><strong><a href=""https://tio.run/##ASgA1/9qZWxsef//xZIhY8O@w75g4bqO4bmg/8OHR@KCrGrigb7CtsK2//8y"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>We can first arrange the set of <span class=""math-container"">\$N\$</span> <em>sorted</em> rows any way we like leading to <span class=""math-container"">\$N!\$</span> matrices with sorted rows. Each of these matrices will have column sums from <span class=""math-container"">\$1\$</span> through to <span class=""math-container"">\$N\$</span> <em>in order</em>, so all column-wise permutations will be distinct, so there are <span class=""math-container"">\$N!^2\$</span> such matrices.</p> | |
<p>We can create these matrices by noting that each number in the set <span class=""math-container"">\$[1,N]\$</span> is greater than or equal to exactly <span class=""math-container"">\$N\$</span> of the elements in the set (including itself).</p> | |
<p>Thus a table of <span class=""math-container"">\$\geq\$</span> between two permutations of the first <span class=""math-container"">\$N\$</span> natural numbers is such a table, e.g.:</p> | |
<div class=""s-table-container""> | |
<table class=""s-table""> | |
<thead> | |
<tr> | |
<th style=""text-align: center;""><span class=""math-container"">\$\geq\$</span></th> | |
<th style=""text-align: center;"">1</th> | |
<th style=""text-align: center;"">3</th> | |
<th style=""text-align: center;"">2</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td style=""text-align: center;"">3</td> | |
<td style=""text-align: center;"">0</td> | |
<td style=""text-align: center;"">1</td> | |
<td style=""text-align: center;"">0</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">2</td> | |
<td style=""text-align: center;"">0</td> | |
<td style=""text-align: center;"">1</td> | |
<td style=""text-align: center;"">1</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">1</td> | |
<td style=""text-align: center;"">1</td> | |
<td style=""text-align: center;"">1</td> | |
<td style=""text-align: center;"">1</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
<p>Where one permutation defines the column sums (directly - i.e. <span class=""math-container"">\$\{1,3,2\}\$</span>, above) and the other defines the row sums (in reverse order - i.e. <span class=""math-container"">\$\{3,2,1\}\$</span>, above, defines the sums <span class=""math-container"">\$\{1,2,3\}\$</span>)</p> | |
<pre><code>Œ!cþþ`ẎṠ - Link: integer, N | |
Œ! - all permutations (of [1..N]) | |
` - use as both arguments of: | |
þ - table of: | |
þ - table of: | |
c - n-choose-k (a golf to get a positive integer when n>=k else 0) | |
Ẏ - tighten to a list of the sub-tables | |
Ṡ - sign (convert the positives to ones) | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>>€ḶŒ!Z€Œ!€Ẏ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/uUdOahzu2HZ2kGAVkASkQf1ff////jQE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of my Vyxal.</p> | |
<pre><code> € # Over each of... | |
# implicit range(1, n+1) | |
> # Are they greater than... | |
Ḷ # range(0, n) | |
Œ! # Permutations | |
Z€ # Transpose each | |
Œ!€ # Permutations of each | |
Ẏ # Flatten by one level | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 20 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒṖẈṀ’ỊƲƇV<26Ạ$ƇṪ‘ịØa | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##AUAAv/9qZWxsef//xZLhuZbhuojhuYDigJnhu4rGssaHVjwyNuG6oCTGh@G5quKAmOG7i8OYYf///ycwMzAxMDIyMjIn"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##FYo9CsJAEIX7OUUKS4ud/Z0F9RiCpYVNyAXsFpuIdhYSQcFarIJNkjKYe8xeZF2L9z2@xyt3VbVP6Xvh7sr9kbsQw42H09RO9XohLffP2VRz94qh4eE8NtvEw2c@1mUM92K5KmJ4TG08vDcpoZIeCZzXiGC9yQ4kBEoDRglPDlBr0gReIRnwUpK2gOSEs2C1U/koACGXzLtUIP7IEX9o8wM"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 18 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒlfØa,Ṣ$ | |
Ç⁼"Ç}</ðƇ | |
</code></pre> | |
<p>A dyadic Link that accepts the list of potentials on the left and the identity on the right and yields the filtered list.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opJy0wzMSdR7uXKTCdbj9UeMepcPttTb6hzcca/9/eLm2/qOmNUcnPdw54///aHXvovySRHUdBXXf/LzixGwgD8QJKcrPTizOzc8D87yD/EMcg339/UCc4MTcfAVvPQWgkjywJMiAYgWgdvXY/1AeUKM6AA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ŒlfØa,Ṣ$ - Helper Link: list of characters, Name | |
Œl - lower case (Name) | |
Øa - "a-z" | |
f - (lowered Name) filter keep ("a-z") | |
$ - last two links as a monad - f(X=that): | |
Ṣ - sort (X) | |
, - (X) pair with (that) | |
Ç⁼"Ç}</ðƇ - Main Link: Potentials; Identity | |
Ƈ - keep Potentials, P, for which: | |
ð - dyadic chain - f(P, Identity): | |
Ç - call Helper with Name=P | |
Ç} - call Helper with Name=Identity | |
" - zip with: | |
⁼ - equal? | |
/ - reduce by: | |
< - less than? | |
i.e. alphas(lowered(P)) == alphas(lowered(Identity)) | |
less than? | |
sorted(alphas(lowered(P))) == sorted(alphas(lowered(Identity))) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 23 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<p><sup>No built-in palindromising :(</sup></p> | |
<pre><code>;ⱮṚḊ$ƤŒḂƇḢȯ | |
ŻḊƤÇ⁼¥Ƈ⁸ḢṚÇ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/60cZ1D3fOerijS@XYkqOTHu5oOtb@cMeiE@u5ju4GCh5bcrj9UeOeQ0uPAakdQAmg2sPt////d3ZydHIGEwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##TY@xDoJADIb3PgWDow4Ho4kJ8BSOhSDBOLG5qQuJo6PRxeBmNBoHjE4SL77G3Ytge6iw9P/79dL@N44mk2lV9fX5qG5rVSw7Mn@tVLGQmSp27xO87gRlXmZ6/njuJUlBA3pbZpW6X7tlNtazjdUbWHq2lRe9OAyrOElxhGkSMzaGAfwd4/8bSDGMQkwZslIHrue53JN4HrAD5IqARi0kFxgbYECwnhIVtuM4tuDWGG5BCFsYRGLTcve7nR34VHxTmNXOb77QpP4FNekAOAuHgNbZ@lJ9obX4Aw"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>;ⱮṚḊ$ƤŒḂƇḢȯ - Helper Link: get shortest palindrome: left palindromic prefix, S | |
Ƥ - for prefixes (of S): | |
$ - last two links as a monad: | |
Ṛ - reverse | |
Ḋ - dequeue | |
Ɱ - (S) map (that) with: | |
; - concatenate | |
Ƈ - keep those for which: | |
ŒḂ - is palindrome? | |
Ḣ - head (Note: when S='' we head [] and get zero) | |
ȯ - (that) logical OR (S) (deal with that zero) | |
ŻḊƤÇ⁼¥Ƈ⁸ḢṚÇ - Main Link: palindrome, P | |
Ż - prepend a zero | |
Ƥ - for prefixes (of that): | |
Ḋ - dequeue | |
Ƈ - keep those for which: | |
¥ ⁸ - last two links as a monad - f(X=that, P): | |
Ç - call Helper (X) | |
⁼ - equals (P)? | |
Ḣ - head | |
Ṛ - reverse | |
Ç - call Helper | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ṣ⁼ÞOṂḂṾƲṪ | |
</code></pre> | |
<p>A monadic Link that accepts a list of three characters as specified and yields the resulting character.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hzkWPGvccnuf/cGfTwx1ND3fuO7bp4c5V/x/u3qJzuD3rUcMcBVs7hUcNc49tetS0JvL/f0dtQy4nbSeuIG0DLkMg2wBIG@gZcAXqBQJpRy5DPWcgNgQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Note that <code>+</code> and <code>.</code> are less than all other possible characters and that their ordinals are odd (<span class=""math-container"">\$43\$</span>) and even (<span class=""math-container"">\$46\$</span>), respectively. Also, variables always have ordinals greater than either <code>0</code> or <code>1</code>.</p> | |
<pre><code>Ṣ⁼ÞOṂḂṾƲṪ - Link: list of characters, S = [a, o, b] | |
Ṣ - sort (S) -> [o, min(a,b), max(a,b)] | |
... this places a variable, if present, on the right | |
Ʋ - last four links as a monad - f(S): | |
O - ordinals | |
Ṃ - minimum -> 43 (o='+') or 46 (o='.') | |
Ḃ - mod two -> 1 or 0 | |
Ṿ - uneval -> '1' or '0' | |
Þ - sort (the sorted S) by: | |
⁼ - equals ('1' or '0') | |
... i.e. for o='+' (OR) place any '0's at the right | |
or for o='.' (AND) place any '1's at the right | |
Ṫ - tail ...get the right-most | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 <a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>rCm2ĖṠÞĖF€%o | |
</code></pre> | |
<p>A monadic Link that accepts an odd, positive integer and yields a list of triples.</p> | |
<p><strong><a href=""https://tio.run/##AR4A4f9qZWxsef//ckNtMsSW4bmgw57Elkbigqwlb////zU"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>Or see a <a href=""https://tio.run/##y0rNyan8/7/IOdfoyLSHOxccnndkmtujpjWq@f8Pt8cf3pcAFDu0HEgc6T68z1BH9@GOJY8aZtg@atxxYtnD3d2PGuaEJeZkpgBpz7wyCGsuV1Cu0dFJD3fO0DncfqwLaJj7//8mRgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">check of the first 21</a><br /> | |
(checks that there are exactly <span class=""math-container"">\$\frac{n-1}{2}\$</span> others that are greater and exactly <span class=""math-container"">\$\frac{n-1}{2}\$</span> that are less for each triple in the result.).</p> | |
<h3>How?</h3> | |
<pre><code>rCm2ĖṠÞĖF€%o - Link: (odd, positive) integer, n | |
C - complement (n) -> 1-n | |
r - (n) inclusive range (that) -> [n,n-1,n-2,...,1,0,-1,...,3-n,2-n,1-n] | |
m2 - modulo two slice -> [n, n-2,...,1, -1,...,3-n, 1-n] | |
Ė - enumerate -> [[1,n],[2,n-2],...,[(n+1)/2,1],[(n+3)/2,-1],...,[n-1,3-n],[n,1-n]] | |
Þ - sort by: | |
Ṡ - sign (vectorises) | |
...rotates that list left by (n+1)/2 such that the [(n+3)/2,-1] entry is first | |
Ė - enumerate | |
F€ - flatten each | |
% - modulo (n) (vectorises) | |
o - logical OR (n) (vectorises) ...replaces zeros with n. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>!:Żg$$fR | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer, <span class=""math-container"">\$n\$</span>, and yields the <span class=""math-container"">\$n\$</span><sup>th</sup> row as a list of positive integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1/R6ujudBWVtKD///@bAQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>!:Żg$$fR - Link: integer, n e.g. 4 | |
! - factorial (n) 24 | |
$ - last two links as a monad - f(x=n!): | |
$ - last two links as a monad - f(x): | |
Ż - zero-range (x) [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24] | |
g - (that) greatest common divisor (x) [24, 1, 2, 3, 4, 1, 6, 1, 8, 3, 2, 1,12, 1, 2, 3, 8, 1, 6, 1, 4, 3, 2, 1,24] | |
: - (x) integer divide (that) [ 1,24,12, 8, 6,24, 4,24, 3, 8,12,24, 2,24,12, 8, 3,24, 4,24, 6, 8,12,24, 1] | |
R - range (n) [ 1, 2, 3, 4] | |
f - filter keep [ 1, 4, 3, 2, 3, 4, 1] | |
= [ 1, 4, 3, 2, 3, 4, 1] | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>14</s> 12 bytes</h1> | |
<pre><code>=”:‘+,×ɗị@ƭ/ | |
</code></pre> | |
<p><a href=""https://tio.run/##PY89CsJAEIX7nGJbMbzgT0J4INh7Ag9gI7mAXToLDxAbS0sbURDSJSB4jOQi687M6hbzdvft92Z2v6uqg/ersb5wrM/TtG8@zdCe1u9b5of20T2H170/pt0120y23sPNErp5AkArwxmEW4Qq94TsCd2H@2WoDBWy5BWAyKsraj5/iZYJWiqouWLrewov3YTPVekK6Y44heXTuotKPmE8YTxhPGE88Z/cZkecHpHX/rlqPAe/UKUr5ZfRZ/QZfeHLLw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Thought I could do something fun with matrix multiplication, but this seems to beat any possibilities in that direction.</p> | |
<pre><code>=”: Is each character a colon? | |
‘ Increment to get the numeric values, | |
/ then reduce that by: | |
ƭ alternate between | |
+,×ɗ pair sum and product | |
ị@ and index element into accumulator. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>pS;ị¥$Þ | |
</code></pre> | |
<p>A dyadic Link that accepts <span class=""math-container"">\$w\$</span> on the left and <span class=""math-container"">\$h\$</span> on the right and yields the path as a list of 1-indexed coordinates.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/78g2Prh7u5DS1UOz/v//7/pf2MA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/78g2Prh7u5DS1UOz/uvc3i5/qOGmSpHJz3cOeNR05qsRw1zFGztFB41zNXMetS479C2Q9v@/4@ONtBRMIjl0gHRhkbGIBaQgooZAsVAtJGOghGYbwAVAEmAVQBVgvWY6CiYQGlzEG0KFo8FAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a> (converts the output to 0-indexing).</p> | |
<h3>How?</h3> | |
<p>Each anti-diagonal consists of the maximal subset of coordinates that have the same sum. The path traverses these anti-diagonals in this coordinate-sum order. Those with odd sums are traversed in row order, while those with even sums are traversed in column order. (This is all true regardless of whether 0 or 1 indexing is employed.)</p> | |
<pre><code>pS;ị¥$Þ - Link: integer, w; integer h | |
p - ([1..w]) Cartesian product ([1..h]) -> coordinates | |
Þ - sort by: | |
$ - last two links as a monad - f([r, c]): | |
S - sum ([r, c]) -> r+c = #diagonal | |
¥ - last two links as a dyad -f (#diagonal, [r, c]): | |
ị - (#diagonal) index into ([r, c]) - 1-based and modular | |
-> r if #diagonal is odd; c otherwise | |
; - (#diagonal) concatenate (that) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 25 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ZLr0œċL⁸ḣ"ⱮFE$ƇḢ!^µÐ¡§§0e | |
</code></pre> | |
<p>A full program that accepts a rectangular list of lists of ones and zeros and a non-negative integer and prints <code>1</code> if possible or <code>0</code> if not.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/Kp8jg6OQj3T6PGnc83LFY6dHGdW6uKsfaH@5YpBh3aOvhCYcWHlp@aLlB6v///6OjDXUMgNAwlksnGszQMQAx4aKx/00B"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>This <a href=""https://tio.run/##PVExjsJADOz3FxxIae0f0ECFdD1CdGlOVHSUoaG45iReABRpEBLohIKQKDbAP3Y/shd7vBcJM7bHM3byVS4Wq5SmkyW9ts/vSaya0Bw@4vk0Hg3em9Dse3PXbmJ1a3/8zte@pjK9tuF2iNXDX/013H8/Q7Omth5yf/C@xPUxpaIoZo6J2HU/AgIklrwrOOsLZOkgdsGGJMojdGlBTPqsXOYsrSXJBTpD4gW6AiLdQXOzUJ4zodzTHGrsdAoyWJ/h9x@1oitjzlIiUFSfYA1j1aG8OTZh/Ks9rmUYMoOLEVVhOy4j1OBhr8xUcbwZ49TMsyVFqPtQfw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a> alters the code so it is callable as a dyadic Link (by replacing the <code>µ</code> with a newline and <code>Ç⁹</code>) and calls the link starting with <code>0</code> until a truthy result is found for each of the grids and returns the values reached. Note that going any higher is guaranteed to give a truthy result due to the implementation (repeatedly applying an operation and collecting up).</p> | |
<h3>How?</h3> | |
<p>Greedily inverts the Young "cut-out" that contains all of the same elements with the maximal row-length array. Performs this <span class=""math-container"">\$N\$</span> times and then checks for the existence of an array with no ones.</p> | |
<pre><code>ZLr0œċL⁸ḣ"ⱮFE$ƇḢ!^µÐ¡§§0e - Main Link: grid of 1s and 0s, G (n rows, m columns) | |
С - repeat and collect (starting with G)... | |
- ...times: (implicit) second program argument, N | |
µ - ...action: the monadic chain to the left - f(Current): | |
Z - transpose (Current) | |
L - length | |
r0 - inclusive range to 0 -> [m,...,2,1,0] | |
L - length (Current) -> n | |
œċ - combinations with replacement | |
-> [[m,m,m],...,[m,m,1],[m,m,0],[m,m-1,m-1],...,[0,0,0]] | |
⁸ - chain's left argument -> Current | |
Ɱ - map with: | |
" - zip with: | |
ḣ - head to | |
-> Young-style "cut-outs" reverse sorted by row-lengths | |
Ƈ - keep those for which: | |
$ - last two links as a monad: | |
F - flatten | |
E - all equal? | |
Ḣ - head | |
! - factorial (vectorises) -> converts all 0s to 1s | |
^ - XOR (Current) | |
§ - sums | |
§ - sums | |
0 - zero | |
e - exists in? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>s8Ẉ⁽"s_Ọ | |
</code></pre> | |
<p>A monadic Link that accepts a non-negative integer and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/7/Y4uGujkeNe5WK4x/u7vn//7@RiRkA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>s8Ẉ⁽"s_Ọ - Link: integer, n e.g. 17 | |
8 - eight | |
s - split (implicit [1..n]) into chucks of length (8) | |
[[1..8],[9..16],[17]] | |
Ẉ - length of each [8,8,1] | |
⁽"s - 9616 | |
_ - subtract (vectorises) [9608,9608,9615] | |
Ọ - cast to characters ['█','█','▏'] | |
</code></pre> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>OÆmṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9//cFvuw50N////j1bPAArlq@soqJfnF@WkgBhJlanqsQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>ṗµṙJ;U$Ṃ)QŒgẈċ⁵ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASsA1P9qZWxsef//4bmXwrXhuZlKO1Uk4bmCKVHFkmfhuojEi@KBtf///zP/Nf80"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of @Kevin Cruijssen's 05AB1E answer, so upvote that!</p> | |
<h2>Explanation</h2> | |
<pre><code>ṗµṙJ;U$Ṃ)QŒgẈċ⁵ - Dyadic link taking C, N and S as the third command-line argument | |
ṗ - C cartesian-power N (C implicitly converted to range [1..C]) | |
µ ) - Over each X: | |
J - Get list [1, len(X)] | |
ṙ - For each Y in that, rotate X left by Y | |
$ - Last two links as a monad: | |
U - Reverse each | |
; - Concatenate | |
Ṃ - Minimum | |
Q - After map, uniquify | |
Œg - Split into groups of adjacent equal elements (vectorizes) | |
Ẉ - Length of each | |
ċ⁵ - Count occurences of the third input (S) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>”#2Øhṗị@‘ | |
</code></pre> | |
<p>A full program that accepts a list of integers from <span class=""math-container"">\$[0,255]\$</span> and prints the resulting hexadecimal string.</p> | |
<p><strong><a href=""https://tio.run/##ASgA1/9qZWxsef//4oCdIzLDmGjhuZfhu4tA4oCY////WzI0NSwgNDMsIDJd"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>...a fair bit shorter than the naive approach of a monadic Link like <code>+⁹b⁴Ḋ€‘ịØh”#;</code> which comes in at 13 bytes - <a href=""https://tio.run/##ATIAzf9qZWxsef//K@KBuWLigbThuIrigqzigJjhu4vDmGjigJ0jO////1syNDUsIDQzLCAyXQ"" rel=""nofollow noreferrer"">TIO</a>.</p> | |
<h3>How?</h3> | |
<pre><code>”#2Øhṗị@‘ - Main Link: list of integers, Colours | |
”# - '#' character | |
... the chaining of `nilad nilad nilad` (”#2Øh) | |
forces this to be printed to STDOUT with no trailing character(s) | |
2 - two | |
Øh - hexadecimal characters -> "0123456789abcdef" | |
ṗ - Cartesian power -> ["00","01",...,"ff"] | |
‘ - increment (Colours) (vectorises) | |
@ - with swapped arguments: | |
ị - index into | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>+5Ḷ*I⁸¡ | |
</code></pre> | |
<p>A dyadic Link that accepts <span class=""math-container"">\$d\$</span> on the left and <span class=""math-container"">\$x\$</span> on the right and yields a list of the first five terms.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1/b9OGObVqejxp3HFr4//9/o/8mAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>+5Ḷ*I⁸¡ - Link: integer, d; integer, x | |
+5 - (d) add five -> d+5 | |
Ḷ - lowered range -> [0,1,2,...,d+4] | |
* - exponentiate (x) -> [0^x,1^x,2^x,...,(d+4)^x] | |
¡ - repeat... | |
⁸ - ...times: chain's left argument -> d | |
I - ...action: deltas | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ṅṭ2/Ḋm2IẠƲ¡Œṙß | |
</code></pre> | |
<p>A full program that accepts a list of integers from <span class=""math-container"">\$[1,4]\$</span> and prints the results in Jelly's list format separated by newlines.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hzpaHO9ca6T/c0ZVr5Plw14Jjmw4tPDrp4c6Zh@f////fUEfBSEcBSBqDSQjbEAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Inspired by <a href=""https://codegolf.stackexchange.com/users/73054/cursorcoercer"">CursorCoercer</a>'s <a href=""https://codegolf.stackexchange.com/a/253834/53748"">Pyth answer</a>.</p> | |
<p><code>Œṙ</code>, run-length decode, will error if given a list of integers or a list containing a singleton list. The code ensures that if the current list identifies the same value to be repeated twice in a row then the former will be true and, otherwise, if the current list is of odd length when the latter will be true.</p> | |
<pre><code>Ṅṭ2/Ḋm2IẠƲ¡Œṙß - Main Link: list of integers, S | |
Ṅ - print S | |
¡ - repeat... | |
Ʋ - ...number of times: last four links as a monad: | |
Ḋ - dequeue | |
m2 - modulo-two slice | |
I - deltas | |
Ạ - all non-zero? | |
2/ - ...action: pairwise reduce by: | |
ṭ - tack | |
Œṙ - run-length decode | |
ß - call this link again with that as S | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 25 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a> (no built-in); 2 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a> (built-in)</h1> | |
<h3>Built-in</h3> | |
<p>The two-byte built-in <code>ŒV</code> (evaluate Python code) works as a full program when given the raw input enclosed in <code>'''</code> - the exit code identifies the result: <span class=""math-container"">\$0\$</span> <a href=""https://tio.run/##y0rNyan8///opLD///@rq6srKSklAjGQBQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">if valid</a>, <span class=""math-container"">\$1\$</span> <a href=""https://tio.run/##y0rNyan8///opLD///@rq6srKSklgjGQDQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">if not</a>.</p> | |
<p>Aside: The zero-byte program, when given the raw input, will actually give the evaluated string if valid, or the input if not. However, this does not conform with <a href=""/questions/tagged/decision-problem"" class=""post-tag"" title=""show questions tagged 'decision-problem'"" aria-label=""show questions tagged 'decision-problem'"" rel=""tag"" aria-labelledby=""decision-problem-container"">decision-problem</a> defaults.</p> | |
<h3>Non built-in</h3> | |
<pre><code>Ạ3ƤḢḤ‘ɓẠ⁹ƤḢ×TƊḟḶ}+Ḣ | |
ḊÇ¡ÐL | |
</code></pre> | |
<p>A monadic Link that accepts a list of <span class=""math-container"">\$1\$</span>s (<code>"</code>s) and <span class=""math-container"">\$0\$</span>s (<code>a</code>s) and yields an empty list (falsey) if valid or a non-empty list (truthy) if not.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hrgXGx5Y83LHo4Y4ljxpmnJwMFHjUuBMsdHh6yLGuhzvmP9yxrVYbyOd6uKPrcPuhhYcn@Pz//z/aUAcEDXTgdCwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hrgXGx5Y83LHo4Y4ljxpmnJwMFHjUuBMsdHh6yLGuhzvmP9yxrVYbyOd6uKPrcPuhhYcn@Px/uHvLoa22jxrmKhkYHm6318l61DBHwcZWASiiGfn/v7q6egyXUqISCIMpEAlkQllKMEEgnQjmggGXEhKAaoUZANXMhaYSKMEFNpoL3QYsFkB1YVjJlciFpAHEh9BAXwAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Ạ3ƤḢḤ‘ɓẠ⁹ƤḢ×TƊḟḶ}+Ḣ - Helper Link, prefix length that may be removed: list of 1s and 0s, L | |
3Ƥ - for overlapping infixes of length 3: | |
Ạ - all? | |
Ḣ - head -> 1 if L starts with three 1s, 0 otherwise | |
Ḥ - double | |
‘ - increment -> 3 if L starts with three 1s, 1 otherwise | |
ɓ - new dyadic Link - f(L, Y=that) | |
⁹Ƥ - for overlapping infixes of length Y: | |
Ạ - all? | |
Ɗ - last three links as a monad - f(Z=that): | |
Ḣ - head (alters Z) and yield | |
T - truthy indices (of the altered Z) | |
× - multiply (vectorises) | |
Ḷ} - lowered range (Y) -> [0] or [0,1,2]) | |
ḟ - filter discard (these invalid locations) | |
+ - add Y (vectorises) | |
Ḣ - head (the empty list yields 0) | |
ḊÇ¡ÐL - Main Link: list of 1s and 0s, L | |
ÐL - repeat while results are distinct applying: | |
¡ - repeat... | |
Ç - ...number of times: call the helper Link - f(current L) | |
Ḋ - ...action: dequeue | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 8 </s> 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>‘ḊḌB$\Ẉ | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer, <span class=""math-container"">\$n\$</span>, and yields a list of the first <span class=""math-container"">\$n\$</span> terms.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw4yHO7oe7uhxUol5uKvj////hgYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Performs each conversion step in the opposite order as it avoids the need to get lists again at the end.</p> | |
<p>Uses a reduce that only uses the left item at each step, starting with a list of length <span class=""math-container"">\$n\$</span> that starts with a <span class=""math-container"">\$2\$</span> as it saves a byte over collecting up <span class=""math-container"">\$n-1\$</span> times starting with a <span class=""math-container"">\$2\$</span>.</p> | |
<pre><code>‘ḊḌB$\Ẉ - Link: integer, n | |
‘ - increment (n) -> n+1 | |
Ḋ - dequeue ([1..n+1]) -> [2..n+1] | |
\ - reduce by: | |
$ - last two links as a monad - i.e. f(left): | |
Ḍ - convert from decimal e.g. 2 -> 2 or [1,0,1,0] -> 1010 | |
B - convert to binary e.g. 2 -> [1,0] or 1010 -> [1,1,1,1,1,1,0,0,1,0] | |
Ẉ - length of each | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>Dœ^/LỊaṢ-ịø#Ṫ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASQA2/9qZWxsef//RMWTXi9M4buKYeG5oi3hu4vDuCPhuar///8yNzA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Out of curiosity, I decided to see how far I could get without actually computing permutations, and two hours of head bashing later it ties caird's existing answer (modulo a golf to use <code>ø</code>). The logic boils down to checking two conditions:</p> | |
<ul> | |
<li><p>At most one digit occurs an odd number of times.</p> | |
</li> | |
<li><p>There must be multiple nonzero digits if at least one digit is zero.</p> | |
</li> | |
</ul> | |
<p>and stuck in a blender for five minutes on high, that's:</p> | |
<pre><code> # Count up collecting the first n integers | |
ø starting from 0 which satisfy: | |
D Do the digits | |
œ^/ reduced by symmetric multiset difference | |
LỊ have length ≤ 1? | |
Ṣ Sort the digits, | |
a replace them all with 0 if the previous condition is not met, | |
-ị and take the second to last element (wrapping around if length 1), | |
# succeeding if it's nonzero. | |
Ṫ Return the last result. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>2ƽƲ¿Ẓ$# | |
</code></pre> | |
<p>A monadic Link that accepts an integer, <span class=""math-container"">\$n\$</span>, and yields the first <span class=""math-container"">\$n\$</span> Fermi-Dirac primes.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/ocNuhvUC86dD@h7smqSj////fzBAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>2ƽƲ¿Ẓ$# - Link: integer, n | |
2 # - count up, starting at 2, and find the first n integers for which: | |
$ - last two links as a monad: | |
¿ - while... | |
Ʋ - ...condition: is square? | |
ƽ - ...action: integer square root | |
Ẓ - is prime? | |
</code></pre> | |
<p>Note: The integer-square-root, <code>ƽ</code> could be square-root <code>½</code>, but we'd need to cast to an integer (e.g. floor, <code>Ḟ</code>) to use <code>Ẓ</code> anyway (e.g. <code>2.0</code> is not considered prime), but using <code>ƽ</code> avoids any floating point arithmetic entirely.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŒPUṚ;"Ɗi | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIDQhztnWSsd68r8f3i5g/6jpjX//0dHK/kHOYb4BynpKCj5hwQ5BvkrxXLpRCsFu4a7ggVdw4OBDLCYs7@/D0gITENEPFyDg0FCwa4ewc4QMcdwxwjHSMcokLBjRCSQG@WIaWaQK0TMyT8CJOLkHwnV7eToHAo20tHZ0QnIgugMDnYMhtoEYQPFYwE"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes the letter-list <span class=""math-container"">\$\sigma\$</span> on the left and the target word <span class=""math-container"">\$S\$</span> on the right, returning a non-negative integer (truthy) if the word can be formed and 0 (falsy) otherwise.</p> | |
<p>Inspired by <a href=""https://chat.stackexchange.com/transcript/message/62244870#62244870"">a brief exchange with caird coinheringaahing</a>.</p> | |
<pre><code>ŒP Powerset of σ: list of all sublists of σ, not necessarily contiguous. | |
U Reverse each, then | |
Ṛ reverse the entire list, | |
;"Ɗ and concatenate corresponding elements of the unmodified powerset: | |
ŒPUṚ;"Ɗ it's ordered so that each sublist's complement is at the complementary index. | |
i Find the first index of S in that result, or 0 if not found. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Employs the inverse test of a post by <a href=""https://codegolf.stackexchange.com/users/97857/pxeger"">pxeger</a> - <a href=""https://codegolf.stackexchange.com/a/243174/53748"">here</a>.</p> | |
<pre><code>JŒ!<ƝṢƑ$Ƈịċ⁸ | |
</code></pre> | |
<p>A dyadic Link that accepts the sign, <span class=""math-container"">\$S\$</span>, on the left and the deck of letters, <span class=""math-container"">\$\sigma\$</span>, on the right and yields a positive integer (truthy) if possible or <span class=""math-container"">\$0\$</span> (falsey) if not.</p> | |
<p><strong><a href=""https://tio.run/##ATQAy/9qZWxsef//SsWSITzGneG5osaRJMaH4buLxIvigbj///8iU1RBVElPTiL/IklPVEFOVFMi"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/r6CRFm2NzH@5cdGyiyrH2h7u7j3Q/atzx//By/UdNa/7/j45W8g9yDPEPUtJRUPIPCXIM8leK5dKJVgp2DXcFC7qGBwMZYDFnf38fkBCYhoh4uAYHg4SCXT2CnSFijuGOEY6RjlEgYceISCA3yhHTzCBXiJiTfwRIxMk/EqrbydE5FGyko7OjE5AF0Rkc7BgMtQnCBorHAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>First, this constructs a list of all permutations of the indices of <span class=""math-container"">\$S\$</span> which do not decrease after their first increase.</p> | |
<p>e.g. for <span class=""math-container"">\$S\$</span> of length four:</p> | |
<pre><code>[1, 2, 3, 4] | |
[2, 1, 3, 4] | |
[3, 1, 2, 4] | |
[3, 2, 1, 4] | |
[4, 1, 2, 3] | |
[4, 2, 1, 3] | |
[4, 3, 1, 2] | |
[4, 3, 2, 1] | |
</code></pre> | |
<p>It then uses these to index into the deck, <span class=""math-container"">\$\sigma\$</span>, to construct all the possible signs and counts the occurrences of the sign, <span class=""math-container"">\$S\$</span>.</p> | |
<pre><code>JŒ!<ƝṢƑ$Ƈịċ⁸ - Link: list of characters S, list of characters D (sigma) | |
J - range of length (S) -> [1,2,3,...,length(S)] | |
Œ! - all permutations | |
Ƈ - filter keep those for which: | |
$ - last two links as a monad: | |
Ɲ - for neighbouring pairs: | |
< - less than? | |
Ƒ - is invariant under?: | |
Ṣ - sort | |
ị - index into (D) (vectorises) | |
⁸ - chain's left argument = S | |
ċ - count occurrences | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>O+7S‘ịØa | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields a character.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/99f2zz4UcOMh7u7D89I/P//f3J@Smp6fk4aAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/99f2zz4UcOMh7u7D89I/P9w95bD7Y@a1kT@/58BlM8vzy/KSeFKTEpOSU3jSs5PSU3Pz0njKi5JTM5OrUjOSMxLT@VKBAEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>O+7S‘ịØa - Link: list of characters, Message | |
O - ordinals (Message) | |
+7 - add seven (vectorises) | |
S - sum | |
‘ - increment | |
Øa - "abc...xyz" | |
ị - index into (1-based and modular) | |
</code></pre> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>RÆE§ḂSṄạ | |
</code></pre> | |
<p><a href=""https://tio.run/##ARwA4/9qZWxsef//UsOGRcKn4biCU@G5hOG6of///zE0"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>RÆE§ḂSṄạ | |
R - Range [1, input] | |
ÆE - For each, get a list of the prime exponents | |
§ - Sum each | |
Ḃ - Modulo each by 2 | |
S - Sum | |
Ṅ - Print (with a trailing newline) | |
ạ - Get the absolute difference between this and the input (also implicitly printed) | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>ZU$Ƭ:/€INM’Ḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z8qVOXYGiv9R01rPP18HzXMfLhj0f/D7UBu5P//0dGGOkaxOtHGOiaxsToK0dGmOuZAriVQEMw11zEFcs2AZCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>ZU$Ƭ:/€INM’Ḣ - Main link. Takes a matrix M on the left | |
$Ƭ - Do the following until a repeat is found: | |
Z - Transpose | |
U - Reverse rows. This rotates clockwise 90° | |
€ - To each rotation: | |
:/ - Reduce each column by integer division | |
I - Get the (negative) differences | |
N - Negate | |
M - Get the index of the maximal element | |
’ - Decrement | |
Ḣ - Get the first (minimal) element | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 33 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>,_J$;,Ṛ,ŒHƲE€i1 | |
“𩽑ḶŒpDF€ṙ⁸Ç€i’ | |
</code></pre> | |
<p>A dyadic link that accepts the time of day in minutes as an integer on the left and the category as an integer on the right and yields the number of minutes until the clock will show a time with the given category.</p> | |
<div class=""s-table-container""> | |
<table class=""s-table""> | |
<thead> | |
<tr> | |
<th style=""text-align: center;"">category</th> | |
<th style=""text-align: center;"">input value</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td style=""text-align: center;"">all the same</td> | |
<td style=""text-align: center;"">1</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">increasing</td> | |
<td style=""text-align: center;"">2</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">palindrome</td> | |
<td style=""text-align: center;"">3</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">pair</td> | |
<td style=""text-align: center;"">4</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
<p>(Zero will give the time until no category too.)</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/18n3kvFWufhzlk6Ryd5HNvk@qhpTaYh16OGOYc3HFp5aO@jhhkPd2w7OqnAxQ0o83DnzEeNOw63gxQ9apj5//9/M3PD/yYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/18n3kvFWufhzlk6Ryd5HNvk@qhpTaYh16OGOYc3HFp5aO@jhhkPd2w7OqnAxQ0o83DnzEeNOw63gxQ9apj5/@GORQ93Ln7UMNcq7OGOVjODw8sf7lwF1JuYk6NQkpGqUJyYmwrkZuYlF6UmFmfmpQM5BYk5mXkpRflgmYLEzCKg9sxjXZr//0dHqxuaWJmYq@soqCNUqcdy6USrG1gZGIDEkU2GyBgZWxkbY9MClDAygUhkFkGEDGHGIFyEajy6ONAMU0vs9hoaWhkaIhkfCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>,_J$;,Ṛ,ŒHƲE€i1 - Helper Link = categorise: Time as a list of three or four digits | |
$ - last two links as a monad - f(Time): | |
J - range of length (Time) -> [1,2,3] or [1,2,3,4] | |
_ - (Time) subtract (that) (vectorises) | |
, - (Time) pair with (that) | |
Ʋ - last four links as a monad - f(Time): | |
Ṛ - reverse (Time) | |
, - (Time) pair with (that) | |
ŒH - split (Time) into two halves | |
, - ([Time, Reversed(Time)]) pair (that) | |
; - concatenate | |
-> [Time, Time - Indices, [Time, Reversed(Time)], [Prefix, Suffix]] | |
€ - for each: | |
E - all equal? -> 1 or 0 | |
i1 - first 1-indexed index of 1, or 0 if none | |
“𩽑ḶŒpDF€ṙ⁸Ç€i’ - Link = time to next: time of day in minutes, M; category, C | |
“𩽑 - code-page indicies = [24,6,10] | |
Ḷ - lowered range -> [[0..23],[0..5],[0..9]] | |
Œp - Cartesian product -> [[0,0,0],...,[0,5,9],[1,0,0],...,[23,5,9]] | |
D - digits -> [...,[[2,3],[5],[9]]] | |
F€ - flatten each -> [[0,0,0],...,[0,5,9],[1,0,0],...,[2,3,5,9]] | |
ṙ⁸ - rotate (that) left by (M) | |
Ç€ - call the helper Link (above) for each | |
i - first 1-indexed index of (C) in (that) | |
’ - decrement | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 20 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>1ịṭṚZµ4¡O+3\Z$⁺+4:9Ọ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lines and yields a list of lines.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/w4e7uhzvXPtw5K@rQVpNDC/21jWOiVB417tI2sbJ8uLvn/8PdWw63R/7/r25hYaHOZaGurm4BJC3AJIgNFgcA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/w4e7uhzvXPtw5K@rQVpNDC/21jWOiVB417tI2sbJ8uLvn/8PdWw63R3Idnfxw5@JHjfsObTu07XD7o6Y1WVAO0AhDQy5DcyAG0lwRIMCloxOho4NCQsS51C0sLNS5LNTV1S2ApAWYBLEh4lyGBsYGpgbmBpZcXIp1XHWKXFyBXFzaurraXDUKCjUQFlcclxYQxgEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>1ịṭṚZµ4¡O+3\Z$⁺+4:9Ọ - Link: list of lines, T | |
µ4¡ - repeat four times (starting with T): | |
1 - one | |
ị - index into -> top row | |
Ṛ - reverse (the current lines) | |
ṭ - tack -> reversed current lines + top row | |
Z - transpose | |
O - convert to ordinals | |
⁺ - do this twice: | |
$ - last two links as a monad: | |
3\ - three-part reduce with: | |
+ - addition | |
Z - transpose | |
+4 - add four | |
:9 - integer divide by nine | |
Ọ - convert to characters | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 15 </s> 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>×3Ṗ+×ɗRṚ;$m2;@ | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer and yields a longest trampoline as a list of positive integers.</p> | |
<p><strong><a href=""https://tio.run/##ASAA3/9qZWxsef//w5cz4bmWK8OXyZdS4bmaOyRtMjtA////NQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Trampolines are <span class=""math-container"">\$3n\$</span> long, start with <span class=""math-container"">\$n\$</span> and are then filled at the leftmost then rightmost available slots starting at <span class=""math-container"">\$3n-1\$</span> descending until <span class=""math-container"">\$n\$</span> slots are left, which need filling with numbers that will go out of bounds in both directions.</p> | |
<p>i.e. the template is:</p> | |
<pre><code>[n, 3n-1, 3n-3, ..., <n ?'s>, ..., 3n-4, 3n-2] | |
</code></pre> | |
<p>The code starts with a list from <span class=""math-container"">\$1\$</span> to <span class=""math-container"">\$3n-1\$</span> and adds <span class=""math-container"">\$3ni\$</span> to the entries at indices <span class=""math-container"">\$i\leq n\$</span> (the ones that will end up at the <code>?</code>s in the template). It then prefixes this with its reverse, appends the forward version, discards every other element, and prefixes with <span class=""math-container"">\$n\$</span> to give a trampoline.</p> | |
<pre><code>×3Ṗ+×ɗRṚ;$m2;@ - Link: integer, n e.g. 3 | |
×3 - multiply (n) by three 9 | |
R - range (n) [1,2,3] | |
ɗ - last three links as a dyad: | |
Ṗ - pop (3n) [1,2,3,4,5,6,7,8] | |
× - (3n) multiply (range n) [9,18,27] | |
+ - add [10,20,30,4,5,6,7,8] | |
$ - last two links as a monad: | |
Ṛ - reverse [8,7,6,5,4,30,20,10] | |
; - concatenate [8,7,6,5,4,30,20,10,10,20,30,4,5,6,7,8] | |
2 - two | |
m - modulo slice [8, 6, 4, 20, 10, 30, 5, 7] | |
@ - with swapped arguments: | |
; - (n) concatenate [3,8,6,4,20,10,30,5,7] | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 30 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-4 thanks to <a href=""https://codegolf.stackexchange.com/users/52210/kevin-cruijssen"">Kevin Cruijssen</a> (remove an effectively redundant filter of the "direction" <code>[0,0]</code>, which also means there's no need to get the threatening queen separately.)</p> | |
<pre><code>+8RĖ×Ɱ2Ż’p`¤¤f€ZḢ | |
ŒṪç€iƇẈEɗⱮ$Ạ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of <code>1</code>s (queens) and <code>0</code>s (not queens) that yields <code>1</code> if there is a peaceful standoff or <code>0</code> if not.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1/bIujItMPTH21cZ3R096OGmQUJh5YcWpL2qGlN1MMdi7iOTnq4c9Xh5UBu5rH2h7s6XE@ClKo83LXg////0dEGOigwlksHm5AhNlWG2DQaYmo0xGe8IbqQIUhVLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/1/bIujItMPTH21cZ3R096OGmQUJh5YcWpL2qGlN1MMdi7iOTnq4c9Xh5UBu5rH2h7s6XE@ClKo83LXg/8PdWx7u2ASUcQNi/4c7mg63cx2d/HDn4keN@w5tO7TtcDtQ/P9/PQUUyIWdH0hAHpkfCFcfCOfjUh/IhceAQCItpIxPcwvo5oBA6jqA1DincQgEkuQgqjsgkOxcQJQDAtGyBb4gDqSCj9Htw@qAQEQ64ELmBcKjBJsFgTjKAVTz0OwDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>+8RĖ×Ɱ2Ż’p`¤¤f€ZḢ - Helper Link = get queen & threatened queens( | |
queen coordinate, Q; | |
all queen coordinates, A | |
): | |
¤ - nilad followed by links as a nilad: | |
8 - eight | |
R - range -> [1,...,7,8] | |
Ė - enumerate -> [[1,1],...,[7,7],[8,8]] | |
¤ - nilad followed by links as a nilad: | |
2 - two | |
Ż - zero-range -> [0,1,2] | |
’ - decrement -> [-1,0,1] | |
` - use as both arguments of: | |
p - Cartesian product -> [[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]] | |
Ɱ - map with: | |
× - multiply -> [[[-1,-1],...,[-7,-7],[-8,-8]],[[-1,0],...,[-7,0],[-8,0]],[[-1,1],...,[-7,7],[-8,8]], ... ... ... ,[[1,1],...,[7,7],[8,8]]] | |
+ - (Q) add (vectorises) -> nine lists of potential locations in | |
each of the eight lines of sight | |
in proximity order plus the direction | |
[0,0] which will all be Q | |
(includes off-board locations) | |
f€ - for each: filter keep (A) -> nine lists (eight are possibly empty) | |
Z - transpose | |
Ḣ - head -> list of threatened queens and Q herself. | |
ŒṪç€iƇẈEɗⱮ$Ạ - Link = is peaceful?(board): | |
ŒṪ - truthy multidimensional indices -> all queen coordinates | |
$ - last two links as a monad - f(all queens): | |
ç€ - call the Helper link for each queen with all queens on the right | |
Ɱ - map (across Q in all queens) with: | |
ɗ - last three links as a dyad - f(Helper results, Q): | |
Ƈ - keep those for which: | |
i - first 1-indexed index of Q or 0 if not found | |
Ẉ - length of each | |
E - all equal? | |
Ạ - all? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŻrḤ$3ḍFTḣ | |
</code></pre> | |
<p>A monadic Link that accepts a non-negative integer, <span class=""math-container"">\$n\$</span>, and yields the first <span class=""math-container"">\$n\$</span> triangular honeycomb numbers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw4wgbZVHTWuADOOHO3rdQh7uWPz//38zEwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>The triangle's <span class=""math-container"">\$i^{\text{th}}\$</span> row contributes every third element starting with the <span class=""math-container"">\$(3 - (i+1\pmod 3))^{\text{th}}\$</span> element...</p> | |
<pre><code>ŻrḤ$3ḍFTḣ - Link: integer, n e.g. 4 | |
Ż - zero-range (n) [ 0, 1, 2, 3, 4] | |
$ - last two links as a monad: | |
Ḥ - double [ 0, 2, 4, 6, 8] | |
r - inclusive range [[0],[1,2],[2,3,4],[3,4,5,6],[4,5,6,7,8]] | |
3 - three 3 | |
ḍ - divides? [[1],[0,0],[0,1,0],[1,0,0,1],[0,0,1,0,0] | |
F - flatten [ 1, 0,0, 0,1,0, 1,0,0,1, 0,0,1,0,0] | |
T - truthy indices [ 1, 5, 7, 10, 13 ] | |
ḣ - head (to index n) [1,5,7,10] | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 9 </s> 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ḷ²’xRĖḄḣ | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer, <span class=""math-container"">\$n\$</span>, and yields a list of the first <span class=""math-container"">\$n\$</span> odd-odd triangular polka dot numbers.</p> | |
<p><strong><a href=""https://tio.run/##AR4A4f9qZWxsef//4bi2wrLigJl4UsSW4biE4bij////Mzc"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Calculates the first <span class=""math-container"">\$T(n)=\frac{n(n+1)}{2}\$</span> terms, and outputs the first <span class=""math-container"">\$n\$</span>.</p> | |
<pre><code>Ḷ²’xRĖḄḣ - Link: integer, n e.g. 5 | |
Ḷ - lowered range (n) [ 0, 1, 2, 3, 4] | |
² - square (vectorises) [ 0, 1, 4, 9, 16] | |
’ - decrement [ -1, 0, 3, 8, 15] | |
R - range (n) [ 1, 2, 3, 4, 5] | |
x - repeat elements [ -1, 0, 0, 3, 3, 3, 8, 8, 8, 8, 15, 15, 15, 15, 15] | |
Ė - enumerate [[1,-1],[2,0],[3,0],[4,3],[5,3],[6,3],[7,8],[8,8],[9,8],[10,8],[11,15],[12,15],[13,15],[14,15],[15,15]] | |
Ḅ - convert from base 2 (vectorises) | |
...i.e. [a,b] -> 2a+b [ 1, 4, 6, 11, 13, 15, 22, 24, 26, 28, 37, 39, 41, 43, 45] | |
ḣ - head (to index n) [ 1, 4, 6, 11, 13] | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>Rj)F;1 | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer and yields a list of positive integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z8oS9PN2vD////GAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Much like alephalpha's <a href=""https://codegolf.stackexchange.com/a/253324/53748"">Husk answer</a>...</p> | |
<pre><code>Rj)F;1 - Link: integer, N | |
) - for each (n in [1..N]): | |
R - range (n) | |
j - join with (n) | |
F - flatten | |
;1 - concatenate a one | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>Ærċ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wW9GR7v@hh5cfWqr0/3@0oY6Rjq65jkmsjgIaW9dEx1RH10jHgDDXRMcAJGCiYwgSMoSqMDTSMQOKGwIJIxMQwxIoAFQa@99QRwGoXMFARwHIMgJyQBQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input as a list of coefficients in ascending order. The Footer on TIO reverses each of the test cases to fit this.</p> | |
<h2>How it works</h2> | |
<pre><code>Ærċ - Main link. Takes a polynomial P on the left, and a root r on the right | |
Ær - Calculate the roots of P, with repeats | |
ċ - Count the number of times r appears in the list of roots | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 11 10 </s> 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>9_ḋJÆN$‘ | |
</code></pre> | |
<p>A monadic Link that accepts a list of integers and yields the checksum value as an integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/98y/uGObq/DbX4qjxpm/P//P9pUx1jHSMdMx0DHAsgy1TGKBQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>9_ḋJÆN$‘ - Link: list of integers, A | |
9 - nine | |
_ - subtract A (vectorises) -> Remainders = [9-A1, 9-A2, ...] | |
$ - last two links as a monad - f(A): | |
J - range of length (A) -> [1,2,3,4,5,...,length(A)] | |
ÆN - nth prime -> Primes = [2,3,5,7,11,...,length(A)th-Prime] | |
ḋ - (Remainders) dot product (Primes) = (9-A1)*2 + (9-A2)*3 + ... | |
‘ - increment -> checksum | |
</code></pre> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>+Un155SỊ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/187NM/Q1DT44e6u/w93b/E/3P6oac3RPUBmFpDxqGGOgo2twqOGuZH//ztyOTqBcBQQAxlOrmGRXO7@Pm5cUf4@jlzhnlGOQS5cTp7u/iFBkVxBjs6uzo5BQKXOLq5u7h6eXt4@vn7@AYFBwSGhYeERkVEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 thanks to Jonathan Allan</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ḅ60÷.864+.Ḟ | |
</code></pre> | |
<p>A monadic Link that accepts a list of non-negative integers, <code>[h, m, s]</code>, and yields a non-negative integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjlYzg8Pb9SzMTLT1Hu6Y9////2hDIx1jEx1Ts1gA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hjlYzg8Pb9SzMTLT1Hu6Y9//opIc7Z@gcbs961DBHwdZO4VHDXM3I//@jow2NdIxNdEzNYrl0og10gBDEMDLWMbUEIhDb0FAHjMBsUx0jUx1jUzBbB6gTpssQwjCEaDeEmBMLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ḅ60÷.864+.Ḟ - Link: list of non-negative integers, T = [h, m, s]: | |
ḅ60 - convert T from base sixty -> 3600*h+60*m+s = seconds | |
.864 - 0.864 (seconds per "second") | |
÷ - (seconds) divide (0.864) -> "deconds" | |
. - a half | |
+ - (deconds) add (a half) | |
Ḟ - floor to nearest integer | |
</code></pre> | |
" | |
"64159","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>DịØa;@”Ax5¤Uḣ5U | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/l4e7uwzMSrR0eNcx1rDA9tCT04Y7FpqH/D7c/aloT@f9/tImxkaGxjoKFmYmpjoKxiZGOgiUQGMYCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Almost certainly I'm missing some atoms or syntax tricks that can get this down further. 11 bytes are spent to handle the padding.</p> | |
<p>Explanation:</p> | |
<pre><code>DịØa;@”Ax5¤Uḣ5U | |
D get decimal representation | |
ịØa index into lowercase alphabet | |
”Ax5¤ repeat "A" 5 times | |
;@ prepend "A"s to the other string | |
Uḣ5U take the last 5 characters | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ẈÄṬ¬kẎ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASoA1f9qZWxsef//4bqIw4ThuazCrGvhuo7/w4fFkuG5mP//WzEsMl0sWzMsNF0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Another port of Neil's logic--completely invert the partition--except without string operations. Takes and returns a list of lists.</p> | |
<pre><code> Ṭ Generate an array with 1s at the indices in | |
Ä the cumulative sum of | |
Ẉ the lengths of the original partitions. | |
k Partition the array | |
Ẏ concatenated | |
¬ after positions of 0s. | |
</code></pre> | |
" | |
"106844","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 40 bytes</h1> | |
<pre><code>“¡Œb» | |
Ñ;¢x⁵ | |
“¡Ph%»Ḥ | |
“¡çı»;¢1£“ŀu»¢1£2£”o | |
</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6Fjc9HjXMObTw6KSkQ7u5Dk-0PrSo4lHjVi6wYECG6qHdD3csgfAOLz-y8dBuoALDQ4uBAkcbSg_tBnOMQPy5-UuKk5KLoabCTAcA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>Basically just a couple of compressed strings, repeating some of them</p> | |
" | |
"114332","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, <s>16</s> <s>15</s> 13 bytes</h1> | |
<pre><code>8825.985÷½÷ØP | |
</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FhstLIxM9SwtTA9vP7T38PbDMwKWFCclF0NlYaoA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>This is my first Jelly answer, so it can almost certainly be golfed.</p> | |
<ul> | |
<li>-1 byte thanks to MehanAlavi</li> | |
</ul> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, Fast: 47 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a> / Slow: 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<h3>Slow:</h3> | |
<pre><code>L‘Œ!IṠnẠ¥ƇV€L | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters - <code><-></code> represented as <code>-01</code> respectively and yields the solution count.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/nUcOMo5MUPR/uXJD3cNeCQ0uPtYc9alrj8///fyVDXSBUAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the, truncated <a href=""https://tio.run/##y0rNyan8/9/nUcOMo5MUPR/uXJD3cNeCQ0uPtYc9alrj8/9RwxwbXTsgqWtg@KhhbiWQpaChBCSVNK0UgAJZOofbj23SfNS44@ieyP//o5WUdBSU7ECEDYjQBbPAfDsw2w7C0dWF8HTt7KCiQPFYAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a> (shows the Link input in parentheses).</p> | |
<h5>How?</h5> | |
<pre><code>L‘Œ!IṠnẠ¥ƇV€L - Link: list of characters, A, from '-01' (equivalent to '<->' respectively): | |
L - length (of A) | |
‘ - increment | |
Œ! - all permutations of [1..that] | |
I - deltas (b-a for each neighbouring pair (a,b) in each list) | |
Ṡ - signs -> 1 if a<b; -1 if a>b | |
V€ - evaluate each (of A) as Jelly code -> '-': -1, '0' -> 0, '1' -> 1 | |
¥Ƈ - keep those (of the delta lists) for which: | |
n - not equal? (vectorises) | |
Ạ - all? | |
L - length | |
</code></pre> | |
<hr /> | |
<h3>Fast:</h3> | |
<pre><code>ḅ3$Ɲ%6ỊTœP€⁸;ḊŻ$}¥/€Ñ€Sȯ1 | |
i@‘ịɗ,Ç$;ɼ0ịƲe?® | |
Ø0jÇ | |
</code></pre> | |
<p>A monadic Link that accepts a list of integers - <code><-></code> represented as <code>[2,0,1]</code> respectively and yields the solution count.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjlZjlWNzVc0e7u4KOTo54FHTmkeNO6wf7ug6ulul9tBSfaDA4YlAIvjEekOuTIdHDTMe7u4@OV3ncLuK9ck9BkDOsU2p9ofWcR2eYZB1uP3/o8Z9djaZjzauA7L/K9nZ2dggsBIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hjlZjlWNzVc0e7u4KOTo54FHTmkeNO6wf7ug6ulul9tBSfaDA4YlAIvjEekOuTIdHDTMe7u4@OV3ncLuK9ck9BkDOsU2p9ofWcR2eYZB1uP3/o8Z9djaZjzauOzrp4c4ZjxrmKGgACU0rhUcNc7NUgNqObdIE2nB0T@T//9FKSjoKSnYgwgZE6IJZYL4dmG0H4ejqQni6dnZQUag4UETXBqYBKKoLJOxsoGpAymzAFFjADsyGYqVYAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a> (shows the Link input in parentheses).</p> | |
<h5>How?</h5> | |
<p>Implements the same algorithm as <a href=""https://codegolf.stackexchange.com/users/9288/alephalpha"">alephalpha</a>'s <a href=""https://codegolf.stackexchange.com/a/252362/53748"">Mathematica answer</a> - go show some love :)</p> | |
<p>No built-in cache so this implements one. It's not got particularly great performance because (a) Jelly has no dictionary or hash-map data type, (b) Jelly only has a single register, so I keep values alongside their corresponding keys so it must search through those too (they can never match as keys are lists while values are positive integers), and (c) I went with a golfy implementation which looks up the key twice.</p> | |
<p>Note: the main Link is the one at the bottom, <code>Ø0jÇ</code>.</p> | |
<pre><code>ḅ3$Ɲ%6ỊTœP€⁸;ḊŻ$}¥/€Ñ€Sȯ1 - Link 1, calculate count: list of integers, A, from [0,1,2] (equivalent to '-><' respectively): | |
ḅ3$Ɲ - convert each neighbouring pair from base 3 | |
%6 - modulo by six (vectorises) | |
Ị - insignificant? (effectively is that 0 or 1?) | |
T - truthy indices | |
-> starts of substrings equivalent to: '->', '<-', '<>', and '--' | |
i.e. possible surrounding chars of the highest value | |
œP€⁸ - partition (A) at each of those (discarding the index itself) | |
¥/€ - reduce each by: | |
$} - apply to the right hand one: | |
Ḋ - dequeue | |
Ż - prefix a zero (equivalent to a '-') | |
; - (left one) concatenate (that) | |
Ñ€ - call Link 2 (below) for each (if any) | |
S - sum | |
ȯ1 - logical OR with one | |
i@‘ịɗ,Ç$;ɼ0ịƲe?® - Link 2, get count: list of integers, A, from [0,1,2] (equivalent to '-><' respectively): | |
® - recall from the register | |
Our cache: initially zero, but becomes a list of inputs (lists) | |
and outputs (positive integers) with a zero prefix | |
e.g. [0, [2], 1, [2,2], 1, [1], 1, [1,2], 2, ...] | |
'<'=1 '<<'=1 '>'=1 '><'=2 ... | |
? - if... | |
e - ...condition: exists? | |
ɗ - ...then: last three links as a dyad - f(A, cache) | |
i@ - index (of A) in (the cache) | |
‘ - increment -> index of the pre-calculated value | |
ị - index into the cache -> pre-calculated value | |
Ʋ - ...else: last four links as a monad - f(A): | |
$ - last two links as a monad - f(A): | |
Ç - call Link 1 (above) | |
, - (A) paired with that | |
ɼ - apply to the register & yield: | |
; - (register) concatenate (that) -> adds the "key" A (a list) and value | |
0ị - 0 index into -> gets the value back out | |
Ø0jÇ - Link 3 (main Link): list of integers, A, from [0,1,2] (equivalent to '-><' respectively): | |
Ø0 - [0,0] (equivalent to "--") | |
j - join with A | |
Ç - call Link 2 (above) | |
</code></pre> | |
<hr /> | |
<h3>Also:</h3> | |
<p>Fast version taking the characters as given in the question <span class=""math-container"">\$51\$</span> <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a>:</p> | |
<pre><code>*Ɲ%87%5ḂTœP€⁸;45;Ḋ}ʋ/€Ñ€Sȯ1 | |
i@‘ịɗ,Ç$;ɼ0ịƲe?® | |
⁾--jOÇ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1/r2FxVC3NV04c7mkKOTg541LTmUeMOaxNT64c7umpPdesDBQ5PBBLBJ9YbcmU6PGqY8XB398npOofbVaxP7jEAco5tSrU/tI7rUeM@Xd0s/8Pt/4FyWUCelYJm5P//0UpKOgpKdiDCBkTogllgvh2YbQfh6OpCeLp2dlBRqDhQRNcGpgEoqgsk7GygakDKbMAUWMAOzIZipVgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>SBŻ⁹¡ṫC}⁸; | |
</code></pre> | |
<p>A dyadic Link that accepts a list of bits on the left and a positive integer on the right and yields a list of bits extended with the parity bits.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/Y6ejuR407Dy18uHO1c@2jxh3W////jzbUgcLY/0YGAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/z/Y6ejuR407Dy18uHO1c@2jxh3W/8MeNa05vPzQUn3NyP//o6OVDA0MDQ2UdBQMY7l0opVAHCAE8o3AfJAsBAOFjCFKQGqgGCIH0gKmQfpMYrli/xsDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>SBŻ⁹¡ṫC}⁸; - Link: bits, n | |
S - sum (bits) -> count of ones | |
B - to binary | |
¡ - repeat... | |
⁹ - ...times: chain's right argument = n | |
Ż - ...action: prepend a zero | |
-> count of ones as binary with n leading zeros | |
} - using the right argument (n): | |
C - complement -> 1-n | |
ṫ - tail (from 1-indexed index 1-n) | |
-> parity bits (including any necessary leading zeros) | |
⁸ - chain's left argument = bits | |
; - concatenate (parity bits) to (bits) | |
</code></pre> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 1 byte</h1> | |
<pre><code>x | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/i/@Hl@o@a1hyd9HDnDCAd@f9/dHS0oY6RjnGsDpQGMqLNdAyA0AzINNUxBEIDsKihgYEOEAOZBiCRWAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 7 </s> 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ẋṫ4XN¤ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of characters and yields another with 2-5 random entries.</p> | |
<p><strong><a href=""https://tio.run/##TU@7UQQxDM1dhRogow5iCHW2/LnVSozkhdsKmKEOMtJLgAwq2UoW35GQvv87EvO679vn6/bxfnt/9/22b1/nn5eHffcZmaGqiYeMUhzUwCvaI3SiXgNCVpsoQVcpC4WIndtEQCt58HaC3KSQDZ8AYaxQUVIoiv3mqmMqHiLrE8mo0ez/ErFxYMJeydZrb0RewacmwQY/kIQ2wYEX@kMjegfRy8CkzxeBUWaKvakEOi2JAMHncRc0w8Ha7GM2/QI"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ẋṫ4XN¤ - Link: list, A | |
Ẋ - get a shuffled copy of A | |
¤ - nilad followed by link(s) as a nilad: | |
4 - four | |
X - random choice from 1-4 | |
N - negate | |
ṫ - tail (the shuffled copy) from (that) 1-indexed index | |
</code></pre> | |
" | |
"112514","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>9</s> 8 bytes</h1> | |
<pre><code>ØḄØẹḂ?X) | |
</code></pre> | |
<p><em>-1 byte thanks to @Steffan</em></p> | |
<p><a href=""https://tio.run/##y0rNyan8///wjIc7WoDErp0PdzTZR2j@///fFAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Explanation:</p> | |
<pre><code>ØḄØẹḂ?X) # main link taking an integer | |
) # over the list [1..n] | |
? # if | |
Ḃ # n modulo 2 is truthy | |
ØḄ # yield the consonants | |
Øẹ # otherwise the vowels | |
X # get a random letter from that | |
<span class=""math-container"">```</span> | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>Ir0Œpk€ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9@zyODopILsR01r/h9uPzrp4c4ZQObDnYsi//@PNtQx1DEAQkMkaBALAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Inspired by <a href=""https://codegolf.stackexchange.com/a/252314/85334"">Jonathan Allan's solution</a>.</p> | |
<pre><code>I Get the forward differences of the list. | |
k Partition the list after each truthy position | |
€ of each element of | |
Œp the Cartesian product of | |
r0 the ranges from each difference to 0 inclusive. | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ŒgŒṖẎ€€ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opPSjkx7unPZwV9@jpjVA9P9wO0hgBpD5cOeiyP//DXUMdQyA0BAJGgAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of my Brachylog solution.</p> | |
<pre><code>Œg Partition into runs of consecutive equal elements. | |
ŒṖ Generate every partition of the runs, | |
Ẏ€€ and concatenate the runs in each slice. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8? 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ṛ/ȧÆr,N+AƲƇ | |
</code></pre> | |
<p>A monadic Link that accepts a list of the coefficients (<code>[d,c,b,a]</code>) and yields a list of the (one or three) real roots, unless <code>a</code> is zero in which case it yields an empty list.</p> | |
<p><strong><a href=""https://tio.run/##ASYA2f9qZWxsef//4bmbL8inw4ZyLE7Ei0HGssaH////Wy0xLDAsMywxXQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hztn6J5YfbivS8TvS7Xhs07H2/4fbj056uHOGZuT//9HRuoY6BjrGOoaxXDrRhjpgCGJa6JjoGEGYBjogCFcA5ICYYH2GIHYsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<p>...<span class=""math-container"">\$8\$</span> bytes if we can handle <code>a</code> being zero (in which case it works for all polynomials):</p> | |
<pre><code>Ær,NċAƲƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wW5GO35Fux2ObjrX///8/WtdQx0DHWMcwFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h3>How?</h3> | |
<p>The heavy lifting is done by a built-in...</p> | |
<pre><code>ṛ/ȧÆr,N+AƲƇ - Link: coefficients, P = [d,b,c,a] | |
/ - reduce (P) by: | |
ṛ - right | |
-> a | |
Ær - polynomial roots (of P) | |
ȧ - logical AND | |
-> [d,c,b,a] or 0 | |
Ƈ - keep those for which (with 0, keep those of range(0)=[]): | |
Ʋ - last four links as a monad - f(x): | |
N - negate (x) | |
, - (P) paired with (that) | |
A - absolute value (of x) | |
ċ - count occurrences (of that in the pair) | |
-> Truthy (1 or 2*) if x is real, falsey (0) if not | |
* when x=0 | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ITŒP‘œṖ€ | |
</code></pre> | |
<p>A monadic Link that accepts a list of ones and zeros and yields a list of the valid partitions.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/98z5OikgEcNM45Ofrhz2qOmNf8Ptx@d9HDnDCAz8v//aEMdQx0DIDREggaxAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ITŒP‘œṖ€ - Link: list, B e.g. [0, 0, 1, 1, 0, 1] | |
I - deltas (of B) [ 0, 1, 0,-1, 1] | |
T - truthy indices [ 2, 4, 5] | |
ŒP - powerset [[],[2],[4],[5],[2,4],[2,5],[4,5],[2,4,5]] | |
‘ - increment [[],[3],[5],[6],[3,5],[3,6],[5,6],[3,5,6]] | |
€ - for each: | |
œṖ - partition (B) at [[[0,0,1,1,0,1]],[[0,0],[1,1,0,1]],[[0,0,1,1],[0,1]],[[0,0,1,1,0],[1]],[[0,0],[1,1],[0,1]],[[0,0],[1,1,0],[1]],[[0,0,1,1],[0],[1]],[[0,0],[1,1],[0],[1]]] | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>142D;Ṛ;¬K”P; | |
</code></pre> | |
<p>A full program that outputs a PBM file on STD OUT.</p> | |
<p><strong><a href=""https://tio.run/##AUAAv/9qZWxsef//MTQyRDvhuZo7wqxL4oCdUDv/MuG4tuG5lzTCtcOH4oG@IiJqLEDFkuG5mGrigJwgLT4g4oCdKVn/"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Jelly cannot produce images on screen, so this places an image file content on STD OUT ready to be directed to a file.</p> | |
<p>The PBM format idea came from <a href=""https://codegolf.stackexchange.com/users/11261/jordan"">Jordan</a>'s <a href=""https://codegolf.stackexchange.com/a/252279/53748"">Goruby</a> and <a href=""https://codegolf.stackexchange.com/a/252278/53748"">Ruby</a> posts. Go upvote!</p> | |
<p>The method is similar to <a href=""https://codegolf.stackexchange.com/users/36398/luis-mendo"">Luis Meno</a>'s <a href=""https://codegolf.stackexchange.com/a/252262/53748"">MATL</a> post, because there is nothing simpler. Go upvote!</p> | |
<p>The only difference is that rather than the number on top of the reversed negated number we have the reverse of the number on top of the negated number.</p> | |
<pre><code>142D;Ṛ;¬K”P; - Main Link: list of four bits, N e.g. [0,0,1,0] | |
142 - 142 | |
D - to decimal digits -> [1, 4, 2] | |
Ṛ - reverse (N) [0,1,0,0] | |
; - concatenate [1,4,2,0,1,0,0] | |
¬ - logical NOT (N) [1,1,0,1] | |
; - concatenate [1,4,2,0,1,0,0,1,1,0,1] | |
K - join with spaces [1,' ',4,' ',2,' ',0,' ',1,' ',0,' ',0,' ',1,' ',1,' ',0,' ',1] | |
”P - 'P' | |
; - concatenate ['P',1,' ',4,' ',2,' ',0,' ',1,' ',0,' ',0,' ',1,' ',1,' ',0,' ',1] | |
- implicit, smashing print P1 4 2 0 1 0 0 1 1 0 1 | |
i.e. the pixels: | |
0100 | |
1101 | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 9 </s> 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-1 by taking the exhaust velocity in 10<sup>th</sup>s - thanks <a href=""https://codegolf.stackexchange.com/users/52210/kevin-cruijssen"">Kevin Cruijssen</a>!</p> | |
<pre><code>112÷Æe’× | |
</code></pre> | |
<p>A dyadic Link that accepts the exhaust velocity on the left, in tenths, and the mass on the right and yields the fuel mass.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/Q0Ojw9sNtqY8aZh6e/v//fyOT/4YGBgAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>112÷Æe’× - Link: number v, number m | |
112 - 112 | |
÷ - divide by v | |
Æe - Exp(that) | |
’ - decrement | |
× - multiply by m | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>5</s> 4 bytes</h1> | |
<pre><code>0ḟ1# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/g4Y75hsr/D7c/alrz/380F2e0YawOkDQAk0Y6ChCGsY6CIZANJoFsY7AgmAAKGMEETHUUTMBKIAwLsBScC9RtDkQw8yBSEOMNYGZDTIMbaAjTZQa21hCkwhSsyhKiCmY8hG0CVmgBMckilisWAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Doesn't use the bounds on the input.</p> | |
<p>...am I missing something?</p> | |
<pre><code>0 Starting with 0, | |
1# find the first integer | |
ḟ which is not in the input. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 12 </s> 11 <a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>B€æcþ`Ḃċ€BT | |
</code></pre> | |
<p>A monadic Link that accepts an integer and yields a list of integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/pUdOaw8uSD@9LeLij6Ug3kOcU8v//f2NLAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/pUdOaw8uSD@9LeLij6Ug3kOcU8l/ncPvRSQ93zlDx1oz8/99Ix0THVMdMx8hUx9hSx8RIx9DAAAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a> (reduced set as code is slow).</p> | |
<h3>How?</h3> | |
<pre><code>B€æcþ`Ḃċ€BT - Link: integer, n | |
€ - for each i in [1,n]: | |
B - convert to binary | |
` - use as both arguments of: | |
þ - table with: | |
æc - convolution | |
Ḃ - modulo 2 (vectorises) | |
B - convert n to binary | |
€ - for each row in the table: | |
ċ - count occurrences (of n in binary) | |
T - truthy indices | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>7</s> 6 bytes</h1> | |
<pre><code>Bæc/ḂḄ | |
</code></pre> | |
<p><a href=""https://tio.run/##DcwxCgIxEAXQfk7xWysziZmY1kMI1mIjewFLF0HwIBZiJStEtHLBe8xeZJzu8/j/73dddzBbjdftXFuv7WT6Hr5PbY/11N/1dZuOn/H8u8w2ZgGMQIyISBXBs7gIJSRkisjgQAUVkogTmMGxkGvBMhMv4Fj8oPqKK0nyopvkPw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 thanks to Jonathan Allan</em></p> | |
<p>Takes a list of <code>[a, b]</code>. (The dyadic equivalent is the very fun-looking <code>BæcḂḄɓB</code>.)</p> | |
<pre><code>B Convert a and b to their binary digits, | |
æc/ and convolve them. | |
Ḃ Take each mod 2 | |
Ḅ and convert from binary. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 37 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“ḲṚẉċ‘ḤD“feg”żⱮ;Ṛ€$“1.““2.“Qh4#”żⱮK€Y | |
</code></pre> | |
<p>A full program that prints the eight games.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw5yHOzY93Dnr4a7OI92PGmY83LHEBSiYlpr@qGHu0T2PNq6zBso@alqjAhQ11AMSQGQEogMzTJRharyBCiL//wcA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<pre><code>“ḲṚẉċ‘ḤD“feg”żⱮ;Ṛ€$“1.““2.“Qh4#”żⱮK€Y - Main Link: no arguments | |
“ḲṚẉċ‘ - code-page indices = [177,182,227,232] | |
Ḥ - double -> [354,364,454,464] | |
D - decimal digits -> [[3,5,4],[3,6,4],[4,5,4],[4,6,4]] | |
“feg” - "feg" | |
żⱮ - map with zip -> [[['f',3],['e',5],['g',4]],[['f',3],['e',6],['g',4]],[['f',4],['e',5],['g',4]],[['f',4],['e',6],['g',4]]] | |
$ - last two links as a monad: | |
Ṛ€ - reverse each -> [[['g',4],['e',5],['f',3]],[['g',4],['e',6],['f',3]],[['g',4],['e',5],['f',4]],[['g',4],['e',6],['f',4]]] | |
; - concatenate -> [[['f',3],['e',5],['g',4]],[['f',3],['e',6],['g',4]],[['f',4],['e',5],['g',4]],[['f',4],['e',6],['g',4]],[['g',4],['e',5],['f',3]],[['g',4],['e',6],['f',3]],[['g',4],['e',5],['f',4]],[['g',4],['e',6],['f',4]]] | |
“1.““2.“Qh4#” - ["1.","","2.","Qh4#"] | |
żⱮ - map with zip -> [[["1.",['f',3]],[[],['e',5]],["2.",['g',4]],["Qh4#"]],[["1.",['f',3]],[[],['e',6]],["2.",['g',4]],["Qh4#"]],[["1.",['f',4]],[[],['e',5]],["2.",['g',4]],["Qh4#"]],[["1.",['f',4]],[[],['e',6]],["2.",['g',4]],["Qh4#"]],[["1.",['g',4]],[[],['e',5]],["2.",['f',3]],["Qh4#"]],[["1.",['g',4]],[[],['e',6]],["2.",['f',3]],["Qh4#"]],[["1.",['g',4]],[[],['e',5]],["2.",['f',4]],["Qh4#"]],[["1.",['g',4]],[[],['e',6]],["2.",['f',4]],["Qh4#"]]] | |
K€ - space-join each -> [["1.",['f',3],' ',[],['e',5],' ',"2.",['g',4],' ',"Qh4#"],["1.",['f',3],' ',[],['e',6],' ',"2.",['g',4],' ',"Qh4#"],["1.",['f',4],' ',[],['e',5],' ',"2.",['g',4],' ',"Qh4#"],["1.",['f',4],' ',[],['e',6],' ',"2.",['g',4],' ',"Qh4#"],["1.",['g',4],' ',[],['e',5],' ',"2.",['f',3],' ',"Qh4#"],["1.",['g',4],' ',[],['e',6],' ',"2.",['f',3],' ',"Qh4#"],["1.",['g',4],' ',[],['e',5],' ',"2.",['f',4],' ',"Qh4#"],["1.",['g',4],' ',[],['e',6],' ',"2.",['f',4],' ',"Qh4#"]] | |
Y - newline-join -> ["1.",['f',3],' ',[],['e',5],' ',"2.",['g',4],' ',"Qh4#",'\n',"1.",['f',3],' ',[],['e',6],' ',"2.",['g',4],' ',"Qh4#",'\n',"1.",['f',4],' ',[],['e',5],' ',"2.",['g',4],' ',"Qh4#",'\n',"1.",['f',4],' ',[],['e',6],' ',"2.",['g',4],' ',"Qh4#",'\n',"1.",['g',4],' ',[],['e',5],' ',"2.",['f',3],' ',"Qh4#",'\n',"1.",['g',4],' ',[],['e',6],' ',"2.",['f',3],' ',"Qh4#",'\n',"1.",['g',4],' ',[],['e',5],' ',"2.",['f',4],' ',"Qh4#",'\n',"1.",['g',4],' ',[],['e',6],' ',"2.",['f',4],' ',"Qh4#"] | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 12 </s> 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-1 by delaying the mod-2 check like <a href=""https://codegolf.stackexchange.com/users/52210/kevin-cruijssen"">Kevin Cruijssen</a>'s <a href=""https://codegolf.stackexchange.com/a/252128/53748"">05AB1E answer</a>.</p> | |
<pre><code>ŒṗŒ!€ẎQṀ€ḂS | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer and yields the number of compositions with an odd largest part.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opIc7px@dpPioac3DXX2BD3c2gFg7moL///9vAQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (Slow - <a href=""https://tio.run/##y0rNyan8///opIc7pz/c0fRw5yqVY@1HJyk@alrzcFdfoM9/y8PtQPZ/AA"" rel=""nofollow noreferrer""><span class=""math-container"">\$9\$</span> within <span class=""math-container"">\$1\$</span> minute on TIO</a>)</p> | |
<p>Or, a faster version which can do all <span class=""math-container"">\$33\$</span> in <a href=""https://tio.run/##ASoA1f9qZWxsef//xZLhuZfCtUw7xZLJoCE6L8OX4biC4bmqKVP/MzPDh@KCrP8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">under <span class=""math-container"">\$12\$</span> seconds on TIO</a> in <span class=""math-container"">\$15\$</span> bytes (slightly slower than the <span class=""math-container"">\$16\$</span> byte version in the history of edits):</p> | |
<pre><code>ŒṗµL;Œɠ!:/×ḂṪ)S | |
</code></pre> | |
<h3>How?</h3> | |
<p>The slow one:</p> | |
<pre><code>ŒṗŒ!€ẎQṀ€ḂS - Link: positive integer, n e.g. 5 | |
Œṗ - integer partitions [[1,1,1,1,1],[1,1,1,2],[1,1,3],[1,2,2],[1,4],[2,3],[5]] | |
Œ!€ - all permutations of each [[[1,1,1,1,1],[1,1,1,1,1],...],[[1,1,3],[1,3,1],[1,1,3],[1,3,1],[3,1,1],[3,1,1]],...,[[5]] | |
Ẏ - tighten [[1,1,1,1,1],[1,1,1,1,1],...,[1,1,3],[1,3,1],[1,1,3],[1,3,1],[3,1,1],[3,1,1],...,[5]] | |
Q - deduplicate [[1,1,1,1,1],...,[1,1,3],[1,3,1],[3,1,1],...,[5]] | |
Ṁ€ - maximum of each [1,2,2,2,2,3,3,3,2,2,2,4,4,3,3,5] | |
Ḃ - modulo 2 [1,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1] | |
S - sum 7 | |
</code></pre> | |
<p>The faster version calculates the number of distinct permutations for each partition and sums them up instead:</p> | |
<pre><code>ŒṗµL;Œɠ!:/×ḂṪ)S - Link: positive integer, n | |
Œṗ - all partitions | |
(note: each are always in sorted order) | |
µ ) - for each: e.g. part = [2,2,2,4,5,5] | |
L - length 6 | |
Œɠ - run-lengths [3,1,2] | |
; - concatenate [6,3,1,2] | |
! - factorial [720,6,1,2] | |
/ - reduce by: | |
: - integer division 60 | |
Ḃ - (part) modulo 2 [0,0,0,0,1,1] | |
× - multiply [0,0,0,0,60,60] | |
Ṫ - tail 60 | |
S - sum | |
</code></pre> | |
" | |
"106844","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, <s>9</s> 8 bytes</h1> | |
<pre><code>ṙLHĊƊṚŒḌ | |
</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6Fpt8PI50cT3cOfNw-8Ods45OerijZ0lxUnIxVPpmYbRSdLRprI5CtImOgqEBiGGso2AJZIMFjXQULIBsoJwRWM5QR8EcyAcqMQSqMQKrMQNygOoMgQqNTMCKgKoMgcqMjME8oLyREdgww9hYpViozQA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>How?</p> | |
<pre><code>ṙLHĊƊṚŒḌ : Main Link | |
L : length; used to count the number of elements | |
H : Halve; divides by 2 | |
Ċ : Rounds up (ceil) | |
Ɗ : Last three links as a monad | |
ṙ : Rotate x y times (x is implied input) | |
Ṛ : Reverse element | |
ŒḌ : Reconstruct matrix from its diagonals | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>RḤ’4÷Ṛḅ- | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer, <span class=""math-container"">\$n\$</span>, and yields a floating point number, <span class=""math-container"">\$\pi_n\$</span>.</p> | |
<p><strong><a href=""https://tio.run/##ARwA4/9qZWxsef//UuG4pOKAmTTDt@G5muG4hS3///8z"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>RḤ’4÷Ṛḅ- - Link: positive integer, n | |
R - range n -> [1,2,3,...,n] | |
Ḥ - double -> [2,4,6,...,2n] | |
’ - decrement -> [1,3,5,...,2n-1] | |
4 - 4 | |
÷ - divide -> [4/1,4/3,4/5,...,4/(2n-1)] | |
Ṛ - reverse -> [4/(2n-1),...,4/5,4/3,4/1] | |
- - -1 | |
ḅ - convert from base -> (-1)^(n-1)*4/(2n-1)+...+1*4/5+-1*4/3+1*4/1 = pi_n | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 25 23 </s> 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>⁽£4;“1/½+¿|?4‘Ä<⁸SḂ⁻¡3 | |
</code></pre> | |
<p>A monadic Link that accepts an integer in <span class=""math-container"">\$[927,2022]\$</span> and yields:</p> | |
<ul> | |
<li><span class=""math-container"">\$0\$</span> if there was a king on the throne at any point during the year (except for Charles III (2022));</li> | |
<li><span class=""math-container"">\$3\$</span> if neither a king nor queen reigned; or</li> | |
<li><span class=""math-container"">\$1\$</span> otherwise (if a queen and only a queen reigned all year or Charles III succeeded (2022)).</li> | |
</ul> | |
<p><strong><a href=""https://tio.run/##ATUAyv9qZWxsef//4oG9wqM0O@KAnDEvwr0rwr98PzTigJjDhDzigbhT4biC4oG7wqEz////MTY1MA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see <a href=""https://tio.run/##AUYAuf9qZWxsef//4oG9wqM0O@KAnDEvwr0rwr98PzTigJjDhDzigbhT4biC4oG7wqEz/yzDhylH//9yYW5nZSg5MjcsIDIwMjMp"" rel=""noreferrer"" title=""Jelly – Try It Online"">all years</a>.</p> | |
<h3>How?</h3> | |
<pre><code>⁽£4;“1/½+¿|?4‘Ä<⁸SḂ⁻¡3 - Link: integer, Y | |
⁽£4 - 1553 | |
“1/½+¿|?4E‘ - code-page indices = [49,47,10,43,11,124,63,52] | |
; - concatenate -> [1553,49,47,10,43,11,124,63,52] | |
Ä - accumulate -> [1553,1602,1649,1659,1702,1713,1837,1900,1952] | |
<⁸ - less than Y? (vectorises) | |
S - sum -> S | |
¡ - repeat... | |
⁻ 3 - ...number of times: not equal to three | |
(leave as 3 when no monarch) | |
Ḃ - ...action: mod 2 | |
-> 0 if a king during the year except 2022; or | |
1 otherwise | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>BḌRDḄċ | |
</code></pre> | |
<p><a href=""https://tio.run/##AS0A0v9qZWxsef//QuG4jFJE4biExIv/LMOHxZLhuZgkauKAnCAtPiDigJ0pWf//MzA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<p>For the input <span class=""math-container"">\$x\$</span>, we generate the range <span class=""math-container"">\$[1, n]\$</span>, where <span class=""math-container"">\$n\$</span> is the binary representation of <span class=""math-container"">\$x\$</span>, treated as decimal. For example: <span class=""math-container"">\$x = 3\$</span> yields <span class=""math-container"">\$n = 11\$</span> and <span class=""math-container"">\$x = 6\$</span> yields <span class=""math-container"">\$n = 110\$</span>. We then convert each number in this range to its decimal digits, convert them back to binary, and count the occurrences of <span class=""math-container"">\$x\$</span>.</p> | |
<p>We use the fact that Jelly's base converter doesn't care about the digit values, and simply sums up <span class=""math-container"">\$a \times b^n\$</span> for digit <span class=""math-container"">\$a\$</span>, base <span class=""math-container"">\$b\$</span> and position <span class=""math-container"">\$n\$</span>.</p> | |
<pre><code>BḌRDḄċ - Main link. Takes x on the left | |
B - Convert x to binary | |
Ḍ - Treat this binary representation as a base 10 number, n | |
R - Range from 1 to n | |
D - Convert each to digits | |
Ḅ - Convert the digits to binary | |
ċ - Count occurrences of x | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>RḤrƝP€4÷Ṛḅ-+3 | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer and yields the approximation (up to the floating point accuracy).</p> | |
<p><strong><a href=""https://tio.run/##ASIA3f9qZWxsef//UuG4pHLGnVDigqw0w7fhuZrhuIUtKzP///80"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>RḤrƝP€4÷Ṛḅ-+3 - Link: positive integer, n e.g. 4 | |
R - range [1,2,3,4] | |
Ḥ - double [2,4,6,8] | |
Ɲ - for neighbours: | |
r - inclusive range [[2,3,4],[4,5,6],[6,7,8]] | |
P€ - product of each [24,120,336] | |
4÷ - four divided by those [1/6,1/30,1/84] | |
Ṛ - reverse [1/84,1/30,1/6] | |
ḅ- - convert from base -1 sum([1/84,-1/30,1/6])=0.14523809523809522 | |
+3 - add three 3.14523809523809522 | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 24 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ON%7’»0_2¦€4ḋ10,3Æm+.Ḟ÷⁵ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of characters and yields a number.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/fT9X8UcPMQ7sN4o0OLXvUtMbk4Y5uQwMd48Ntudp6D3fMO7z9UePW/4fbgVL//0dHqzuqx3LpRKu7qesowAiwgIs2iOOiC@E5gjhOIMIZLAwV1QULg0lnXQz1UGltuF4nFNPA4o5QvWBxZ7CQM5KENrr1cCfGAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ON%7’»0_2¦€4ḋ10,3Æm+.Ḟ÷⁵ - Link: list of grades e.g. ['A-', 'B+', 'F', 'F'] | |
O - ordinals (vectorises) [[65, 45], [66, 43], [70], [70]] | |
N - negate [[-65, -45], [-66, -43], [-70], [-70]] | |
%7 - mod seven [[5, 4], [4, 6], [0], [0]] | |
’ - decrement [[4, 3], [3, 5], [-1], [-1]] | |
»0 - max with zero [[4, 3], [3, 5], [0], [0]] | |
2¦€ - from 2nd of each: | |
_ 4 - subtract four [[4, -1], [3, 1], [0], [0]] | |
ḋ10,3 - dot product with [10,3] [37, 33, 0, 0] | |
Æm - mean 17.5 | |
+. - add a half 18.0 | |
Ḟ - floor 18 | |
÷⁵ - divide by ten 1.8 | |
</code></pre> | |
<hr /> | |
<p>If banker's rounding was used <span class=""math-container"">\$21\$</span> bytes is possible with <code>ON%7’»0_2¦€4Uḅ.3Æmær1</code> (<code>U</code> reverses each, <code>ḅ.3</code> converts from base <span class=""math-container"">\$0.3\$</span>, and <code>ær1</code> uses Python's <code>round</code> to round to 1 decimal place).</p> | |
" | |
"106844","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 65 bytes</h1> | |
<pre><code>“⁾ḋḷ?D8=ƙʂȤ£²^ĖẸI)¡e[µ°⁾ṢJ*MĠɓ¤Ḃġ⁽vEEɲạ®G{(ŀ³⁻¹ƭTẸⱮ’ṃ“ȥ3’Ọ | |
Øaż¢Fy | |
</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FjfrHzXMedS47-GO7oc7ttu7WNgem3mq6cSSQ4sPbYo7Mu3hrh2emocWpkYf2npoA0jZzkVeWr5HFpycfGjJwx1NRxY-atxb5up6ctPDXQsPrXOv1jjacGjzo8bdh3YeWxsC1Pxo47pHDTMf7mwG2nJiqTGIvbuH6_CMxKN7Di1yqwRKLylOSi6GOmZ9tJIH0HH5CuH5RTkpSrFQYQA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<pre><code>“⁾ḋḷ?D8=ƙʂȤ£²^ĖẸI)¡e[µ°⁾ṢJ*MĠɓ¤Ḃġ⁽vEEɲạ®G{(ŀ³⁻¹ƭTẸⱮ’ṃ“ȥ3’Ọ : Link 1 | |
“⁾ḋḷ?D8=ƙʂȤ£²^ĖẸI)¡e[µ°⁾ṢJ*MĠɓ¤Ḃġ⁽vEEɲạ®G{(ŀ³⁻¹ƭTẸⱮ’ : Compressed integer for 454193002670633612531343815167055208136573147142298478503419521655224802790872780438775790455172058745698867697958481400 | |
“ȥ3’ : Compressed integer for 42802 | |
ṃ : Base decompression; convert x to base length(y) then index into y; results in character codes | |
Ọ : Cast to characters | |
Øaż¢Fy : Main Link | |
Øa : Lowercase alphabet | |
¢ : Last link as a nilad | |
ż : Zip; interleave x and y | |
F : Flatten list | |
y : Translate the elements of y according to the mapping in x; change the characters | |
</code></pre> | |
<p>Integers used to get the character codes borrowed from <a href=""https://codegolf.stackexchange.com/users/92689/steffan"">Steffan's</a> <a href=""https://codegolf.stackexchange.com/a/248389/106844"">Vyxal Answer</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 21 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>WZ€ị®ẎƊ⁸©L*3¤Ð¡ẎZ€ẎEƇ | |
</code></pre> | |
<p>A monadic Link that accepts a 1-indexed list of nodes, each of which is a pair of positive integers identifying the nodes pointed to by each of the two transition characters (i.e. like the test cases in the question but incremented by one) and yields an empty list (falsey) if no synchronising word exists or a non-empty list (truthy) if one does.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z886lHTmoe7uw@te7ir71jXo8Ydh1b6aBkfWnJ4wqGFQCGw9K4@12Pt////j4421FEwitVRgNCxAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong><br /> | |
...Too slow for the length 5 and greater tests, but since all of those that do have synchronising words are much shorter <a href=""https://tio.run/##dVExS8QwGN3vV2RwESK0TZqmCDq5uYuGDg7nIJ1OHdyqy4HCIU4ddBBcBHHWc@vh/Y/mj9Q0fUl6gtP35eV97718OZ@W5XXXHZ3o2/f2@775aJeL9Z2@@WzeDnVVN6@rh@bFYPZ@uThYz7ufx/ar3tXVE9nZI7p67tvL2dXUtKY7K08vhrZezbf2t4@7TikVURIXlAy1mFCl4oBEA2I7g8SewwOHea5TMZX3uGUmQBglHAxbk7GC0/yfsZFHUpICkWN3gyeYFH1NcWbgZVCScGBeMQdTBm/rICjJgduaA@dw5JgzCTKf2SqmYDDcOIc87FKOHQWUM7w6CRmFV3S7dZliVIEJBoVofE5x7@Yy/2oBhvvx7E8GHrbgFNxeN/7UZi0mxS8"" rel=""nofollow noreferrer"">this</a>, which searches only up to length <span class=""math-container"">\$n+2\$</span> gives the correct output for all test cases.</p> | |
<h3>How?</h3> | |
<p>Full brute force - generates the list of nodes (by starting node) pointed to by all words from length one up to length <span class=""math-container"">\$n^3+1\$</span> (more than the current known upper bound) and keeps any that are all equal.</p> | |
<pre><code>WZ€ị®ẎƊ⁸©L*3¤Ð¡ẎZ€ẎEƇ - Link: list of pairs of integers, A | |
W - wrap A in a list | |
С - collect and repeat... (includes the original wrapped A) | |
¤ - ...number of times: nilad followed by links as a nilad: | |
⁸ - chain's left argument = A | |
© - (copy to the register) | |
L - length | |
*3 - to the third power | |
Ɗ - ...action: last three links as a monad: | |
Z€ - transpose each | |
ị® - index into the register | |
Ẏ - tighten | |
Ẏ - tighten | |
Z€ - transpose each | |
Ẏ - tighten | |
Ƈ - keep those for which: | |
E - all equal? (i.e. all point to the same node) | |
</code></pre> | |
<hr /> | |
<p><strong>20 bytes</strong> if a full program can output nothing if no synchronising word exists or a (not consistent) list representation if one does - uses the same method:</p> | |
<pre><code>WZ€ị³ẎƊ³L*3¤Ð¡ẎZ€ẎEƇ | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>m0;w13Ƥ“"ṁĿ4ṘṘ»Ṃ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields <code>1</code> if constructible or <code>0</code> if not.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/XwLrc0PjYkkcNc5Qe7mw8st/k4c4ZQHRo98OdTf8f7t5ydM/h9kdNa1S8gUTk//8lpSW6QMwFpZHZqDwsCrFrwNSKEMdiCFYJXAZWcMEUcUGUQzUh662AG8JVATcWyXwUm9As5cLuRoQSTEciPInhBYxgQPYLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>The input must (a) start with <code>tut-tut</code>, (b) end with <code>tut-tut</code>, and (c) have <code>tut-tut</code> as a contiguous substring of all of its length <span class=""math-container"">\$13\$</span> slices. We can, however, just test that (c) holds for the input concatenated with its reverse concatenated with the input (e.g. <code>abc</code> -> <code>abccbaabc</code>). This works since <code>tut-tut</code> is palindromic and any bad starts or bad ends in the input will now nest between any <code>tut-tut</code>s.</p> | |
<pre><code>m0;w13Ƥ“"ṁĿ4ṘṘ»Ṃ - Link: list of characters, S e.g. "abc" | |
m0 - reflect -> "abccba" | |
; - concatenate -> "abccbaabc" | |
Ƥ - for infixes... | |
13 - ...of length 13: | |
w “"ṁĿ4ṘṘ» - first 1-indexed index of "tut-tut" or 0 if not found | |
Ṃ - minimum (an empty list yields 0) | |
</code></pre> | |
<hr /> | |
<p>Bit of a shame it takes half the code to make "tut-tut"!</p> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>⁼þ⁼ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9R457D@4DE/8Ptj5rW/P8fHR1tqKNgAEGxOgrRQNoQhQcVQPBAArEgLkinIUIWHw9dJ6otGC7AZqcBsk5DJIVIqlCUIBQawkxEEkCIoboWXcAQbixGsBjgsNkAq@NQwgwpqJFdGBsbCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>another port of Command Master's 05AB1E answer, so takes an adjacency matrix as input</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 11 </s> 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Followed <a href=""https://codegolf.stackexchange.com/users/81203/att"">att</a>'s description in their <a href=""https://codegolf.stackexchange.com/a/251711/53748"">Mathematica answer</a>.</p> | |
<pre><code>_µ0+⁵ọẠʋ1# | |
</code></pre> | |
<p>A full program that accepts <code>g</code>, <code>d</code>, <code>i</code> and prints the result.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/@0FYD7UeNWx/u7n24a8GpbkPl////axgZ6BgZaP7XMDTQMQVROoaaAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>_µ0+⁵ọẠʋ1# - Main Link: grid-dimensions (g), DVD-dimensions (d) | |
_ - g subtract d (vectorises) | |
µ - start a new monadic chain - f(g-d) | |
0 - set the left argument "Step" to 0 (right argument is g-d by default) | |
# - count up and find... | |
1 - ...the first truthy result of: | |
ʋ - last four links as a dyad - f(Step, g-d): | |
⁵ - program's third argument -> initial-state (i) | |
+ - add to Step (vectorises) | |
ọ - multiplicity (vectorises) (number of times each Step+i value | |
divides the respective g-d value) | |
Ạ - all? (are both non-zero?) | |
- implicit print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Œṗḍ⁵ẠƇL | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer and yields a positive integer.</p> | |
<p><strong><a href=""https://tio.run/##ASIA3f9qZWxsef//xZLhuZfhuI3igbXhuqDGh0z/LMOHKUf//zI1"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Œṗḍ⁵ẠƇL - Link: integer, Cents e.g. 4 | |
Œṗ - integer partitions of Cents [[1,1,1,1],[1,1,2],[1,3],[2,2],[4]] | |
⁵ - ten 10 | |
ḍ - divides? (vectorises) [[1,1,1,1],[1,1,1],[1,0],[1,1],[0]] | |
Ƈ - keep those for which: | |
Ạ - all? [[1,1,1,1],[1,1,1], [1,1] ] | |
L - length 3 | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>Dç/$ƬL’ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8f3j6f5fDy/VVjq3xedQw8////2YWFhaWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes a function from the previous line and a number from an argument.</p> | |
<pre><code>Dç/$ Convert an integer to its decimal digits and reduce by the input function | |
Ƭ Repeat and collect the results until the results are not unique | |
(repeats after reaching a single digit number) | |
L’ Get its length minus 1 | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>&‘<Ẓø#Ṫ | |
</code></pre> | |
<p><a href=""https://tio.run/##ARkA5v9qZWxsef//JuKAmDzhupLDuCPhuar///80"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> # Count up the first n matches | |
Ṫ then take the last | |
ø starting from 0: | |
& Is the candidate bitwise AND | |
‘ itself + 1 | |
< less than | |
Ẓ whether or not it's prime? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒṗL)S | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opIc7p/toBv///98UAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<hr /> | |
<p>Or</p> | |
<pre><code>Œṗ€ẎL | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>œṖ€DḌ§⁸%S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o5Ic7pz1qWuPycEfPoeWPGneoBv8/3K4Z@f@/obGOgqGhIZgAkUbGJjoKJsZGhgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Times out on most of the test cases, but agrees with existing solutions on smaller ones. The equivalent <code>DLœṖ€DḌ§⁸%S</code> (for 11 bytes) is <a href=""https://tio.run/##y0rNyan8/9/F5@jkhzunPWpa4/JwR8@h5Y8ad6gG/z/crhn5/7@JuYWpkY6CoTEQGxoCCSNjE1MdBVMTYyMgz9jcyNLQwNTE3AgA"" rel=""nofollow noreferrer"">considerably faster</a>.</p> | |
<pre><code>œṖ Partition | |
D the digits of n | |
€ at each [1 .. n], individually. | |
Ḍ Convert each digit slice in each partition back from digits. | |
§ Sum each partition, | |
⁸% take n mod each sum, | |
S and sum the sums. | |
</code></pre> | |
<p>Generates a large number of extra partitions all of which sum back to the original <span class=""math-container"">\$n\$</span>, which don't affect the final sum because <span class=""math-container"">\$n \mod n = n\$</span>.</p> | |
" | |
"21775","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>15</s> 13 bytes (thanks @Jonathan Allan!)</h1> | |
<pre><code>OH+53œ?@ƒ5FṢƑ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/fQ9vU@Ohke4djk0zdHu5cdGzi////g4J8IAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>OH+53œ?@ƒ5FṢƑ | |
O ord() the input list (vectorizes) | |
H Divide by 2 (vectorizes) | |
+ Add... | |
53 ...53 (all these steps vectorize) | |
ƒ Reduce the input list with: | |
@ The preceding dyadic link, with its arguments swapped: | |
œ? The nth permutation of the right argument | |
...using the following as the starting value for the reduce: | |
5 5 (which gets implicitly converted to [1,2,3,4,5] by œ?) | |
F Flatten (wraps 5 into [5] in case the input list is empty) | |
Ƒ Check if the output of the previous link is equal to its left argument: | |
Ṣ Sort the output list | |
(The last two bytes effectively check if the list is already in sorted order.) | |
</code></pre> | |
<p>Uses essentially the same logic as <a href=""https://codegolf.stackexchange.com/a/251541/21775"">@xnor's answer</a>. The two permutations I used were <code>45231</code> and <code>45123</code>, since their indices (94 and 91, respectively) can be easily computed from the <code>ord</code> values of 'R' and 'L' (82 and 76, respectively): divide by 2 and add 53. I wrote a Python script to check all valid pairs of permutations to find the optimal ones (in terms of how many bytes are needed to calculate their indices from 82 and 76), and no other permutations were better than these.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>߀ŒḊ⁺Ḋ$?P | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///w/EdNa45Oerij61HjLiCpYh/w/3C7ZuT//9GxOgrRhjpGOsY6ZiAmiB2rA6RiQaQZiIgFApBMLERptFEsskKgEhOYAFgqOtoYJgQUiY0FAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/251421/85334"">ovs's BQN solution</a>.</p> | |
<pre><code> ŒḊ The depth of the argument (0 if integer) | |
? unless | |
⁺ the depth of the argument | |
Ḋ is greater than 1 (range [2 .. depth] is nonempty) | |
ß in which case recur | |
€ on each element | |
P and take the product of the results. | |
</code></pre> | |
" | |
"106844","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>OÄ÷T+.Ọ</code></pre> | |
<pre><code>OÄ÷T+.Ọ ~Main link | |
O ~Cast to number | |
Ä ~Cumulative sum; add the values | |
÷T ~Divide by indices | |
+. ~Add .5 | |
Ọ ~Cast to characters | |
</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6Fqv9D7cc3h6irfdwd8-S4qTkYqj4qmglD6C6fEWlWKgIAA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>⁹Æs;ÆdÆṣƑƲ1# | |
</code></pre> | |
<p>A full program that will (eventually!) print the result.</p> | |
<p><a href=""https://tio.run/##AR4A4f9qZWxsef//4oG5w4ZzO8OGZMOG4bmjxpHGsjEj//8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Don't Try it online!</a><br /> | |
The <code>⁹</code> starts the search at 256, if one replaces it with <code>1</code> it'll find <code>12</code> - try that <strong><a href=""https://tio.run/##y0rNyan8/9/wcFux9eG2lMNtD3cuPjbx2CZD5f//AQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">here</a></strong>.</p> | |
<hr /> | |
<p>Faster in 13:</p> | |
<pre><code>“;Y,’Æf2*×’$P | |
</code></pre> | |
<p>Try it <a href=""https://tio.run/##y0rNyan8//9RwxzrSJ1HDTMPt6UZaR2eDmSpBPz/DwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">here</a>.</p> | |
" | |
"92689","<h1><a href=""https://github.com/Vyxal/Vyxal"" rel=""nofollow noreferrer"">Vyxal</a>, <s>14</s> <s>13</s> 11 bytes</h1> | |
<pre><code>»;⟑L»ǐE:‹*Π | |
</code></pre> | |
<p><a href=""https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCuzvin5FMwrvHkEU64oC5Ks6gIiwiIiwiIl0="" rel=""nofollow noreferrer"">Try it Online!</a></p> | |
<p>-1 byte thanks to alephalpha and -2 bytes thanks to Mukundan314.</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>17</s> 16 bytes</h1> | |
<pre><code>“¤¦¬Œþ=‘2*’æ«21P | |
</code></pre> | |
<p><a href=""https://tio.run/##ASYA2f9qZWxsef//4oCcwqTCpsKsxZLDvj3igJgyKuKAmcOmwqsyMVD//w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 byte thanks to xnor.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 27 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>L‘2*’ṭƲf’iS{Ṗ | |
ŒPçƇµ;S2*_ṠP) | |
</code></pre> | |
<p>A monadic Link that accepts a list of distinct integers greater than <span class=""math-container"">\$1\$</span> and yields a list of the implied pseudo-sublime numbers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/nUcMMI61HDTMf7lx7bFMakJEZXP1w5zSuo5MCDi8/1n5oq3WwkVb8w50LAjT///8fbaSjYKyjYKqjYK6jYAhkGYJoS6CgoY6CGRBbANmGBiBBIyBhagQSNjCPBQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/nUcMMI61HDTMf7lx7bFMakJEZXP1w5zSuo5MCDi8/1n5oq3WwkVb8w50LAjT/6xxuPzrp4c4Zj5rWZD1qmKNga6fwqGGuZuT//9HRRrE60UY6xhBSxwRG65gDWTAaJGKqY65jaAoVNNUxQ3DBMsY6hkDSUsfYUMfMUMfCUsfQAMg3MtcxNQKKGJjHxgIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>L‘2*’ṭƲf’iS{Ṗ - Helper Link, valid subset?: Subset; L | |
L - length of Subset | |
‘ - increment -> p' | |
Ʋ - last four links as a monad - f(p'): | |
2 - two | |
* - exponentiate (p') | |
’ - decrement -> q' | |
ṭ - tack -> [p', q'] | |
f - filter keep only those of [p', q'] which are in L | |
We now have one of: []; [p']; [q']; or [p'=p, q'=q] | |
’ - decrement -> F (e.g. F=[p-1, q-1]) | |
{ - using left argument, Subset: | |
S - sum | |
i - first 1-indexed index of that sum in F or 0 if not found | |
Ṗ - pop (implicit range [1..that]) | |
This yields: | |
[] (falsey) when i resulted in 0 or 1; or | |
[1] (truthy) when i resulted in 2 (i.e. p'=p, q'=q, and q-1=sum) | |
ŒPçƇµ;S2*_ṠP) - Link, get pseudo-sublimes: set of integers > 1, L | |
ŒP - powerset of L -> all subsets we could make | |
Ƈ - filter-keep those for which: | |
ç - call the Helper Link - f(subset, L) | |
µ ) - for each: | |
e.g. [a, b, ..., n] | |
S - sum (Subset) a + b + ... + n = q-1 | |
; - concatenate -> [ a, b, ..., n, q-1 ] | |
2 - two | |
* - exponentiate -> [ 2^a, 2^b, ..., 2^n, 2^(q-1)] | |
Ṡ - sign (Subset)-> [ 1, 1, ..., 1] | |
_ - subtract -> [2^a-1, 2^b-1, ..., 2^n-1, 2^(q-1)] | |
P - product -> pseudo-sublime number | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>bUS%Uḅ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z8pNFg19OGO1v@Hl@trRv7/H80VHW1oYGCgo2BqbqajYGSso2AIRCaGsUDSKFYHjzRUFsjQUQCKmwDV6CgAFZnrKFjoKFgClRkAVZmgqjIFSxoCWUZAMWOQJlOgKtNYrlgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>b Convert each to base b | |
U reversed, | |
S sum corresponding digits, | |
% mod b, | |
U reverse back to big-endian, | |
ḅ convert from base b. | |
</code></pre> | |
<blockquote> | |
<p>a good example of why base-conversion builtins should be little-endian</p> | |
</blockquote> | |
<p>-- <a href=""https://chat.stackexchange.com/transcript/message/61848059#61848059"">ais523</a></p> | |
<p>Incidentally, having to reverse twice only costs one byte due to dyadic chaining rules requiring something between <code>%</code> and <code>ḅ</code> anyways, but in cases like this I'd have to agree that</p> | |
<blockquote> | |
<p>I like the monadic link rules, but not the dyadic link rules</p> | |
</blockquote> | |
<p>-- <a href=""https://chat.stackexchange.com/transcript/message/57320257#57320257"">ais523</a></p> | |
" | |
"21775","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>37</s> 36 bytes (thanks @Steffan!)</h1> | |
<pre><code>2*’ | |
§=⁹aÇP€×2*⁹¤ʋ | |
Ñe³ƊƇµ’³œcç"Ñ’$F¹Ƈ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/99I61HDTK5Dy20fNe5MPNwe8KhpzeHpQMHGnYeWnOrmOjwx9dDmY13H2g9tBao7tPno5OTDy5UOTwRyVNwO7TzW/v///2hjHQUTHQVTHQUzHQVzHQVD01gA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Also a mess.</p> | |
<p>Link 1: computes <span class=""math-container"">\$2^x-1\$</span></p> | |
<pre><code>2 Two | |
* To the power of the input | |
’ Decrement | |
</code></pre> | |
<p>Link 2: given a list of subsets of length <span class=""math-container"">\$p-1\$</span> of the input list, and <span class=""math-container"">\$q-1\$</span> (as defined in the question), return a list with all valid answers or 0.</p> | |
<pre><code>§=⁹aÇP€×2*⁹¤ʋ | |
§ Compute the sum of each sublist (vectorizes at depth 1) | |
= Check if equal to... (vectorizes) | |
⁹ ...q-1 | |
a Logical AND with... | |
ʋ ...the four previous links as a dyad | |
Ç The previous link as a monad (2^x-1 for each x in each subset) | |
€ For each subset: | |
P Compute the product | |
× Multiply by... | |
¤ ...a nilad followed by some links, as a nilad: | |
2 Two | |
* To the power of... | |
⁹ ...q-1 | |
</code></pre> | |
<p>Link 3 (main link): given the input list, outputs all valid answers.</p> | |
<pre><code>Ñe³ƊƇµ’³œcç"Ñ’$F¹Ƈ | |
Ƈ Filter the list using: | |
Ɗ The last three links as a monad | |
Ñ The next link as a monad (wraps around to link 1) | |
e Check if it's present in... | |
³ ...the input list | |
µ Start a new monadic chain | |
(At this point, the list contains all 'p' in the input list such that 2^p-1 is also in the input list.) | |
’ Decrement | |
œc All combinations of ... of any length in the list (vectorizes over the right argument) | |
³ The input list | |
" Zipping over the left and right arguments: | |
ç Call the previous link as a dyad, with the next link as the right argument | |
$ The last two links as a monad: | |
Ñ The next link (wraps around to link 1) on each valid 'p', thus generating all the candidates for 'q' | |
’ Decrement (thus generating all the candidates for q-1) | |
F Flatten | |
Ƈ Filter the list using: | |
¹ The truth value of each element itself (thus removing all falsy values from the list) | |
</code></pre> | |
" | |
"106844","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 2 bytes</h1> | |
<pre><code>xJ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/C6////yGpxSUKxSVFmXnpAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>i@ÞƑ | |
</code></pre> | |
<p><a href=""https://tio.run/##bYyxDcJAEATrQdpk//bs/cwBTVAAgS03QAXENEAzltzW8SIhYbKVZme77/ujal2O9/mq6/G83KoCppGEbUkRIUh9QEKpBFsop9kdOWYG2j9@GkF6/G1@K31uGR8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Semi-based on several of <a href=""https://codegolf.stackexchange.com/a/251235/85334"">DLosc's 5-byters</a>.</p> | |
<pre><code> Ƒ The input is not changed by | |
Þ sorting its elements by | |
i@ their first indices in the input. | |
</code></pre> | |
<p>Kind of like cutting the <code>F</code> out of <code>¹ƙ`F⁼</code>, but also kind of like cutting the <code>`ṢƑ</code> out of <code>iⱮ`ṢƑ.</code></p> | |
" | |
"16766","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>iⱮ`ṢƑ | |
</code></pre> | |
<p>Takes a list of integers. <a href=""https://tio.run/##y0rNyan8/z/z0cZ1CQ93Ljo28f///9EmOiY6llBoqGMYCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h3>Explanation</h3> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/251233/16766"">my BQN solution</a>.</p> | |
<pre><code>iⱮ`ṢƑ | |
i First index of right argument in left argument | |
Ɱ mapped over right argument | |
` using the single argument as both left and right arguments | |
Ƒ The result is equal to | |
Ṣ itself sorted | |
</code></pre> | |
<hr /> | |
<p>Here's some other 5-byte solutions (see also <a href=""https://codegolf.stackexchange.com/a/77617/16766"">Dennis's 5-byte solution</a>):</p> | |
<pre><code>ĠṢFṢƑ | |
Ġ Group indices by their value in the list | |
Ṣ Sort list of lists of indices | |
F Flatten | |
Ƒ The result is equal to | |
Ṣ itself sorted | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///Igoc7F7kB8bGJ////jzbRMdGxhEJDHcNYAA"" rel=""nofollow noreferrer"">Try it online!</a></p> | |
<pre><code>ĠṢF⁼J | |
Ġ Group indices by their value in the list | |
Ṣ Sort list of lists of indices | |
F Flatten | |
⁼ The result is equal to | |
J Range from 1 up to len of original argument | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///Igoc7F7k9atzj9f///2gTHRMdSyg01DGMBQA"" rel=""nofollow noreferrer"">Try it online!</a></p> | |
<pre><code>¹ƙ`F⁼ | |
¹ƙ` Sort into buckets of identical items, ordered by first occurrence | |
F Flatten | |
⁼ The result is equal to the original list | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///QzmMzE9weNe75//9/tImOiY4lFBqCYCwA"" rel=""nofollow noreferrer"">Try it online!</a></p> | |
" | |
"21775","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>7</s> <s>6</s> <s>5</s> 4 bytes (thanks @Jonathan Allan!)</h1> | |
<pre><code>ṖÆḊ’ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzmmH2x7u6HrUMPP////R0YY6BkBoGKsTrWuoA@YAmQY6YI6uIZgN5hnExgIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Ṗ Delete the last row of the input matrix | |
ÆḊ Compute sqrt(det(A A^T)), where A is the result of the previous step | |
’ Decrement | |
</code></pre> | |
<p>Accepts the <a href=""https://en.wikipedia.org/wiki/Incidence_matrix"" rel=""nofollow noreferrer"">oriented incidence matrix</a> of the graph. Based on <a href=""https://en.wikipedia.org/wiki/Kirchhoff%27s_theorem"" rel=""nofollow noreferrer"">Kirchhoff's Theorem</a>, the fact that a graph has exactly one <a href=""https://en.wikipedia.org/wiki/Spanning_tree"" rel=""nofollow noreferrer"">spanning tree</a> if and only if it's a tree graph, and the fact that the <a href=""https://en.wikipedia.org/wiki/Laplacian_matrix"" rel=""nofollow noreferrer"">Laplacian matrix</a> of a graph can be easily computed from its oriented incidence matrix as follows: <span class=""math-container"">$$L=BB^T$$</span> where <em>L</em> is the Laplacian matrix and <em>B</em> is the oriented incidence matrix. Outputs a truthy value if the graph is <em><strong>not</strong></em> a tree, and a falsy value if it is.</p> | |
<p>After deleting the last row from the incidence matrix (<code>Ṗ</code>) and multiplying by its transpose, the result will be equal to the Laplacian matrix with the last row and last column deleted: exactly what we need. <code>ÆḊ</code> transposes, multiplies, <em>and</em> computes the determinant for us: perfect! It also takes the square root of the result, but for reasons I'll explain later, this isn't a problem.</p> | |
<p>The determinant of the matrix product mentioned previously, the square of the result of all but the last step, is the number of spanning trees of the graph. This is 0 for a non-fully-connected graph, 1 for a tree, and 2 or more for a fully-connected non-tree graph. Now, I mentioned that <code>ÆḊ</code> takes the square root of the determinant. Is this a problem? It isn't, since the square root of 0 is 0, the square root of 1 is 1, and the square root of a number greater than 1 will also be a number greater than 1. Therefore, after decrementing (<code>’</code>), the result will be falsy (0) if and only if the determinant is 1: that is, if and only if the graph is a tree graph.</p> | |
<p>If the number of nodes happens to be one greater than the number of edges, deleting the last row will result in a square matrix. In this case, <code>ÆḊ</code> will simply compute the determinant, so won't this lead to incorrect outputs? It won't, since for a square matrix <em>A</em>: <span class=""math-container"">$$\sqrt{\det(A A^T)} = \sqrt{\det(A) \det(A^T)} = \sqrt{\det(A) \det(A)} = |\det(A)|$$</span> | |
Therefore, the result will still be exactly what we need (since the determinant of the matrix in question is guaranteed to be non-negative).</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒPḊFQLƊ_LƊ€ȧ/’ | |
</code></pre> | |
<p>A monadic Link that accepts an edge list and yields a zero (falsey) if a tree or a non-zero integer (truthy) if not a tree.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opICHO7rcAn2OdcUD8aOmNSeW6z9qmPn////oaEMdo1idaCMdYyBprGMCJA2BZCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///opICHO7rcAn2OdcUD8aOmNSeW6z9qmPn/UcOcvPwShUSFkqLU1EcNc4F8KOtwuz1QWeT//9HRGoY6CkaasVw6UJaOgoaRjoIxlDbBLmMMkgHSJjoKpqgqDJH1QmiECmOoCjMobY5mmynUTHNUM40x3IFkCw6XoqswweYOU@L8BJMxRrgQ4VIgbQZxcSwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>We know that (a) the number of edges must be exactly one less than the number of vertices and (b) there must be no sub-graph (including the whole graph, but excluding the empty graph) which has the same number of vertices and edges. So this finds the difference between vertex count and edge count for every non-empty set of edges, checks that all are non-zero and that the result for the full set of edges is <span class=""math-container"">\$1\$</span>.</p> | |
<pre><code>ŒPḊFQLƊ_LƊ€ȧ/’ - Link: list of edges | |
ŒP - get the powerset of the edges (N.B. full-set is rightmost) | |
Ḋ - dequeue (removes the empty set) | |
€ - for each: | |
Ɗ - last three links as a monad: | |
Ɗ - last three links as a monad: | |
F - flatten the current set of edges | |
Q - deduplicate -> distinct vertices used by this set of edges | |
L - length -> vertex count | |
L - length of this set of edges -> edge count | |
_ - subtract -> vertex count - edge count | |
/ - reduce by: | |
ȧ - logical AND -> 1 if a tree, 0,2,3,... otherwise | |
’ - decrement -> zero (falsey) if a tree non-zero (truthy) otherwise | |
</code></pre> | |
<hr /> | |
<p>If one takes an adjacency matrix with all vertices also identified as self-connected <span class=""math-container"">\$12\$</span> bytes is possible - see <a href=""https://codegolf.stackexchange.com/users/92689/steffan"">Steffan</a>'s <a href=""https://codegolf.stackexchange.com/a/251220/53748"">answer</a>.</p> | |
<hr /> | |
<p>If one takes the Laplacian matrix then <span class=""math-container"">\$6\$</span> bytes is possible - see <a href=""https://codegolf.stackexchange.com/users/21775/alex"">Alex</a>'s <a href=""https://codegolf.stackexchange.com/a/251223/53748"">answer</a>.</p> | |
" | |
"92689","<h1><a href=""https://github.com/Vyxal/Vyxal"" rel=""nofollow noreferrer"">Vyxal</a>, 13 bytes</h1> | |
<pre><code>LÞefA?LT*?f∑> | |
</code></pre> | |
<p><a href=""https://vyxal.pythonanywhere.com/#WyJBIiwiIiwiTMOeZWZBP0xUKj9m4oiRPiIsIiIsIltbMSwgMV0sIFsxLCAxXV1cbltbMSwgMSwgMCwgMF0sIFsxLCAxLCAxLCAxXSwgWzAsIDEsIDEsIDBdLCBbMCwgMSwgMCwgMV1dXG5bWzEsIDEsIDAsIDAsIDBdLCBbMSwgMSwgMSwgMCwgMF0sIFswLCAxLCAxLCAxLCAwXSwgWzAsIDAsIDEsIDEsIDFdLCBbMCwgMCwgMCwgMSwgMV1dXG5bWzEsIDEsIDEsIDAsIDBdLCBbMSwgMSwgMCwgMSwgMV0sIFsxLCAwLCAxLCAwLCAwXSwgWzAsIDEsIDAsIDEsIDBdLCBbMCwgMSwgMCwgMCwgMV1dXG5bWzEsIDAsIDEsIDAsIDAsIDEsIDFdLCBbMCwgMSwgMSwgMCwgMSwgMCwgMF0sIFsxLCAxLCAxLCAwLCAwLCAwLCAwXSwgWzAsIDAsIDAsIDEsIDAsIDAsIDFdLCBbMCwgMSwgMCwgMCwgMSwgMCwgMF0sIFsxLCAwLCAwLCAwLCAwLCAxLCAwXSwgWzEsIDAsIDAsIDEsIDAsIDAsIDFdXVxuW1sxLCAxLCAwLCAwXSwgWzEsIDEsIDAsIDBdLCBbMCwgMCwgMSwgMV0sIFswLCAwLCAxLCAxXV1cbltbMSwgMSwgMSwgMF0sIFsxLCAxLCAxLCAxXSwgWzEsIDEsIDEsIDBdLCBbMCwgMSwgMCwgMV1dXG5bWzEsIDEsIDEsIDAsIDBdLCBbMSwgMSwgMSwgMCwgMF0sIFsxLCAxLCAxLCAwLCAwXSwgWzAsIDAsIDAsIDEsIDFdLCBbMCwgMCwgMCwgMSwgMV1dXG5bWzEsIDAsIDEsIDAsIDFdLCBbMCwgMSwgMSwgMCwgMF0sIFsxLCAxLCAxLCAxLCAwXSwgWzAsIDAsIDEsIDEsIDFdLCBbMSwgMCwgMCwgMSwgMV1dXG5bWzEsIDEsIDAsIDAsIDAsIDAsIDBdLCBbMSwgMSwgMCwgMCwgMCwgMCwgMF0sIFswLCAwLCAxLCAxLCAxLCAwLCAwXSwgWzAsIDAsIDEsIDEsIDEsIDAsIDFdLCBbMCwgMCwgMSwgMSwgMSwgMCwgMF0sIFswLCAwLCAwLCAwLCAwLCAxLCAxXSwgWzAsIDAsIDAsIDEsIDAsIDEsIDFdXSJd"" rel=""nofollow noreferrer"">Try it Online!</a></p> | |
<p>Takes input as an adjacency matrix with 1s on the main diagonal. Port of @loopy walt's second answer from @Command Master, upvote that!</p> | |
<pre><code>LÞefA?LT*?f∑> | |
L # Get the length of the input | |
Þe # Matrix exponentiate it to that | |
f # Flatten | |
A # Are all non-zero? Call this X | |
?L # Get the length of the input again | |
T # Triple it (multiply by 3) | |
* # Multiply this by X. Call this Y | |
?f∑ # Get the flattened sum of the input | |
> # Is Y greater than this? | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>13</s> 12 bytes</h1> | |
<pre><code>æ*LȦ×L×3>ẎS$ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wMi2fE8sOT/c5PN3Y7uGuvmCV/0f3OBxuf9S05uikhztnAGkgygJRDXMUbGwVHjXMjfz/Pzo62lBHwTBWRwFCgxhglo6CARDBxCEIxDOA8QwQPAMsOtE1G6DoQDXCAN0GhBiysRhuMkBogvMMMFyGLoDiWhRRDC9iDwcDFB8iOxdmOrp1KIYYICFDdGEsTsTmbbSQQ@OhhRlmJBoSEYmGeCIRW6xicw26g5BsQgtnNEfiShuGuNKGAXq04BBGMRGfsCFB1Xj9DHdiLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 byte thanks to Jonathan Allan.</p> | |
<p>Same.</p> | |
<pre><code>æ*LȦ×L×3>ẎS$ | |
æ* - Matrix exponentiate the input to... | |
L - Its length. | |
Ȧ - After flattening, are they all non-zero? | |
×L - Multiply this by the length of the input. | |
×3 - Multiply by 3. | |
> - Is this greater than... | |
ẎS$ - The flattened sum of the input? | |
</code></pre> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>OÆmƤ+.Ọ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9//cFvusSXaeg939/z//98DKJivCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>OÆmƤ+.Ọ | |
O - Get a list of character codes from the input string | |
Ƥ - Over prefixes: | |
Æm - Get the mean | |
+. - To each, add 0.5 | |
Ọ - Convert from character codes to charcters. Decimals are rounded down. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>8⁼þj-‘×þ`ị“.* R ” | |
</code></pre> | |
<p>A niladic Link that yields a list of the lines of characters. The empty lines have trailing spaces.</p> | |
<p><strong><a href=""https://tio.run/##ASoA1f9qZWxsef//OOKBvMO@ai3igJjDl8O@YOG7i@KAnC4qIFIg4oCd/8KiWf8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (Footer joins with newlines)</p> | |
<h3>How?</h3> | |
<p>Implements <a href=""https://codegolf.stackexchange.com/a/251105/53748"">Jonah's brilliant method</a>.</p> | |
<pre><code>8⁼þj-‘×þ`ị“.* R ” - Link: no arguments | |
8 - 8 | |
þ - ([1..8]) table ([1..8]) with: | |
⁼ - is equal? | |
- - -1 | |
j - join | |
‘ - increment all values | |
` - use as both arguments of: | |
þ - table with: | |
× - multiply | |
“.* R ” - ".* R " | |
ị - index into (1-indexed and modular, so 0 gives ' ') | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 24 23 </s> 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>W8p¤ạṢ€ċؽʋƇ$ƬŒṬĖP€o/’ | |
</code></pre> | |
<p>A monadic Link that accepts a pair of integers and yields a list of lists of integers.</p> | |
<p><strong><a href=""https://tio.run/##ATsAxP9qZWxsef//VzhwwqThuqHhuaLigqzEi8OYwr3Ki8aHJMasxZLhuazEllDigqxvL@KAmf/Dh0f//zEsMQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (The footer pretty prints the grid)</p> | |
<h3>How?</h3> | |
<p>Repeatedly finds coordinates reachable from the current list of coordinates starting with just the given coordinate. Then creates grids from each of these lists with their grid number at the identified coordinates and reduces these with logical OR to keep the first non-zero value at each coordinate. This has the initial position as <span class=""math-container"">\$1\$</span> rather than <span class=""math-container"">\$0\$</span>, so all numbers are then reduced by one.</p> | |
<pre><code>W8p¤ạṢ€ċؽʋƇ$ƬŒṬĖP€o/’ - Link: integers [x, y] | |
W - wrap -> [[x, y]] | |
Ƭ - collect up while distinct applying: | |
$ - last two links as a monad: | |
¤ - nilad followed by link(s) as a nilad: | |
8 - eight | |
p - ([1..8]) Cartesian power ([1..8]) -> all coordinates | |
Ƈ - keep those for which: | |
ʋ - last four links as a dyad: | |
ạ - absolute difference (vectorises) | |
Ṣ€ - sort each | |
ؽ - [1,2] | |
ċ - count occurrences | |
ŒṬ - convert to grids of zeros with ones at the coordinates | |
Ė - enumerate -> [[1, 1st grid], [2, 2nd grid], ...] | |
P€ - product of each -> grids with 1s replaced by grid number | |
/ - reduce by: | |
o - logical OR (vectorises) | |
’ - decrement | |
</code></pre> | |
<hr /> | |
<p>Alternative 22, same method just identifying the existence of <code>[1,2]</code> and <code>[2,1]</code> by filtering for those which, when sorted, are invariant under the operation of getting the range of their length (<code>[1,2]</code>):</p> | |
<pre><code>W8p¤ạṢJƑ$Ƈ¥Ƈ$ƬŒṬĖP€o/’ | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>Œṗḟ€“©µÞ‘Ạ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIc7pz/cMf9R05pHDXMOrTy09fC8Rw0zHu5a8P9wO1DQ@fCGIwse7u4@uschC6QGrExB107hUcPcSCAv61HjvkPbgHBr0P//pgYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Outputs in the opposite direction; returning <code>false</code> indicates that the input is a Chicken McNugget number. The TIO footer swaps this for you.</p> | |
<h2>How it works</h2> | |
<pre><code>Œṗḟ€“©µÞ‘Ạ - Main link. Takes an integer n on the left | |
Œṗ - Integer partitions of n; all ways to sum integers to n | |
“©µÞ‘ - Yield [6, 9, 20] | |
€ - Over each partition P: | |
ḟ - Remove all 6s, 9s and 20s | |
Ạ - Are all resulting lists non-empty? | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>8</s> 6 bytes</h1> | |
<pre><code>sJEƇḢ€ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/Yy/VY@8Mdix41rfl/uN1bM/L/f6XEpOQUEFbSUVBKTEyEUmAAZgOlUtOUAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of my Brachylog solution.</p> | |
<pre><code>s Slice the input into chunks of | |
J every length. | |
EƇ Keep only partitions with all equal elements, | |
Ḣ€ and return the first element of each remaining partition. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 + 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a> = 13</h1> | |
<h4>Polar to Cartesian:</h4> | |
<pre><code>×ıÆeׯi | |
</code></pre> | |
<p>A dyadic Link accepting <span class=""math-container"">\$\theta\$</span> on the left and <span class=""math-container"">\$r\$</span> on the right that yields a list <span class=""math-container"">\$[x, y]\$</span>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///w9CMbD7elHp5@uC3z////Rv9NAQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h4>Cartesian to polar:</h4> | |
<pre><code>æịA,æA | |
</code></pre> | |
<p>A dyadic Link accepting <span class=""math-container"">\$y\$</span> on the left and <span class=""math-container"">\$x\$</span> on the right that yields a list <span class=""math-container"">\$[r, \theta]\$</span>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wsoe7ux11Di9z/P//v4meqYmZieV/XSM9AwsDc2MA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>×ıÆeׯi - Link: theta; r | |
ı - the imaginary unit, i | |
× - (theta) multiplied by (i) | |
Æe - apply the exponential function -> e^(i.theta) | |
× - multiply that by r -> r.e^(i.theta) | |
Æi - Separate that into real and imaginary parts | |
</code></pre> | |
<pre><code>æịA,æA - Link: y; x | |
æị - y+i.x | |
A - absolute value -> r (same as for x+iy - we've just reflected in Re=Im) | |
æA - atan2(y, x) -> theta (by definition) | |
, - pair | |
</code></pre> | |
<hr /> | |
<p>Alternative <span class=""math-container"">\$7\$</span> byte Polar to Cartesian: <code>ÆẠ,ÆSƊ×</code><br /> | |
(pair <code>,</code> the cosine <code>ÆẠ</code> and sin <code>ÆS</code> of <code>Ɗ</code> <span class=""math-container"">\$\theta\$</span> and multiply <code>×</code> by <span class=""math-container"">\$r\$</span>).</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>%RḤ_RỊTḊ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/1816OGOJfFBD3d3hTzc0fX/cLu3ZuT//4Y6CkY6CsY6CiY6CqY6CmY6CuY6ChY6CpY6CoYGQAxkGgFpI2OgvLGRKQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Feels... messy, but the best I can think of to reuse the range ties: <code>Ḋ%Ḥ_Ịʋ@Ƈ</code></p> | |
<pre><code>%R n mod each [1 .. n] | |
Ḥ times 2 | |
_R minus each corresponding [1 .. n] | |
Ị in [-1 .. 1]? | |
T Find truthy indices | |
Ḋ and remove the first (always 1). | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 16 10 </s> 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>÷Ċ¬>¡⁵⁸sẈ | |
</code></pre> | |
<p>A full program that accepts <code>X N B</code> and prints a list or errors if no solution is possible.</p> | |
<p><strong><a href=""https://tio.run/##ASMA3P9qZWxsef//w7fEisKsPsKh4oG14oG4c@G6iP///zE3/zP/OA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##qyrO@P@/JLW4RENToZorNTkjX0E3T0FJxUHB1k5BiSsrNSenUiG1NE9B/fD2I12H1tgdWvioceujxh3FD3d1qCsA1RnZqRko1NQogPUq5eUrFOfnlJZk5ucppOWX5qUocdVygcxXMDRXMFawgLCNDJHYRkhsUxD7/38A"" rel=""nofollow noreferrer"">test-suite</a> (Thanks, <a href=""https://codegolf.stackexchange.com/users/92689/steffan"">Steffan</a>!)</p> | |
<p>...if erroring is not acceptable then <span class=""math-container"">\$10\$</span> with <code>s÷Ċ¥Ẉ«Ƒ⁵ȧƊ</code> (<a href=""https://tio.run/##ASUA2v9qZWxsef//c8O3xIrCpeG6iMKrxpHigbXIp8aK////MjX/M/84"" rel=""nofollow noreferrer"">TIO</a>) prints <code>0</code> instead.</p> | |
<h3>How?</h3> | |
<pre><code>÷Ċ¬>¡⁵⁸sẈ - Main Link: integer, X; integer, N | |
÷ - (X) divided by (N) | |
Ċ - round up to an integer (let's call this R) | |
⁵ - set the right argument to the program's third argument = B | |
¡ - repeat... | |
> - ...number of times: (R) greater than? (B) | |
¬ - ...action: logical NOT | |
i.e. replace R with 0 if R>B (let's call this P) | |
⁸ - chain's left argument = X | |
s - (implicit [1,2,...,X]) split into chunks of length (P) | |
Note: trailing elements are kept e.g. 7s3 -> [[1,2,3],[4,5,6],[7]] | |
Ẉ - length of each | |
- implicit print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 1 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">byte</a></h1> | |
<pre><code>f | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/t/@Hl@o@a1kT@/x8drZSYlJyipKOgZGiUkmhsohTLpROtlAFUmK@jUJ5flJOiCJJMTM3ML8UlBzQgNS09IzMrOyc3L7@gsKi4pLSsvKKyCqLBA6IhnFINOCQVdfQUYvJiSiDShuZGFibGlgamUH2GRsYQibTMqqqk0qoqkDimCJwNlsEUQVZbBQIIhUBWLAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>This is exactly what Jelly's "filter-keep" dyadic atom does - takes a list on the left and a list on the right and keeps those in the left that appear in the right.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 20 18 </s> 17 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Thanks to <a href=""https://codegolf.stackexchange.com/users/92689/steffan"">Steffan</a> for a speed up! (<code>‘×⁵</code> -> <code>æċ⁵</code>) and a byte that ended up saving elsewhere!<br /> | |
Save of 2 using Steffan's idea of counting >.< - thanks again Steffan!</p> | |
<pre><code>;PDKĠṢ | |
æċ⁵ḶŒpÇ€ċÇ | |
</code></pre> | |
<p>A monadic Link that accepts a pair of non-negative integers and yields a non-negative integer.</p> | |
<p><strong><a href=""https://tio.run/##ATAAz/9qZWxsef//O1BES8Sg4bmiCsOmxIvigbXhuLbFknDDh@KCrMSLw4f///81NCwgMTA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>;PDKĠṢ - Helper Link, cryptic multiplication identifier: pair of integers [a,b] | |
P - product -> a×b | |
; - concatenate -> [a, b, a×b] | |
D - to decimal digits -> [[a1, a2, ...],[b1, b2, ...],[P1, P2, ...]] | |
K - join with space characters (representing times and equals) | |
Ġ - group indices by their values -> [indices of spaces, indices of 0s, ...] | |
Ṣ - sort | |
æċ⁵ḶŒpÇ€ċÇ - Link, cryptic multiplication ambiguity: pair of integers [x,y] | |
⁵ - 10 | |
æċ - next power of (10) of each -> [u, v] (N.B. 0 -> 10, not 1) | |
Ḷ - lowered range of each -> [[0, 1, ..., u-1], [0, 1, ..., v-1]] | |
Œp - Cartesian product -> [[0, 0], [0, 1], ..., [u-1, v-1]] | |
Ç€ - call the helper Link for each | |
Ç - call the helper Link with [x, y] | |
ċ - count occurrences | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>ŻṗḋRċ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o7oc7pz/c0R10pPv/4XbNyP//zQE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Non-builtin solution using Henry Bottomley's comment at the top of the OEIS page. Although this obviously doesn't beat the builtin, I wouldn't be surprised if the same approach might be the shortest in some other array languages.</p> | |
<pre><code> ṗ Generate every combination of n elements with replacement from | |
Ż [0 .. n], | |
ḋ dot product each with | |
R [1 .. n], | |
ċ and count the occurrences of n. | |
</code></pre> | |
<p>This can also be thought of as encoding each unordered partition as an ordered list of the multiplicity of each integer.</p> | |
" | |
"78850","<h1><a href=""https://github.com/Vyxal/Vyxal"" rel=""nofollow noreferrer"">Vyxal</a>, 5 bytes</h1> | |
<pre><code>ṄvL=∑ | |
</code></pre> | |
<p><a href=""https://vyxal.pythonanywhere.com/#WyIiLCIiLCLhuYR2TD3iiJEiLCIiLCI2XG4yIl0="" rel=""nofollow noreferrer"">Try it Online!</a></p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>ŒṗẈ=S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIc7pz/c1WEb/P//f0OD/8YA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Dang it, ninja'd by Kevin because I took the time to get the shortest jelly answer too :p</p> | |
<p>Exact same approach as the 05ab1e answer, derived independently - both answers get the integer partitions of the first input and then count the number of partitions where the length equals the second input.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>32</s> <s>30</s> <s>28</s> 27 bytes</h1> | |
<pre><code>=þØ(_/µJṁ"Äo¹ṁɗ\ḟ"JċⱮ`HnAɓx | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/28L7DMzTi9Q9t9Xq4s1HpcEv@oZ1AxsnpMQ93zFfyOtL9aOO6BI88x5OTK/4fbn/UtCby//9oJY3EnIKMRE0lLh0lDSCI1gQCEEchKbUkUSM9MTcXIukAUqahkZOYm5SSCFGiUZCRqaFRkgFUqFmQCRUrzkwH6tDIz01NT4SLaECENFOtETZpAE3RTILq0kiCCkD4QF6iSrKmRkpqGkSgAihdqalRBZXXSMvP10hKLAIakFgFEgDxwQJAPrINGkALNJNhliQDxZI04fbEAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Removes every pair of parentheses which is the only thing contained by either an outer pair or the entire string.</p> | |
<pre><code>=þØ( Table equality with "()" | |
_/ and subtract the close parens from the open parens. | |
Ä Cumulative sum, to get depths, | |
µJṁ" repeat each index by its depth, | |
\ and scan by: | |
o overlay the element on the accumulator | |
¹ ɗ then | |
ṁ trim the accumulator to the element's length. | |
ḟ"J For each result, filter out its index. | |
=þØ(_/µJṁ"Äo¹ṁɗ\ḟ"J This results in a list of lists where each list | |
uniquely represents the deepest pair of parentheses | |
containing the corresponding element. | |
ċⱮ` Count how many times each list appears. | |
H Is each count halved | |
n not equal to | |
=þØ(_/µ A if the corresponding element is a paren? | |
ɓx Replicate the input by that result. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 33 30 29 </s> 27 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ø(jẹⱮØ(Œ!ż€¥/ṢƑ€ÞṪ_Ø-fƊF’œP | |
</code></pre> | |
<p>A full program that accepts a string and prints the result.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wDI2sh7t2Ptq4Dsg6Oknx6J5HTWsOLdV/uHPRsYlA5uF5D3euij88QzftWJfbo4aZRycH/D/cDpSI/P8/WkkjMacgI1FTiUtHSQMIojWBAMRRSEotSdRIT8zNhUg6gJRpaOQk5ialJEKUaBRkZGpolGQAFWoWZELFijPTgTo08nNT0xPhIhoQIc1Ua4RNGkBTNJOgujSSoAIQPpCXqJKsqZGSmgYRqABKV2pqVEHlNdLy8zWSEouABiRWgQRAfLAAkA9UEQsA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Partitions the input string at its redundant parentheses and prints the characters that remain.</p> | |
<p>The redundant parentheses are found by first finding the indices of all pairs of matching parentheses in a copy of the input string that has been wrapped in parentheses, and then filtering these to those which are bounded by any other (i.e. rule 1, but removing the inner pair).</p> | |
<p>For that, the list of indices of all pairs of matching parentheses are effectively found by pairing each closing index with the opening index that is closest to its left that has not been consumed by any previous closing index. This is actually achieved by constructing all lists of pairs of opening and closing indices and finding the one that (a) has no reversed pairs and (b) has the maximal list of opening indices when ordered by their respective closing indices.</p> | |
<pre><code>Ø(jẹⱮØ(Œ!ż€¥/ṢƑ€ÞṪ_Ø-fƊF’œP - Link: list of characters, S | |
Ø( - "()" | |
j - join with S -> parenthesised S | |
Ø( - "()" | |
Ɱ - map with: | |
ẹ - all indices -> [open_indices, close_indices] | |
/ - reduce this pair of lists by: | |
¥ - last two links as a dyad - f(open_indices, close_indices): | |
Œ! - all permutations of open_indices | |
ż€ - zip each with close_indixes | |
Þ - sort by: | |
€ - for each pair: | |
Ƒ - is invariant under?: | |
Ṣ - sort | |
Ṫ - tail -> X = list of open indices that pair ascending close indices | |
Ɗ - last three links as a monad - f(X) | |
Ø- - [-1,1] | |
_ - subtract [-1,1] from each index-pair | |
f - X filter keep those | |
-> redundant parentheses index pairs | |
F - flatten | |
’ - decrement (from indices in parenthesised S to indices in S) | |
œP - partition S at those indices, discarding borders | |
- implicit, smashing print | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>“½ṬṚ»y | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw5xDex/uXPNw56xDu4H8/x6picl5OgrluUU5KYoA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <code>Heacn, wmrld!</code>. Searched with <a href=""https://tio.run/##ZY5BasMwEEX3OsV001iuGnC6M3ifOxgTjC0nCspIjFSEG3J2R@OUYuhKw3/89@XneHH4tUzkbnDV1s5gbt5RhMGN@uT7s1YwmiEahz3N4heSXiZHkMDghu7DheHHNrIOz7UAM4HVWCT5XtVZjdHgtxYQoIHdMc86BcmRHd92AojTtvwxvkhtXR86ldqKX9kJ4FnPsxQy@6y6LF81YU/a237QRelfREEl/5bvZXjIpuEzSO7gWsrHxsj5C@BWly2sYfDvu2vFk8FYJBXksjwB"" rel=""nofollow noreferrer"">this script</a>.</p> | |
<pre><code> y Transliterate the input by | |
“½ṬṚ» "monoclinal". | |
</code></pre> | |
<p>Unless I <a href=""https://tio.run/##bVLLTsMwELznK5YLcUqImiIuUcOFC/8QVchNXDBNbWvXUVQQ3168TloqgXJZZR47O7I7@ndrHk47tAf4UH1/BH1wFj20tlOvTr6pHDrdem2NxGMORJTMDFTnSXuF3tqeTp3agVfkX2nYktd@YCGJrWz3o8Quh51FHrIqAYIa0pew0@YwWuy7mzRhHBxoA2dJIEYmFahcL1slFq6pqvtyk0OZJaB30Csjvhb0ndU1j8TmYKIoDBfHeTWDE2quPYNVuMgPaCL4JxpI0wW/hO2e2e5ydOHQdkPrxaWyplo9LkO@4K6kr1ccaOQ4ROL5N/OYwS2UnIfBNHx3MEY0tSkY63nN2JRVtdpAWDuPRWsH40XapxmsYcX61hqvzaASQD6sWXxqJ8aG2fmsyjYJONRBOGZTzQdJe96A0rwpUcJ6HVMhZbFAhlXHbpvrFpFigSFk1M8HnOmFNhRqEcscYqMT6emphjL2S0Pvg@U/T2TSh86IdcF@IkfzOXc@/4vGW1Ryfzr9AA"" rel=""nofollow noreferrer"">brute-forced something wrong</a>, a 2-byte compressed string does not seem to be possible.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“ ⁷ỴNt»ṁ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##ASgA1/9qZWxsef//4oCcIOKBt@G7tE50wrvhuYH///8naG93IGFyZSB5b3Un"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Pretty simple...</p> | |
<pre><code>“ ⁷ỴNt»ṁ - Link: list of characters, S | |
“ ⁷ỴNt» - dictionary lookup -> "HelloWorld" | |
ṁ - mould like S | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 44 </s> 39 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-5 thanks to UnrelatedString (clever use of <code>;Ṫ</code> for the empty string special case).</p> | |
<pre><code>ØhḊiⱮŒla;Ṫ$œs3z0ZŻ€ṫ€-7ZḊẸ€Ḣ¬Ɗ¡ƬḊƇṪḣ2ZF | |
</code></pre> | |
<p>A full program that accepts a string and prints the resulting colour code (keeping character casing from the input*).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wjIyHO7oyH21cd3RSTqL1w52rVI5OLjauMog6uvtR05qHO1cDSV3zKKCih7t2gER2LDq05ljXoYXHgMyuY@1AHQ93LDaKcvv//796kaNLZr6jc0lmmas6AA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///wjIyHO7oyH21cd3RSTqL1w52rVI5OLjauMog6uvtR05qHO1cDSV3zKKCih7t2gER2LDq05ljXoYXHgMyuY@1AHQ93LDaKcvv/cHfP0T2H24FqsoD4UcMcBV07hUcNcyP//49WL0pNUddRUC8qzUktBjEMjYxNTM3MLSwNHJ2cXVzRuGClji6Z@Y7OJZllYK6bT6ibG5gBIkC4qjCppKQMxDJLSTJLTTaxTE1LMTK3SE4xSEq2NEoxTDVNNTA3SjGzAFtoYGRsYGBiamBgZq4eCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ØhḊiⱮŒla;Ṫ$œs3z0ZŻ€ṫ€-7ZḊẸ€Ḣ¬Ɗ¡ƬḊƇṪḣ2ZF - ...f(X) | |
Øh - hex characters = "0123456789abcdef" | |
Ḋ - dequeue -> "123456789abcdef" | |
Œl - lower-case X | |
Ɱ - map with: | |
i - first 1-indexed index or 0 if not found | |
$ - last two links as a monad - f(X): | |
Ṫ - tail (yields zero when X is empty) | |
; - X (without its tail) concatenated with that (its tail or a zero) | |
a - logical AND the hex-char-indicator list with X or [0] (vectorises) | |
œs3 - split into three equal chunks | |
Ż€ - prefix each with a zero | |
ṫ€-7 - tail each from index -7 -> last (up to) eight values | |
Z - transpose | |
Ƭ - collect up while distinct, applying: | |
¡ - repeat... | |
Ɗ - ...number of times: last three links as a monad: | |
Ẹ€ - any? for each | |
Ḣ - head | |
¬ - logical NOT | |
Ḋ - ...action: dequeue | |
Ƈ - keep those which are truthy under: | |
Ḋ - dequeue | |
Ṫ - tail | |
ḣ2 - head to index two | |
Z - transpose | |
F - flatten | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>œcŒPṚœc€⁵ẎQLƲÞṪ | |
</code></pre> | |
<p>A full program that accepts alphabet size (n), block size (k), and subset size (v) and prints a minimum covering design.</p> | |
<p><strong><a href=""https://tio.run/##AS0A0v9qZWxsef//xZNjxZJQ4bmaxZNj4oKs4oG14bqOUUzGssOe4bmq////NP8z/zI"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Naive brute-force, and about as inefficient as possible!</p> | |
<pre><code>œcŒPṚœc€⁵ẎQLƲÞṪ - Main Link: n, k | |
œc - k-combinations of [1..n] without repeats | |
ŒP - powerset | |
Ṛ - reverse (to be from longest to shortest) | |
Þ - (stable) sort (these proposed solutions) by: | |
Ʋ - last four links as a monad: | |
⁵ - with right argument = third program argument (v) | |
€ - for each k-tuple in the proposed solution: | |
œc - v-combinations of the k-tuple | |
Ẏ - tighten to a list of the covered v-tuples | |
Q - deduplicate | |
L - length -> number of distinct v-tuples covered | |
Ṫ - tail -> i.e. (one of) the shortest valid proposed solution(s) | |
- implicit print | |
</code></pre> | |
<hr /> | |
<h4>Aside:</h4> | |
<p>A greedy method of adding the lexicographically first unused block that covers the most so far uncovered subsets gets an optimal covering design <em>sometimes</em> and a fairly good alternative (slightly larger number of blocks) other times. Using other orderings (than lexicographic) with the same selection criteria will find optimal coving designs <em>sometimes</em> too. See <a href=""https://www.dmgordon.org/papers/cover.pdf"" rel=""nofollow noreferrer"">New Constructions for Covering Designs | |
(Daniel M. Gordon, Greg Kuperberg, Oren Patashnik)</a></p> | |
<p>This <a href=""https://tio.run/##lVTLjpswFN3zFVeq1DGqO0o61Swi0VXX7QdMIsTDBGuMjWyTzBTx7enFJhBComm9MH7cc@65D1O/21LJp9Op0KqCTAnBMsuVNMCrWmkLv3XONMt/8swGzoZbpq1SYrTIVJVymThUEAQ5K2DPbJypA9MkEXWZpLg1/A@jkAqVvQ5r06RmuAg3AeA4G0MEOpF7RtYUZgTwBdahM22k42d57GkMYvBDLsWMzue@PMEnZBZeD0YiQbA3nqm9TuqSZ4kA1cdN4chtCbZkcHaD63dwvgcdjUERnie26iwnHuShrIsMEofpB3EIutR8Pr8UHI6wQmmv2Unm5m7AU6IHtJ@dKtT0snPbY8kFW@ZyM/pLmbE@OAT9UpKNN1XyxqtE@DhxbmRfttVSKYXrSqH0j9L2iF1WGRJOSvoh2TFelv365PMyoBkLL7DYktwgC@HHrbjmIu4Hf491AZ9l1X1nJh8l58Xd7BB7w9vI5M4fk7pmMieTx0nN8gl9jf7B98i0G5lyJv4fqJlttByeUhD0/SIpYLscKKjauvxiRvf4/rBhCPlO4YnCN5xDCmS9ovDsTtarfo9rb/AcDk2jmWlEX5bpZzTw@xTUmktLigcZtbLDi6h9xc8hag/dZitbD@@2kngRUduX15@G3bXEqJ3vu3ArH8LgdPoL"" rel=""nofollow noreferrer"">Python code</a> does this with the lexicographic ordering - it gets a different, optimal solution for <code>n=10 k=6 v=3</code> (also 10 blocks), but a non-optimal one for (for example) <code>n=6 k=4 v=3</code> (one too many blocks).</p> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>HSạŻP½ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/98j@OGuhUd3Bxza@z/aWMdExzT2cPt/AA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Don't ask me why the chaining works...</p> | |
<pre><code>H # Half of | |
S # The sum of the input | |
ạ # Absolute difference with | |
Ż # The input, with a 0 prepended | |
P½ # Take the square root of the product | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Tḟ+¥ⱮØ+Z | |
</code></pre> | |
<p>A monadic Link that accepts a list and yields a list of start, end pairs of truthy runs (1-indexed, as Jelly is).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/k4Y752oeWPtq47vAM7aj///9HG@gY6oCwIYSOBQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/z/k4Y752oeWPtq47vAM7aj/h9uPTnq4c4Zm5P//0dEGsVw60YZgQsdQx0AHzARSYA6ERhOCCuogaUISRIEGEJ3IehEQQzFOaEgCNKAiBPsxFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Tḟ+¥ⱮØ+Z - Link: list, A | |
T - Truthy indices of A -> t | |
Ø+ - [1,-1] | |
Ɱ - map (for n in [1,-1]) with: | |
¥ - last two links as a dyad f(t, n): | |
+ - t add n (vectorises) | |
ḟ - t filter discard those | |
Z - transpose | |
</code></pre> | |
<p>i.e. get a pair of lists of:</p> | |
<ol> | |
<li>indices of truthy values with no truthy value to their right (run starts); and</li> | |
<li>indices of truthy values with no truthy value to their left (run ends)</li> | |
</ol> | |
<p>...and transpose that to a list of <code>[run start, run end]</code> pairs.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒcżU$Œ!y@ƒ€⁸Q | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##ASgA1/9qZWxsef//xZJjxbxVJMWSIXlAxpLigqzigbhR////WzAsMSwyLDNd"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Since the elements are guaranteed to be distinct we can swap pairs of elements rather than elements at pairs of indices and otherwise follow the description in the question.</p> | |
<pre><code>ŒcżU$Œ!y@ƒ€⁸Q - Link: list of distinct integers, L | |
e.g. [1,7,8] | |
Œc - pairs [[1,7],[1,8],[7,8]] | |
$ - last two links as a monad: | |
U - upend [[7,1],[8,1],[8,7]] | |
ż - zip [[[1,7],[7,1]],[[1,8],[8,1]],[[7,8],[8,7]]] | |
Œ! - all permutations | |
€ - for each: | |
ƒ ⁸ - reduce by, starting with L: | |
@ - with swapped arguments: | |
y - translate | |
Q - deduplicate | |
</code></pre> | |
" | |
"9288","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <sup><s>4</s></sup> 3 bytes</h1> | |
<p>-1 byte thanks to <a href=""https://codegolf.stackexchange.com/users/85334/unrelated-string"">Unrelated String</a>.</p> | |
<pre><code>ṁDḌ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzkaXhzt6/v//b2hkDAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A port of <a href=""https://codegolf.stackexchange.com/a/250344/9288"">my PARI/GP answer</a>.</p> | |
<pre><code> D # To digits | |
ṁ # Fill with the input | |
Ḍ # From digits | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>D1€Ḍ× | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/F8FHTmoc7eg5P////v6GRMQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>I suspect there's a 4-byter but I can't find one.</p> | |
<pre><code>D Ḍ # To digits... | |
1€ # Fill with 1 | |
× # Multiply by original | |
</code></pre> | |
" | |
"113814","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>®;©ṛ | |
Ç®ċ%2 | |
ÇƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///QOutDKx/unM11uP3QuiPdqkZAxrH2/w93bznc/qhpTeT//4lAkAQEXIlJiUACyE5MhFJARlJicnIShJ@cDFSSDEQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>® (load register) | |
; (concatenate with [tacit argument, character we're filtering]) | |
© (store result of previous link in register) | |
ṛ (return right argument [tacit argument, character we're filtering]) | |
Ç (previous link as a monad, [v=character, new_v=character]) | |
®ċ (count occurrences of [character] in register) | |
%2 (mod2 of [count]) | |
Ç (previous link as monad, [v=character, new_v=1 or 0]) | |
Ƈ (filter all items, keeping all that satisfy condition, [v=argument]) | |
</code></pre> | |
<p>Filter each character, storing them in a growing list of previous seen characters. Every time you see a character for an odd numbered time, keep it.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>ŒJẈṁ× | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///oJK@Huzoe7mw8PP3/4fajkx7unKEZ@f9/dLShjoJRrI5CtDEQm@gomMYCOWYgAbCIkY6CSWwsmGsJFrOMhaiLNrWMBUsYGcRC1EUbWUIUQgBYGgQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ŒJ All multidimensional indices, in flat order. | |
Ẉ Get the length of each index (= depth of value at index). | |
ṁ Mold to the structure of the input, | |
× and multiply corresponding elements. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ụm2Ṣị | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///h7iW5Rg93Lnq4u/v////JyYmJiUmJSUnJQDIxMRkA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///h7iW5Rg93Lnq4uxvI3nK4/VHTmsj//xOBIAkIuBKTEoEEkJ2YCKWAjKTE5OQkCD85GagkGYgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test suite</a>.</p> | |
<h3>How?</h3> | |
<p>Same idea <a href=""https://codegolf.stackexchange.com/a/250225/53748"">loopy walt had</a>.</p> | |
<pre><code>Ụm2Ṣị - Link: list, X | |
Ụ - grade X up -> indices sorted by value | |
m2 - mod2 slice -> 1st, 3rd, 5th, etc. | |
Ṣ - sort | |
ị - index into X | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ḟṂŒHÐƤEƇFḢ | |
</code></pre> | |
<p>A monadic Link that accepts a string of digit characters containing a decimal point, <code>.</code>, and yields a digit character.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjvkPdzYdneRxeMKxJa7H2t0e7lj0//9/JWMgMDQyNDI1NjLUMwSRhkoA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##bY49CgJBDIX7nEPYLkwmO5PkAP5cxEb2ArbbbCteQBBLS4sV7Zbde4wXGWew9fEeX3jwIId91x1zTuMlPfv5vJtOy229DJs0XnN6Peb3NHz6@2qbc9M0DklJIWKMwMjg0AUfmYKotcJRW09/GmBBx@JAFc1UzYBiEBSRyiII6H4CH1SLK7AErEysLtB7Iu/rUUjEJeWnLw"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ḟṂŒHÐƤEƇFḢ - Link: list of characters, N | |
Ṃ - minimum of N (guaranteed to be the '.') | |
ḟ - filter ('.') from N | |
ÐƤ - for each suffix of that: | |
ŒH - split into two halves | |
Ƈ - filter keep those which are: | |
E - all equal (i.e first half = second half) | |
F - flatten | |
Ḣ - head | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>ḟ”.ŒHẆf/ƊÐƤFḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##bY4xCgJBDEX7XGS7OMnsTDIXEK/gAbSQvYCdWChYib0IYmlpsWi5uPcYLzJmsPXzPy98@JDVouvWpeT@8tmc8X2a5eduORkPw3G8TXN/Lfn1GPaf7X1eStM0DklJIWKM4NGDQxc4egqiqRUftWX604AXdF4cqGJKqikBxSAoIpUmCOh@Ag6q5gq0QLJJqgtkJmKuh5HIW@ynLw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ḟ”. Remove the radix point. | |
ƊÐƤ For each suffix: | |
ŒH Split it in half, | |
/ and reduce | |
Ẇ the sublists of the pair of halves | |
f by filter left by membership in right. | |
F Flatten the results | |
Ḣ and yield the first element. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>0;x‘Ø1jƲŻ$$¡ḣ | |
</code></pre> | |
<p>A monadic Link that accepts <code>n</code> and yields the first <code>n</code> terms of the boolean is-a-quote sequence.</p> | |
<p><strong><a href=""https://tio.run/##ASEA3v9qZWxsef//MDt44oCYw5gxasayxbskJMKh4bij////MTI"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see a longer prefix (by not heading) <a href=""https://tio.run/##AR0A4v9qZWxsef//MDt44oCYw5gxasayxbskJMKh////NA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">here</a>.</p> | |
<h3>How?</h3> | |
<p>Starts with a zero (the initial <code>a</code>) and builds up the sequence exactly as described in the question, using zeros for non-quotes and ones for quotes.</p> | |
<pre><code>0;x‘Ø1jƲŻ$$¡ḣ - Link: integer, n | |
0 - set the left argument, x, to zero | |
¡ - repeat n times: | |
$ - last two links as a monad - f(x): | |
$ - last two links as a monad - g(x): | |
Ʋ - last four links as a monad - h(x): e.g. [0,0,1,0,1] | |
‘ - increment [1,1,2,1,2] | |
x - repeat (double the quotes) [0,0,1,1,0,1,1] | |
Ø1 - [1,1] | |
j - join (wrap in quotes) [1,0,0,1,1,0,1,1,1] | |
Ż - prepend a zero (prepend a comma) [0,1,0,0,1,1,0,1,1,1] | |
; - concatenate that to x | |
ḣ - head to index n | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>;Ø.;x‘$;1 | |
0Ç¡ḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASEA3v9qZWxsef//O8OYLjt44oCYJDsxCjDDh8Kh4bij////MTU"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Full program yielding first <span class=""math-container"">\$n\$</span> elements of the quote/non-quote sequence. Exponentially slow; better tested with <a href=""https://tio.run/##ASQA2/9qZWxsef//O8OYLjt44oCYJDsxCjDDh8aTwqHhuKP//zf/NjE"" rel=""nofollow noreferrer"">manual control of the number of iterations</a>.</p> | |
<pre><code>;Ø.;x‘$;1 Monadic helper link: iterate | |
;Ø. Append [0, 1]. | |
; Append | |
x $ the argument with its elements repeated by | |
‘ themselves incremented. | |
;1 Append 1. | |
0Ç¡ḣ Main link | |
Ç¡ Repeat that n times | |
0 starting from 0, | |
ḣ and take the first n elements. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>×+_÷4ƭ‘ɼ$ḞƑпṖ | |
</code></pre> | |
<p>A full program* that accepts an integer and prints the resulting sequence.</p> | |
<p><strong><a href=""https://tio.run/##AScA2P9qZWxsef//w5crX8O3NMat4oCYybwk4biexpHDkMK/4bmW////MjE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>×+_÷4ƭ‘ɼ$ḞƑпṖ - Main Link: integer, n | |
п - collect while X, initially n, is: | |
Ƒ - ...invariant under | |
Ḟ - floor to the nearest integer | |
$ - ...last two links as a monad - f(X): | |
ɼ - apply to the register (initially zero) and yield: | |
‘ - increment (i.e. get the next right operand) | |
4ƭ - calling these four links in turn: | |
× - multiply | |
+ - add | |
_ - subtract | |
÷ - divide | |
Ṗ - pop off the trailing, non-integer | |
- implicit print | |
</code></pre> | |
<p>* Note: this is not a reusable Link since the tie quick, <code>ƭ</code>, does not reset between calls to a Link.</p> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 bytes</h1> | |
<pre><code>ẹⱮŒpI>0PƊƇḢ | |
Œuç¦ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hrp2PNq47OqnA084g4FjXsfaHOxZxHZ1Uenj5oWX///@vBKrKL1coLk3KTSzKzEtVKMnMTQWKppYAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ẹⱮŒpI>0PƊƇḢ - Helper link g(s, w) - takes string on the left and word on the right. | |
ẹⱮ - For each character in w, get all indices of it in s. | |
Œp - Take the cartesian product over this list. | |
Ƈ - Filter keep for: | |
Ɗ - Last three links as a monad: | |
I - Increments (deltas / consecutive differences) | |
>0 - Are they greater than zero? (positive) | |
P - Take the product of is to check that all are truthy | |
Ḣ - Get the first item (that satisfies that condition) | |
Œuç¦ - Main link f(s, w) - takes string on the left and word on the right. | |
ç - Run the helper link (as a dyad, given s and w) | |
¦ - At those indices in w... | |
Œu - Uppercase them | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 16 </s> 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>“œNZjr⁽⁾ƈ‘+⁹BUƬ | |
</code></pre> | |
<p>A niladic Link that yields a list of lists of lists (a 2 by 8 array of flattened boards) with <code>1</code>s representing <code>X</code>s and <code>0</code>s representing <code>O</code>s.</p> | |
<p><strong><a href=""https://tio.run/##ASUA2v9qZWxsef//4oCcxZNOWmpy4oG94oG@xojigJgr4oG5QlXGrP//"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see them in the format and order given in the question <a href=""https://tio.run/##y0rNyan8//9Rw5yjk/2isooeNe591LjvWMejhhnajxp3OoUeW/P/0KKHu/qiDY10zHVMdAxNdYx0DIG0gY6ZjqmOpY6hsY6hjqGhjoUOkGEW@3B3d/GjpjXGxSZRQArIAxoX4Z8FZINQ4z4FhUggIwvIOrTt0Lb/AA"" rel=""noreferrer"" title=""Jelly – Try It Online"">here</a>.</p> | |
<h3>How?</h3> | |
<p>Using only reflection in one axis is terser than using four rotational symmetries like in my original 16-byte code (below).</p> | |
<pre><code>“œNZjr⁽⁾ƈ‘+⁹BUƬ - Link: no arguments | |
“œNZjr⁽⁾ƈ‘ - Code page indices = [30,78,90,106,114,141,142,156] | |
+⁹ - add 256 -> [286, 334, 346, 362, 370, 397, 398, 412] | |
B - to binary | |
Ƭ - collect up while distinct applying: | |
U - reverse each | |
</code></pre> | |
<hr /> | |
<h5>Previous @16 bytes:</h5> | |
<pre><code>“⁾⁽ʠ⁷‘ḤBs€3ZṚ$Ƭ€ | |
</code></pre> | |
<p>A niladic Link that yields a list of lists of lists of lists (a 4 by 4 array of 2d boards) with <code>1</code>s representing <code>O</code>s and <code>0</code>s representing <code>X</code>s.</p> | |
<p><strong><a href=""https://tio.run/##AS0A0v9qZWxsef//4oCc4oG@4oG9yqDigbfigJjhuKRCc@KCrDNa4bmaJMas4oKs//8"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see them in the format and order given in the question <a href=""https://tio.run/##y0rNyan8//9Rw5xHjfseNe49teBR4/ZHDTMe7ljiVPyoaY1x1MOds1SOrQEy/x9a9HB3N1CZf0QUkAsUB5MzgaRStKGOsY6BjmFsFpAHQo37FBQigYwsIOvQtkPb/gMA"" rel=""noreferrer"" title=""Jelly – Try It Online"">here</a>.</p> | |
<h3>How?</h3> | |
<pre><code>“⁾⁽ʠ⁷‘ḤBs€3ZṚ$Ƭ€ - Link: no arguments | |
“⁾⁽ʠ⁷‘ - Code page indices = [142,141,165,135] | |
Ḥ - double -> [284,282,330,270] | |
B - to binary -> [[1,0,0,0,1,1,1,0,0], | |
[1,0,0,0,1,1,0,1,0], | |
[1,0,1,0,0,1,0,1,0], | |
[1,0,0,0,0,1,1,1,0]] | |
s€3 - split each into threes -> [[[1,0,0], | |
[0,1,1], | |
[1,0,0]], | |
[[1,0,0], | |
[0,1,1], | |
[0,1,0]], | |
[[1,0,1], | |
[0,0,1], | |
[0,1,0]], | |
[[1,0,0], | |
[0,0,1], | |
[1,1,0]]] | |
€ - for each: | |
Ƭ - collect up while distinct applying: | |
$ - last two links as a monad: | |
Z - transpose } | |
Ṛ - reverse } - together these rotate a quarter | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>19</s> 17 bytes</h1> | |
<pre><code>=”'ŻḂ+¥\¬Ä×ḂƲḊƙŻḊ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/2UcNc9aO7H@5o0j60NObQmsMth6cDOcc2PdzRdWwmSKLr/8PdWw5tPdz@qHGfklLWo43rsoB6dDQj//9PTErmUlcHIhAB5KhzJaonAZlJ6slgFpAECqqnpKYB1SjAFCmABKBsECs9IxPKg0gAdYKZ6mlgkyEWJEJpEAMqDDVPSQliXAwQgkTUlU0sgHYDAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Inspired by the prevalence of regex solutions, the core of the logic is a scan by the state transition table</p> | |
<div class=""s-table-container""> | |
<table class=""s-table""> | |
<thead> | |
<tr> | |
<th style=""text-align: right;""></th> | |
<th style=""text-align: center;""><span class=""math-container"">\$0\$</span></th> | |
<th style=""text-align: center;""><span class=""math-container"">\$1\$</span></th> | |
<th style=""text-align: center;""><span class=""math-container"">\$2\$</span></th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td style=""text-align: right;"">a quote</td> | |
<td style=""text-align: center;""><span class=""math-container"">\$1\$</span></td> | |
<td style=""text-align: center;""><span class=""math-container"">\$2\$</span></td> | |
<td style=""text-align: center;""><span class=""math-container"">\$1\$</span></td> | |
</tr> | |
<tr> | |
<td style=""text-align: right;"">not a quote</td> | |
<td style=""text-align: center;""><span class=""math-container"">\$0\$</span></td> | |
<td style=""text-align: center;""><span class=""math-container"">\$1\$</span></td> | |
<td style=""text-align: center;""><span class=""math-container"">\$0\$</span></td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
<p>which fortunately simplifies pretty nicely to <code>Ḃ+</code>. <span class=""math-container"">\$0\$</span> is anything non-string, <span class=""math-container"">\$1\$</span> is an opening quote or anything inside a string, and <span class=""math-container"">\$2\$</span> is a closing quote or the first quote of an escape pair.</p> | |
<pre><code>=”' For each character, is it a quote? | |
Ż Prepend a 0, then | |
Ḃ+¥\ scan by the table. | |
ƙ Group the input | |
Ż with a 0 prepended | |
€ by the cumulative number of zeroes in the scan result | |
×ḂƲ multiplied by the result mod 2, | |
Ḋƙ remove the opening quote from each group, | |
Ḋ and remove the 0 group (everything outside a string). | |
</code></pre> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>Œ!s2Ṣ€ṢƊ€Q</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FluOTlIsNnq4c9GjpjVA8lgXkA5cUpyUXLz6cPvRSQ93zgAKRELULo42i4VqAwA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>Now that it's been beaten, I'll post my own answer (also <a href=""https://chat.stackexchange.com/transcript/240?m=61551172#61551172"">previously shared in chat</a>).</p> | |
<p>Explanation:</p> | |
<pre><code>Œ! permutations of (implicit range from 1 to) n | |
Ɗ€ for each permutation: | |
s2 split into chunks of 2 | |
Ṣ€ sort each pair | |
Ṣ sort the list of pairs | |
Q remove duplicates | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>Œ!HĊĠ€Ṣ€Q | |
</code></pre> | |
<p><a href=""https://tio.run/##fZc9ThxBEIVzn2IskVgaCbHT9XMEp4RotaETiws4IIAEiZATICdOfAEkMuAg@CLjWZjeberV6w12Z7u@6VfTb6u69@ePy8tf8/x6//X7y93Lw7@bv2@Pv5f38/n59uNq/379dLg@ufry/Of028U8bzfjsN1uz8Zhs1tey5dyHFiupnEo78P7kWl/sWlHyjoyrTcr3rx8yjjo4ZYakVUMI7pGJBGOs9UIzlYjONsx6ThbaWebsogesq8RaWf7lIG0WU9ZRGGJNcwmECmQgYasy2qGczOWTxsHh6WvhK1mcsJXwjrGMpVKcJVKcJWjrUxFWxXpEX546khYq5Jmau3TSo9wWgoeVIwSSjP18LTaKZ64YpFAXyKBvmAhMhXufiS4Cnc/Euh@JND9SnD3I6FUhbtfCe5@JJRmyt3HZhdXLBLoSyTQF2ycTEXaqtAewVW07RKpirYq0iPQ/dI6N2XuR0KpigUV9MWDilFCaaYenlY7m1NcsUigL5FAX3CjYyqFuh8JrqLtTpSqKHReRhzrJhLWqqSZGuwijHB6NPCgYpRQmqnDTsQPE3HFNHNfegTWCx5MmEqhVamZ@6mKUPc16zClR6D7mrmfZmpwUmGE06Ocw6mLEUIzdTipVMIy9z/9ki3rDtIjsI9Z5n6qUmi3NOI@qgitSst2oNIjsCot6zBppkrdN9Jh0Benf5GMuM8J/JPjxH2jBO4vTrqDAlHoLubEfU5wFaHd0on7nMBu6cR9o4RQFaVV6aTDKCWEZmro/m73Hw"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Œ! All permutations of [1 .. n]. | |
H Halve each number in each permutation | |
Ċ rounding up, | |
Ġ€ group indices of equal values in each, | |
Ṣ€ sort each index-grouping, | |
Q and uniquify. | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>ŒcœcHFQƑ$Ƈ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATUAyv9qZWxsef//xZJjxZNjSEZRxpEkxof/LMOHxZLhuZgkSylq4oG@wrbCtv//MiwgNCwgNiwgOA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>ŒcœcHFQƑ$Ƈ - Main link. Takes n on the left | |
Œc - Unordered pairs | |
H - Halve | |
œc - Combinations without replacement of length n/2 | |
$Ƈ - Keep those for which the following is true: | |
F - When flattened, | |
Ƒ - the list is unchanged after | |
Q - deduplication | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ḢɓḟḲOȯ€1S%4ị⁾'2⁹;ḣƲ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjkUnJz/cMf/hjk3@J9Y/alpjGKxq8nB396PGfepGjxp3Wj/csfjYpv///7uqK7gaKbiCoDoA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>There's probably shorter! Calculates the rotation, R, using the sum of the ordinals of the characters trailing each letter or <code>1</code> if none exists modulo 4. Concatenates <code>'</code> or <code>2</code> to the leading letter depending on R mod two and then heads this to the first (up to) R characters.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>ị+D€FVƝƊ⁹¡¥ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASgA1/9qZWxsef//4buLK0TigqxGVsadxorigbnCocKl/8Onw75H//80MP80"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>1-indexed, takes <span class=""math-container"">\$m\$</span> on the right and <span class=""math-container"">\$n\$</span> on the left to give the <span class=""math-container"">\$n\$</span>th term of the sequence.</p> | |
<p>It seems like there should be a non-naive method as well, but the patterns that manifest in the single digits may not be as real as they seem.</p> | |
<pre><code> ⁹¡ Repeat m times | |
+ ¥ starting with n + m: | |
D€ digits of each | |
€ (implicitly rangifies on first iteration), | |
F flatten, | |
VƝ concatenate each pair of adjacent digits into an integer. | |
ị Get the n'th element of the result. | |
</code></pre> | |
" | |
"48934","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>‘RDFṡ2ḌƲ⁴¡³ị | |
</code></pre> | |
<p><a href=""https://tio.run/##AScA2P9qZWxsef//4oCYUkRG4bmhMuG4jMay4oG0wqHCs@G7i////zEy/zI"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"48934","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ṢṚ⁼ȧ߀Ạ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzkUPd8561LjnxPLD8x81rXm4a8H///@jo6NjY3UUoCQYxwIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><a href=""https://tio.run/##fZe7UQRBDER9oiAAGUcARKI6E4ciAUxwyAEHCgcHlyqgsMAhjSOR5bjbj2b69Xq7Wu2MpFG3ei4vrq6uh2H3/rR7v/@9@fx5/n74vX3ZfTwOX6@7t6fvu/Ov171hGPIkcxunZ9vYP@R2edw/F3s0n/6/Vc/I9r11378dv2@Wxbr1Dgs2G0T2Ftklpjg2JY7O6fCWEmxnmiNsMpAk2u0OP0WKafyvSZby70twrEFblUi1QWliLuCmFlAcp2pIpbVqkXgAcAb91ktdemNXrVIbPcQ@oqNXQpNIa8IBR2mEvlu0taUbAlpkXJCbC/qrTxPaZ9pF/@5baN5Fe7Q7juPWkWCk5g3T5OoqBZ0TUisgoNaphYoEwECzWPNwE8SNkOtgGElWxGIsqN00qAXnGXwKcQJqpME@wl/DKDAUs8CzQhFYROOb4Qh8BdBFjonKR0JcRABASoFcVcBJXId0p8kjk1WQAj2StyNOObQKVjEzp4blX3KHgjewBcZ2RM5cDsG4ebAyEtamgvTFuGXi6FSdgTMj6nzRGQpqhSZHJNub8aPzVGcVBFNIMHmw0nSzUw/CHDclyNDwo5k474iHqqtMebq57ka7m@52wOOMJxWrg3pKKIwmQMGZRnUauYEVI/uSp9UdJD0ElagK5vRRlYRVMOQOjcf6YCmLKnCnpYyccooKlEKpltVVIK16wh6LG4lmVl1hFRq5K2EvR4eajAQcEfZ0phAMEfbSArjMmm6EMJXfSkOC3cjK8CIUfwBuKk3pFK4VuaxzoQ4rN0Unl9cUM4pmPUen/J34d/rfXgHcLcBeBNxdYO064G4E9lKwdi9YvRpMeD/Z/gE"" rel=""nofollow noreferrer"">Test all cases given</a></p> | |
<h2>Explanation</h2> | |
<pre><code>ṢṚ⁼ȧ߀Ạ given a candidate list: | |
ȧ check that the following two conditions are satisfied: | |
⁼ 1. the list is equal to | |
Ṛ the reverse of | |
Ṣ the sorted version of the list | |
߀Ạ 2. and the same is true for every element in the list | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>13</s> 11 bytes</h1> | |
<pre><code>ŻṖ‘ż¹FQµIỊa | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o7oc7pz1qmHF0z6GdboGHtno@3N2V@P9w@9FJD3fO0Iz8/z/aUMdIx1jHRMfIQMcIyDaK1YEKmeqYAdkQSUsgCyRirmOhY2gAUQJUbxwLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><code>0</code> for ellipses.</p> | |
<pre><code>Ż Prepend a 0, | |
Ṗ trim the last element, | |
‘ increment, | |
ż¹F flat-interleave with the original input, | |
Q and uniquify. | |
µ a Zero out any elements of the result which | |
I have a difference with the next element | |
Ị greater than 1. | |
</code></pre> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>⁸©µ⁹µ®1ị®Ḣ¤0=?) | |
</code></pre> | |
<p><a href=""https://tio.run/##AVcAqP9qZWxsef//4oG4wqnCteKBucK1wq4x4buLwq7huKLCpDA9Pyn///9nY3VqeGxi/3ogd3pzZ292aGggam9wdyBpZ2N4IG11eGogeG1taXN4ZG4gdCBsbWI"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Absolutely TERRIBLE.</p> | |
<pre><code>⁸©µ⁹µ®1ị®Ḣ¤0=?) - Dyadic link f(k, s) where k is the "word" and s is the "sentence" | |
⁸© - Copy k to the register | |
µ - Begin a new monadic chain f(s) to prevent k from being implicitly printed | |
⁹µ ) - Map over s: | |
®1ị - Get the first character of the register | |
=? - Is it equal to the current character in s? | |
®Ḣ¤ - If so, then remove the first character from the register and push it | |
0 - Else, just use 0 | |
</code></pre> | |
" | |
"25180","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <del>34</del> <del>32</del> <del>30</del> <del>29</del> 28 bytes</h1> | |
<pre><code>R©ạÞḣ5;⁸’¤;2ḣ⁸Ṭµ+3\Ịݬo×®Œg§ | |
</code></pre> | |
<p><a href=""https://tio.run/##AUQAu/9qZWxsef//UsKp4bqhw57huKM1O@KBuOKAmcKkOzLhuKPigbjhuazCtSszXOG7isW7wqxvw5fCrsWSZ8Kn////MTL/Ng"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Thanks to Unrelated String for -2 byte.</p> | |
<h3>Explanation (outdated)</h3> | |
<pre><code>R© Range and copy to register. | |
Þ Sort by... | |
ạ Absolute difference with p. | |
ḣ5 First 5 elements. | |
;⁸’¤;2 Append n-1 and 2. | |
®œ& Intersection with register, for the special case that n=1. | |
Ṭ Untruth (boolean array from truthy indices). | |
µ Chain separator. | |
ṡ3 All slices with length 3. | |
§ Sum each slice. | |
2= True if equals to 2. | |
1; Prepend 1. | |
| Vectorized OR with the result of the previous chain. | |
×® Vectorized multiplication by the register. | |
Œg Group nearby equal elements. Only possible for the zeros. | |
§ Sum each group. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 4 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>żḢF) | |
</code></pre> | |
<p>A monadic Link that takes, as allowed in the comments, a list of words and yields a list of words.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///onoc7Frlp/n@4Y9Phdu///4tSy1KLilMVSjJSFdIyi4pLFErK8xVyUktKgMIK@WkKqYnJGQrl@UUpAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>żḢF) - Link: list of lists of characters, words e.g. [..., "upend", ...] | |
) - for each word: | |
Ḣ - head (word) -> remove and get the first character "u" | |
ż - (beheaded word) zip with (head character) ["pu","e","n","d"] | |
F - flatten that back into to a list of characters "puend" | |
</code></pre> | |
<p>Also requires no empty words, also allowed in the comments (as <code>Ḣ</code> would yield a zero).</p> | |
<p>Note: I would say that the <code>F</code> is necessary since without this flatten a callable link would return each new word as a list of lists of characters while as a full program it would smash the characters together when it prints.</p> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, <sup><s>10</s> <s>7</s></sup> 6 bytes</h1> | |
<pre><code>U2œ?U)</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FstDjY5Otg_VXFKclFy8-HC7N0T4pnu0UrR6UWpZalFxqrqOgnpJBphKyywqLgHzy_NBVE5qSQlQCYiZnwYiUxOTM0B0eX5RinqsUizUGgA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>-3 bytes by doing I/O as a list rather than a space-separated string, now that the OP has allowed that.</p> | |
<p>-1 thanks to @Unrelated String</p> | |
<p>Explanation:</p> | |
<p>Given a word <span class=""math-container"">\$ a_n \cdots a_3 a_2 a_1 \$</span>, the permutation <span class=""math-container"">\$ a_n \cdots a_3 a_1 a_2 \$</span> is at index 2 in the list of permutations of that word.</p> | |
<pre><code> ) map over each word: | |
U reverse | |
2œ? index 2 into all permutations of the reversed input | |
U (un-)reverse | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>Ḳµḣ2Uo)K | |
</code></pre> | |
<p><a href=""https://tio.run/##HcwxDsIwDIXhqzxlQ2LiGswMjFFxSJEbV4lF25WFg3RlQkLqDCcpFwkJkid/ev@FmKec1@X5fq3LvDvIZp8/9@/tcczZ@KKCQSKfzBZGfZtQzgaQTRMab5kpnKlipCvFRFBPcG1MCh0ETKrlDXFl0vja@qf6XseakkDVRMaO4SR2ViubHw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>Ḳµḣ2Uo)K - Main link. Takes a string | |
Ḳ - Split by spaces | |
µ ) - Over each word: | |
ḣ2 - Take the first two characters | |
U - Reverse them | |
o - Logical Or, overwriting the first two characters of the word | |
K - Join with spaces | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>:Ƭ2*@ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/q2BojLYf///8bGf43BgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <code>n</code> on the left, and <code>x</code> on the right. Based on <a href=""https://codegolf.stackexchange.com/a/249464/66833"">Steffan's answer</a>, so be sure to give them an upvote as well.</p> | |
<h2>How it works</h2> | |
<pre><code>:Ƭ2*@ - Main link. Takes n on the left and x on the right | |
Ƭ - Repeatedly apply until a duplicate value is found: | |
: 2 - Floor divide n by 2 | |
*@ - Raise x to each power | |
</code></pre> | |
" | |
"92689","<h1><a href=""https://github.com/Vyxal/Vyxal"" rel=""nofollow noreferrer"">Vyxal</a>, 5 bytes</h1> | |
<pre><code>‡½⌊↔e | |
</code></pre> | |
<p><a href=""https://vyxal.pythonanywhere.com/#WyJBUCIsIiIsIuKAocK94oyK4oaUZSIsIiIsIjIxLCAzXG4wLCAxMDAwXG4xNSwgMlxuNDAwMDAsIDFcbjMsIDIxIl0="" rel=""nofollow noreferrer"">Try it Online!</a></p> | |
<p>Takes inputs in reverse order.</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>HḞ$Ƭ*@ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/j4Y55KsfWaDn8///fyPC/MQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes inputs in reverse order.</p> | |
<h2>Explanation</h2> | |
<pre><code>HḞ$Ƭ*@ Dyadic link f(n, x) | |
Ƭ Repeatedly apply on n until the results are no longer unique | |
$ Last two links as a monad: | |
H Halve | |
Ḟ Floor | |
*@ x to the power of each | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ḊÐḟ¹-Ƥf¥Ƈ@Ƭ⁸ẎṪ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of characters and returns a list of characters or zero (falsey) if no solution is possible.</p> | |
<p><strong><a href=""https://tio.run/##RVExTsQwEPwKXRr4A/9AFJsQxz6cHIqNopRUSBSIH9AczekekKO8k/KP3EcM2RlD47F3Z2Znk03t/ZjSMr2dP5bp83S8mXfm9DW/3s6Hy8u0fL8vx31K6a6QUFxfFW49rNN7tBJXfHJdQ1SKngP4YEQqBirwcnqX7kHhX1oJfAzaOpEsn9kVtOERnFHnS6/VFpq2JrJtkShEehjp2xVroYrBHdrlFvWeCUirJUTsB7VhFMN6Txtm@ZXhIi2qCgGrx0wO8G6Q0OcZBjTj0a4AJarVlqzAfUomtOivX2PkQg3/iFUe9yU9PHPKX7nL/hhH@4FR8xSqxcfi/gc"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ḊÐḟ¹-Ƥf¥Ƈ@Ƭ⁸ẎṪ - Link: list of lists of characters (words), W | |
Ðḟ - filter out those for which: | |
Ḋ - dequeue (i.e. remove words of length > 1) | |
(let's call this list of single-character words S) | |
⁸ - with W as the right argument... | |
Ƭ - collect up input, I (initially S), while distinct applying: | |
@ - with swapped arguments - f(W, I): | |
Ƈ - filter keep those (w in W) for which: | |
¥ - last two links as a dyad - f(w, I): | |
Ƥ - for overlapping outfixes (of w)... | |
- - ...of size: -1 (i.e. outfixes of length one less) | |
¹ - ...do: nothing | |
(i.e. get all potential sub-words of w) | |
f - filter keep -> sub-words which are in I | |
(an empty list is falsey) | |
-> words in W which can be shorted to any of those in I | |
-> reachable word lists ordered by word-length plus an empty list | |
Ẏ - tighten -> list of all words reached | |
Ṫ - tail -> (one of) the longest one(s) or 0 if empty | |
</code></pre> | |
<p>...that's some pretty serious Jelly right there I reckon.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>H߀S‘ | |
</code></pre> | |
<p>A recursive, monadic Link that accepts a non-negative integer and yields the number of binary partitions.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/j8PxHTWuCHzXM@P//v5kBAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/j8PxHTWuCHzXM@H@4Hcj6/78oMS89VcNAx8xAEwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>H߀S‘ - Link: integer, n | |
H - halve -> n/2 | |
€ - for each i in [1..floor(n/2)]: | |
ß - call this Link with argument n=i | |
S - sum | |
‘ - increment | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>11</s> <s>8</s> 6 bytes</h1> | |
<p>Uses inverted boolean output.</p> | |
<pre><code>IÐƤÄPẸ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/z8IRjSw63BDzcteP/4fZHTWuA6P//6GiuaEMdBcNYHQgNZRrrKACROZAE8Yx0FIzAciAGVADKgwoYgtXDSSTjjMGKjGEakC1CQlCZWB2Ic2BmImmAGGICdRzCPoQAVAzFOahiCDfDPITDOWAncMXGAgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> ÐƤ # Map over each suffix: | |
I # Increments (differences between adjacent elements) | |
Ä # For each list, get cumulative sums | |
PẸ # Is there a zero in each column? | |
</code></pre> | |
<p>This is basically: <em>Is there a zero on each diagonal of the subtraction table?</em>. The naive implementation would be:</p> | |
<pre><code>_þ`ŒDP€Ẹ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/@8L6Eo5NcAh41rXm4a8f/w@1ABhD9/x8dzRVtqKNgGKsDoaFMYx0FIDIHkiCekY6CEVgOxIAKQHlQAUOwejiJZJwxWJExTAOyRUgIKhOrA3EOzEwkDRBDTKCOQ9iHEICKoTgHVQzhZpiHcDgH7ASu2FgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 19 </s> 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ø.ṗṣ1ZṫɗƇ_⁵AP€S | |
</code></pre> | |
<p>A full program accepting <code>n</code>, <code>k</code>, and <code>p</code> that prints the result.</p> | |
<p><strong><a href=""https://tio.run/##AS4A0f9qZWxsef//w5gu4bmX4bmjMVrhuavJl8aHX@KBtUFQ4oKsU////zEw/zP/MC42"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (<code>n=100</code> is too big for such an inefficient program.)</p> | |
<h3>How?</h3> | |
<p>Creates all <span class=""math-container"">\$2^{n}\$</span> possible outcomes, filters them to those containing a run of at least <span class=""math-container"">\$k\$</span> heads and then sums the probability of each occurrence.</p> | |
<p>The probability of a given occurrence is the product of <code>p</code>'s and <code>(1-p)</code>s identified by heads and tails respectively. For example the chance of <code>[tails, tails, heads, heads, heads]</code> is the product of <code>[(1-p), (1-p), p, p, p]</code> i.e. <span class=""math-container"">\$p^3(1-p)^{2}\$</span>.</p> | |
<pre><code>Ø.ṗṣ1ZṫɗƇ_⁵AP€S - Main Link: integer n, integer k (p is accessed later) | |
Ø. - [0,1] | |
ṗ - ([0,1]) Cartesian power (n) | |
-> all length-n tosses with 0 as heads and 1 as tails | |
Ƈ - filter keep those for which: | |
ɗ - last three links as a dyad - f(Outcome, k): | |
ṣ1 - split at 1s -> runs of heads | |
Z - transpose | |
ṫ - tail from index k -> empty (falsey) if longest run < k | |
⁵ - third program argument, p | |
_ - subtract -> valid outcomes with heads: -p; tails: 1-p | |
A - absolute values -> valid outcomes with heads: p; tails 1-p | |
P€ - product of each -> valid outcome probabilities | |
S - sum -> total probability of any valid outcome | |
</code></pre> | |
<hr /> | |
<p>If we could take the probability of tails (<span class=""math-container"">\$1-p\$</span>) instead of heads (<span class=""math-container"">\$p\$</span>) 14 byes taking <code>1-p</code>, <code>n</code>, <code>k</code>:</p> | |
<pre><code>C©Ƭṗṣ®ZṫɗƇ⁵P€S | |
</code></pre> | |
<p><a href=""https://tio.run/##AS4A0f9qZWxsef//Q8KpxqzhuZfhuaPCrlrhuavJl8aH4oG1UOKCrFP///8uNP8xMP8z"" rel=""nofollow noreferrer"">Try it online!</a></p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>23</s> <s>20</s> 16 bytes</h1> | |
<pre><code>OḂŒgÄ=U×ƊF€Sm2HĊ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9//4Y6mo5PSD7fYhh6efqzL7VHTmuBcI48jXf8f7t5yuL3EwFsz8v//aCUlpRguBQxgi8rFoqIGTYUtIcCFaUINTlvguvC6o4awGVAVtjjMqIGbgWQOMEx0uKABY6sAcjhQCUIQ4S6Yv2qQQwVdIUogKGAoh9BgUZjBNWhG1yCprQGrRXMCXG0NktoaVFfDNNkihQKSv9Edy6UAD5ca9DBRUMAVsTVww1F9jQj0GiQ1iChCjpgadDUYIjUoIohoRqipQVUDdHcsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-3 thanks to Jonathan Allan, also opening up another -1 (<code>×=¥UFƊ€</code> -> <code>=U×ƊF€</code>)</em></p> | |
<pre><code> Ä Ɗ Consider the cumulative sums of | |
Œg the runs in each row of | |
OḂ whether or not each character is an equals sign | |
Ḃ (ones bit of | |
O the codepoints). | |
= For each element of each cumsummed run, is it equal to | |
U the corresponding element of the run backwards? | |
× Multiply it by the result. | |
F€ Flatten each row, | |
S Sum each column, | |
m2 remove alternating elements, | |
H halve, | |
Ċ and ceiling. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>32r126Ọs⁴Y | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/YqMjQyOzh7p7iR41bIv//BwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>5 if we can just use our langauage's features:</p> | |
<pre><code>ØṖs⁴Y | |
</code></pre> | |
<h3>How?</h3> | |
<pre><code>32r126Ọs⁴Y - Link: no arguments | |
32 - 32 } | |
126 - 126 } | |
r - inclusive range } | |
Ọ - cast to ordinals } - together this is the same as ØṖ yields | |
⁴ - 16 | |
s - split into chunks of length (up to 16) | |
Y - join with newline characters | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ŒṖḌIİƑ$ƇḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIc7pz3c0eN5ZMOxiSrH2h/uWPT/cLu3ZuT//4ZGxiY6CuYWloYGhoY6CmZmZuY6CkaWxgbGhsZGxsYgSUtLoKSBAZBhaGAJUgRWCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ŒṖ Find every partition of the input's digits, | |
Ḍ and convert each slice in each partition back to an integer. | |
Ƈ Filter to only those which | |
I have forward differences | |
İƑ$ which are all their own inverses (i.e. 1). | |
Ḣ Yield the first remaining partition (nontrivial). | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 bytes</h1> | |
<pre><code>Œṗf³$ƑƇœ&/¹¡L | |
P!Ç€Ṁ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATEAzv9qZWxsef//xZLhuZdmwrMkxpHGh8WTJi/CucKhTApQIcOH4oKs4bmA////WzEsIDNd"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 thanks to Jonathan Allan.</p> | |
<p><a href=""https://github.com/Vyxal/Vyxal/issues/1201"" rel=""nofollow noreferrer"">Unlike Vyxal</a>, Jelly's multiset intersection appears to work properly.</p> | |
<p>This is roughly <span class=""math-container"">\$O\left(2^{\left(\prod{s}\right)!}\right)\$</span>. I'm pretty sure using <a href=""https://github.com/cairdcoinheringaahing/jellylanguage/"" rel=""nofollow noreferrer"">caird's fork</a> would save a few bytes but I can't be bothered for now.</p> | |
<pre><code>P!Ç€Ṁ Main link (takes a list of numbers) | |
P! Factorial of product | |
€ Map over 1...n | |
Ç Helper (see below) | |
Ṁ Take maximum | |
Œṗf³$ƑƇœ&/¹¡L Helper link (takes argument n) | |
Œṗ Integer partitions | |
Ƈ Filtered by... | |
$Ƒ Same under | |
f³ Remove all but input | |
/ Reduce by | |
œ& Multiset union | |
¹¡ N times | |
L Get final length | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 170 bytes</h1> | |
<pre><code>“¡¢£¤¥¦©¬®µ½¿€ÆÇÐÑרŒÞßæçðıȷñ÷øœþ”;ØṖ⁵Ż+⁽ø9Ọ“¶°¹²³”;“ƁƇƊƑƓƘⱮƝƤƬƲȤɓƈɗƒɠɦƙɱɲƥʠɼʂƭʋȥẠḄḌẸḤỊḲḶṂṆỌṚṢṬỤṾẈỴẒȦḂĊḊĖḞĠḢİĿṀṄȮṖṘṠṪẆẊẎŻạḅḍẹḥịḳḷṃṇọṛṣṭ§Äẉỵẓȧḃċḋėḟġḣŀṁṅȯṗṙṡṫẇẋẏż”⁾«»⁾‘’⁾“” | |
</code></pre> | |
<p><a href=""https://tio.run/##HZBdUlpBEIUXlBVYWU9eLDeQt3sRwYAmClUCiT/8XKASEQGDdM8oVnXPnbqXXZzZCI4@dVefr8451Yffjo6@7/chuZaBDGUkmYxlIn9lJnNZy6u8hcpMa1rXC73Ujnbzlt7qnU50qgu3LDa61I1S3tZtSG6@ahd8FdJ1br@E9FXpAPbsw/tZFsKykqcPKB586uu@4S9923fDcu5vfOZnflVkZduflh3fKvvlxPfKZbny412/fNlV/MOuWYxh@qAq6AyGQBlsA7QCPYMr4FpMA/8GD8Ez2Ay8hTmF/Q/TKiagiot0w12Bbl20GbqFewMn4Goxj73BsX0f/A@mBtOA@ZlbmAHoBHQOw6AxbBP0BNqAj8F12HPwH/AI/CBTrcL8gF3DtIsp6NhFtuk6oDsXTUZ5DErBJ8UjuAPugQfge5g6TBPmV/4SfxPSrdyLjSMk3ZD0PpfrKOz37w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Builtins are boring, so here is a slightly-less-but-still-kinda-boring answer. Despite multiple attempts to shorten the code by manipulating the code points, it turns out that string literals are the way to go.</p> | |
<p>That said, we do use some actual encoding in places, and use a couple of tricks to save bytes. The main trick used is "unparseable nilads": when Jelly encounters a nilad that doesn't form one of the <a href=""https://codegolf.stackexchange.com/a/71001/66833"">chaining patterns</a>, then the current value of the chain is printed, and the nilad becomes the argument to the rest of the chain.</p> | |
<p>Outputs a newline instead of <code>¶</code></p> | |
<h2>How it works</h2> | |
<pre><code>“¡¢...øœþ”;ØṖ⁵Ż+⁽ø9Ọ“¶°¹²³”;“ƁƇƊ...ẋẏż”⁾«»⁾‘’⁾“” - Main link. No arguments | |
“¡¢...øœþ” - String literal | |
ØṖ - Printable ASCII | |
; - Concatenate | |
⁵ - Unparseable nilad. Output the characters, and continue with 10 as argument | |
Ż - Zero range; [0, 1, ..., 10] | |
⁽ø9 - Compressed integer: 8308 | |
+ - Add to each; [8308, 8309, ..., 8318] | |
Ọ - Convert from code points | |
“¶°¹²³” - String literal | |
; - Prepend; [182, 176, ..., 179, 8308, ..., 8318] | |
“ƁƇƊ...ẋẏż” - Unparseable nilad: string literal | |
⁾«» - Unparseable nilad: "«»" | |
⁾‘’ - Unparseable nilad: "‘’" | |
⁾“” - Unparseable nilad: "“”" | |
</code></pre> | |
<p>Note that we have to use <code>⁾«»</code>, <code>⁾‘’</code> and <code>⁾“”</code> as all these characters are special characters in strings.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>13</s> <s>12</s> 11 bytes</h1> | |
<pre><code>ȷ2ḍ41*ạµ¹Ð¿ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///EdqOHO3pNDLUe7lp4aOuhnYcnHNr/X@fhjlagxOH2FCCZ9ahpzaOGuVZch5fre2tG/v8fbaCjYGkQq6MQbaijYARmGIFFAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 thanks to Zion mycelia adamancy, and another -1 with inspiration from their suggestion</em></p> | |
<p>Uses flat integer I/O.</p> | |
<p>Could almost be 10 (<code>ạ41$’ọ?Ƭȷ2</code>), but that fails for inputs under 41.</p> | |
<pre><code> µ¹Ð¿ Collect results to (and through) 0 from: | |
41* raise 41 to the power of | |
ȷ2ḍ if the number is divisible by 100, | |
ạ and take its absolute difference with that. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>Żṙe€ØW¬œpƊ.ị | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o7oc7Z6Y@alpzeEb4oTVHJxcc69J7uLv7/@Hl@pqR//9HKyUmJSukpKYp6SgYxeooIPNN4XwgRpJXSE5RACswgQkoAIWAfDMoXxHMM4wFAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/85770/85334"">Anders Kaseorg's Pyth answer</a>.</p> | |
<pre><code>Ż Prepend a zero as a buffer between the first and last words, | |
ṙ then rotate left by the index. | |
œpƊ Partition that result around | |
€ ¬ elements which are not | |
e ØW word characters, | |
.ị then take the last and first slices | |
and smash-print them together. | |
</code></pre> | |
<p>Original:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>xðe€ØW¬Ä÷Ɗ=ị@¥ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/i8IbUR01rDs8IP7TmcMvh7ce6bB/u7nY4tPT/4eX6mpH//0crJSYlK6SkpinpKBjF6igg803hfCBGkldITlEAKzCBCSgAhYB8MyhfEcwzjAUA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> eۯW For each element, is it a word character? | |
Ä Take the cumulative sum | |
¬ of the negations | |
÷Ɗ and divide by the original Booleans. | |
= For each value in the result, is it equal to | |
ị@¥ the one at the index? | |
xð Filter the string to truthy positions. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>Ż+¥¡1 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///obu1DSw8tNPz/39AUAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Full program taking <span class=""math-container"">\$n\$</span> from STDIN and outputting coefficients ascending.</p> | |
<p>It's always felt a bit silly that the only "repeat" quick is designed for Fibonacci-like recurrences, but when it comes up I can't say it isn't useful.</p> | |
<pre><code> Since this is invoked as niladic, the initial left argument is 0. | |
1 Starting with 1 on the right, | |
¡ repeat n times | |
¥ with the previous left argument replacing the right argument: | |
+ vectorized add the right argument to | |
Ż the left argument with a prepended 0. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 25 </s> 24 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-1 using <a href=""https://codegolf.stackexchange.com/a/249092/53748"">ais523's trick</a> of using integer division to place <code>inf</code> as walls.</p> | |
<pre><code>Ø1Wạ§ỊɗƇⱮẎQɗ@ƬŒMŒṬSFṀ_Ɗ: | |
</code></pre> | |
<p>A monadic Link that accepts the grid with <code>1</code> as space and <code>0</code> as wall and yields another grid containing the fill distances at spaces and <code>inf</code> at walls.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wDMPwh7sWHlr@cHfXyenH2h9tXPdwV1/gyekOx9YcneR7dNLDnWuC3R7ubIg/1mX1/3C7@///0dGGOgpAZAAkY7l0oDxDKM8AIoFFLhYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ø1Wạ§ỊɗƇⱮẎQɗ@ƬŒMŒṬSFṀ_Ɗ: - Link: Grid | |
Ø1 - literal [1, 1] | |
W - wrap -> [[1, 1]] | |
ŒM - maximal multidimensional indices of Grid -> space coordinates | |
Ƭ - start with A=[[1, 1]] and collect up while distinct applying: | |
@ - with swapped arguments: | |
ɗ - last three links as a dyad - f(space coordinates, A): | |
Ɱ - map (for a in A) with: | |
Ƈ - keep those (s in space-cordinates) for which: | |
ɗ - last three links as a dyad - f(s, a): | |
ạ - absolute difference | |
§ - sums | |
Ị - insignificant? -> is s a neighbour of, or equal to, a? | |
Ẏ - tighten -> flat list of neighbours | |
Q - deduplicate | |
ŒṬ - multidimensional grids with 1s at those indices | |
S - sum -> 0 at walls, 1 at furthest, 2 at next nearest, etc. | |
Ɗ - last three links as a monad - f(X=that): | |
F - flatten | |
Ṁ - maximum -> value at top-left | |
_ - subtract X (vectorises) | |
: - integer divide by the grid -> keeps space values, replaces wall with inf | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ḥ’R_"ƲĖS€;€"ẎQƑ | |
</code></pre> | |
<p>A dyadic Link that accepts the widths on the left and the heights on the right and yields <code>0</code> if there are collisions or <code>1</code> if not.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjiWPGmYGxSsd23RkWvCjpjXWQKz0cFdf4LGJ////jzbSAUEDIDQBYmMg2zAWJGqgYwgWhcgZ6hjFAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hjiWPGmYGxSsd23RkWvCjpjXWQKz0cFdf4LGJ/w8vd9AHcv//j46ONtIx0DEEYgMdIzBpqGMUy6WgAxQ3goqYALExkG0YG8ulEx0NUQ7EcGUgnjFC0gio2gQqCeKZAHlwSUOwBMgyI5ggFEIlIG4xwS4JcRDIrlgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Ḥ’R_"ƲĖS€;€"ẎQƑ - Link: widths, heights | |
Ʋ - last four links as a monad - f(widths): | |
e.g. widths = [3,2,0,1] | |
Ḥ - double [6,4,0,2] | |
’ - decrement [5,3,-1,1] | |
R - range [[1,2,3,4,5],[1,2,3],[],[1]] | |
" - zip with: | |
_ - subtract [[-2,-1,0,1,2],[-1,0,1],[],[0]] | |
Ė - enumerate [[1,[-2,-1,0,1,2],],[2,[-1,0,1]],[3,[]],[4,[0]]] | |
S€ - sum each [[-1,0,1,2,3],[1,2,3],[],[4]] | |
" - zip with heights applying: | |
;€ - concatenate (the current height) to each | |
Ẏ - tighten | |
Ƒ - is invariant under? | |
Q - deduplicate | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>9</s> 7 bytes</h1> | |
<pre><code>+HfḊʋÐḟ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/1/bI@3hjq5T3YcnPNwx///hdm/NyP//ow11FIx0FIxjdRRgTB0FEygPxNRRMIXyTHUUDA2ASoDYxAAhZgYSRtUOUWhqBKLBOlDlgZosgFJAlhHIEpNYAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> Ðḟ Remove elements for which | |
+ that element plus each element of the list | |
H halved | |
Ḋ has more than one element | |
f ʋ after being filtered to only elements of the original list. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 23 bytes</h1> | |
<pre><code>Ḥ’R_"+"JJṗL;Ɱ"ẎQƑɗƇƲṀÞḢ | |
</code></pre> | |
<p>A monadic Link that accepts a list of non-negative integers and yields a list of positive integers specifying the levels (i.e. 1-indexed heights).</p> | |
<p><strong><a href=""https://tio.run/##AT8AwP9qZWxsef//4bik4oCZUl8iKyJKSuG5l0w74rGuIuG6jlHGkcmXxofGsuG5gMOe4bii////WzIsMiwwLDEsM10"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Inefficient brute-force...</p> | |
<pre><code>Ḥ’R_"+"JJṗL;Ɱ"ẎQƑɗƇƲṀÞḢ - Link: cap sizes | |
Ḥ - double (the cap sizes) | |
’ - decrement (these) | |
R - range (those) - i.e. [[1..2*n-1] for each cap size, n] | |
" - zip (those) and (cap sizes) applying: | |
_ - subtraction - i.e. make these offsets like [...,-1,0,1,...] | |
J - range of length (cap sizes) -> [1..length(cap sizes)] | |
" - zip (the offsets) with (the range) applying: | |
+ - addition -> covered indices of each mushroom, "covers" | |
Ʋ - last four links as a monad - f(covers): | |
J - range of length -> same as [1..length(cap sizes)] | |
L - length -> same as length(cap sizes) | |
ṗ - (range) Cartesian power (length) | |
-> all lists of the same length as cap sizes | |
using alphabet [1..length(cap sixes)] | |
Ƈ - filter keep those (arrangements) for which: | |
ɗ - last three links as a dyad - f(arrangement, covers): | |
" - zip with: | |
Ɱ - map with: | |
; - concatenate -> coordinates | |
Ẏ - tighten | |
Ƒ - is invariant under?: | |
Q - deduplicate | |
Þ - sort by: | |
Ṁ - maximum value | |
Ḣ - head | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒcSe¥ƇḤFḟ@ | |
</code></pre> | |
<p>A monadic Link that accepts a list of positive integers and yields the filtered list.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opOTg1ENLj7U/3LHE7eGO@Q7///@PNtRRMNJRMNZRMNFRMDTQUTA1AtFAhpGBQSwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ŒcSe¥ƇḤFḟ@ - Link: list L | |
Œc - ordered pairs (L) | |
Ḥ - double (L) (vectorises) | |
Ƈ - filter the pairs keeping those for which: | |
¥ - last two links as a dyad - f(pair, doubled L) | |
S - sum (pair) | |
e - exists in (doubled L)? | |
F - flatten (this list of pairs whose sum is in the doubled L) | |
@ - with swapped arguments: | |
ḟ - filter discard (take L and remove the pair elements) | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>rNBḌ⁸_AÐṂ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/Iz@nhjp5HjTviHQ9PeLiz6f/hds3I//8NdBQMdRRMdBR0gdgMyDHVUTAFYSBb18JIR8HcAEjoGhoYGAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Absolutely awful...</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 12 </s> 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒJ%þ`ṪỊ§TịF | |
</code></pre> | |
<p>A monadic Link that accepts a rectangular multi-dimensional list and yields the elements that are on its "surface".</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///oJC/Vw/sSHu5c9XB316HlIQ93d7v9//8/OjraREfBQEcBSBrG6nApKEQbgPmmOgoWEL4ZmA9CcHljHQVzEB8owKUANsESqByoCa7CDGyiAbKJIH1wviVYiSHMBIgDgGZawlUYgXWYoZkANdEcYhySGyBONkZ2A4oOM5g8lG8CdoAByJexsQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ŒJ%þ`ṪỊ§TịF - Link: rectangular multi-dimensional list, M | |
ŒJ - multi-dimensional indices of M -> [[1,1,1,...],...,[height,width,depth,...]] | |
` - use as both arguments of: | |
þ - make a table of: | |
% - modulo (vectorises) | |
Ṫ - tail -> [...[x%height,y%width,z%depth,...]...] | |
Ị - abs(x)<=1? (vectorises) | |
§ - sums (of those) | |
T - truthy indices (of that) | |
F - flatten (M) (N.B. same order as the indices produced by ŒJ) | |
ị - index-into | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>2Ṛ;»Ṁ²ƊƊ¡’Bz0ZU | |
</code></pre> | |
<p>A full program that accepts a positive integer from STDIN and prints a list representation of the Bernard.</p> | |
<p><strong><a href=""https://tio.run/##AScA2P9qZWxsef//MuG5mjvCu@G5gMKyxorGisKh4oCZQnowWlX/w4dH/zQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (The footer prints the result as a grid instead of in the raw list format.)</p> | |
<h3>How?</h3> | |
<p>Builds the Bernard in chunks consisting of the equal rows, starting with the row with the single <code>1</code>. At each step we reverse what we have so far and append the next chunk. Each new chunk has as many rows as we've built so far but with double the number of <code>1</code>s.</p> | |
<p>Under the hood, each row is first calculated as one more than its binary value. This starts at <code>2</code> and squares for each new chunk.</p> | |
<pre><code>2Ṛ;»Ṁ²ƊƊ¡’Bz0ZU - Main Link: no arguments | |
2 - literal two | |
¡ - repeat STDIN times starting with X=2: | |
Ɗ - last three links as a monad - f(X): | |
Ṛ - reverse the current list | |
(2 gives its decimal digits reversed = [2]) | |
Ɗ - last three links as a monad - f(Z=that): | |
Ṁ - maximum of Z | |
» - vectorised maximum with Z -> an array of the same shape as | |
Z, all populated with the maximum value in Z | |
² - square them | |
; - (reversed X) concatenate with (that) | |
’ - decrement all the values | |
B - convert them to binary lists | |
z0 - transpose with filler zero } | |
Z - transpose } prepends zeros | |
U - reverse each | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>BṚT’߀ | |
</code></pre> | |
<p>A recursive mondaic Link that accepts <code>n</code> (0-indexed) and yields the <code>n</code>-th pure set using the empty list as the empty set.</p> | |
<p><strong><a href=""https://tio.run/##AR8A4P9qZWxsef//QuG5mlTigJnDn@KCrP/Dh8WS4bmY//8w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>BṚT’߀ - Link: non-negative integer, n | |
B - convert to binary | |
Ṛ - reverse | |
T - truthy indices (1-indexed) | |
’ - decrement (vectorises) | |
€ - for each: | |
ß - call this Link | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>OḢ;$Ḋ⁼¡µƬẈṖ | |
</code></pre> | |
<p>A monadic Link that accepts a ragged list of integers and yields the lengths as a list, including both the initial length and a trailing <code>0</code>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9//4Y5F1ioPd3Q9atxzaOGhrcfWPNzV8XDntP///0dHm@koGOsoRBuCKZPYWCAB5BqBuZZAlqmOgllsbCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9//4Y5F1ioPd3Q9atxzaOGhrcfWPNzV8XDntP86h9uPTnq4c8ajpjVZjxr36dppRv7/Hx0dbaijYBSroxBtDMQmOgqmsbGxXDrR0WY6CiARQzBlEgtUAZSMNgJzLYEsUx0FM4hSY7CUKVgXBBjGQgFQCISBhkQDDTAEKwHZBSRBJgJJrlgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>OḢ;$Ḋ⁼¡µƬẈṖ - Link: ragged list of positive integers, L | |
Ƭ - collect input, X (initially L), while distinct, applying: | |
µ - this monadic chain - f(X): | |
O - ordinal value (vectorises) -- only here to get us a copy of X | |
so that we don't mutate it with Ḣ | |
$ - last two links as a monad - f(Y=that): | |
Ḣ - head Y (alters Y, yields the first element or 0 when given []) | |
; - concatenate that with (the altered Y) | |
¡ - if... | |
⁼ - ...condition: that equals X? (head of X was an integer) | |
Ḋ - ...then: dequeue | |
Ẉ - length of each | |
Ṗ - pop the last length (removes the trailing 1, the length of 0) | |
</code></pre> | |
<hr /> | |
<p>Also 11 with no <code>Ḣ</code> and, therefore, no <code>O</code>: <code>1ị;ḊḊ⁼¡µƬẈṖ</code></p> | |
" | |
"39242","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 1 + 1 = 2 bytes</h1> | |
<pre><code>Ḃ | |
</code></pre> | |
<p><span class=""math-container"">\$f(x) = x \bmod 2\$</span> (<a href=""https://tio.run/##y0rNyan8///hjqb///8bGhkDAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a>).</p> | |
<pre><code>Ḥ | |
</code></pre> | |
<p><span class=""math-container"">\$g(x) = 2x\$</span> (<a href=""https://tio.run/##y0rNyan8///hjiX///83NDIGAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a>). These functions commute only for even input.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>1xẇⱮSɓ2ṗ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9@w4uGu9kcb1wWfnGz0cOf0/4eXO@hrRv7/H22oYxCrAyQNgaQRmG0EZRsBSWMw2xjKNgaSpmC2mY4JkLQEsw0h2gyNdUxBlImOBYgy0zGPBQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><span class=""math-container"">\$k\$</span> on the left, <span class=""math-container"">\$n\$</span> on the right.</p> | |
<pre><code> Ɱ For each | |
ɓ2ṗ sequence of n 1s and 2s, | |
ẇ does it contain as a sublist | |
1x k 1s? | |
S Sum. | |
</code></pre> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>ŒP¡</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FkuPTgo4tHBJcVJy8fJDi45OerhzBkRiwUJjCAMA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>Using <a href=""https://codegolf.meta.stackexchange.com/q/2447"">standard I/O rules</a>; takes input from STDIN</p> | |
<p>Explanation:</p> | |
<pre><code> ¡ repeatedly apply | |
ŒP the power set | |
to nothing | |
which defaults to 0 | |
which is turned into the range [1..0] | |
which is [] | |
</code></pre> | |
<hr /> | |
<p>If you insist on the <code>{{},{{}}}</code> formatting:</p> | |
<h2><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h2> | |
<pre><code>ŒP¡ŒṘ“[{]}”y</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FluPTgo4tPDopIc7ZzxqmBNdHVv7qGFu5ZLipORiqIoFC40hDAA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>This could probably be shorter, but I'm not too interested in golfing boring formatting code.</p> | |
<p>Explanation:</p> | |
<pre><code>ŒP¡ŒṘ“[{]}”y | |
¡ repeatedly apply | |
ŒP the power set | |
ŒṘ convert to string representation | |
y translate | |
“[{]}” square brackets to curly braces | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>xŒPḊVQṢḣ | |
</code></pre> | |
<p>A dyadic Link that accepts the list of positive integers on the left and the number of elements to get, <code>N</code>, on the right and yields a list of the first <code>N</code> concatenated integers.</p> | |
<p><strong><a href=""https://tio.run/##AScA2P9qZWxsef//eMWSUOG4ilZR4bmi4bij////WzEsIDIzLCAxMDFd/zU"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> - extremely inefficient!</p> | |
<h3>How?</h3> | |
<pre><code>xŒPḊVQṢḣ - Link: list of positive integers, L; positive integer, N | |
x - repeat the elements of L N times each | |
ŒP - powerset | |
Ḋ - dequeue (remove the empty list) | |
V - evaluate as Jelly code (concatenates each and gives back the integer) | |
Q - deduplicate | |
Ṣ - sort | |
ḣ - head -> the first N elements | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ḟ”iṢƝ“E“¬(’ḥⱮḂẸ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters from <code>aeiouOU</code> and yields <code>0</code> if valid and <code>1</code> otherwise.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjvmPGuZmPty56NjcRw1zXIH40BqNRw0zH@5Y@mjjuoc7mh7u2vH/4e4th9sfNa35/z8TArjyM7n8M7lKM7lCM7lSM7kSgQx/oGB@KVAslSsfRPiHZiZylYZy5fsDVSQCJSFiqQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Beats my other one, but I kind of prefer that one :)</p> | |
<pre><code>ḟ”iṢƝ“E“¬(’ḥⱮḂẸ - Link: list of characters, S | |
”i - an 'i' character | |
ḟ - S filter-discard 'i's | |
Ɲ - for each neighbouring pair: | |
Ṣ - sort | |
Ɱ - for each sorted pair of neighbours: | |
ḥ - hash using [salt, domain]: | |
“E“¬(’ - list of base 250 integers [70, 2041] | |
Ḃ - modulo two | |
Ẹ - any? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ḟ”iOµPƝ+⁽D§ẒẸ^+4ẒEƊ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields <code>1</code> if valid and <code>0</code> otherwise.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjvmPGuZm@h/aGnBsrvajxr0uh5Y/3DXp4a4dcdomQIbrsa7///@HZmb6Z2YmZmYCGQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hjvmPGuZm@h/aGnBsrvajxr0uh5Y/3DXp4a4dcdomQIbrsa7/D3dvOdz@qGnN//@ZEMCVn8nln8lVmskVmsmVmsmVCGT4AwXzS4FiqVz5IMI/NDORqzSUK98fqCIRKAkRSwUA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>Removes the <code>i</code>s and then takes the exclusive-or of these two checks using the remaining character's ordinal values:</p> | |
<ol> | |
<li>(<code>PƝ+⁽D§ẒẸ</code>) whether any neighbouring pair are from the same <strong>[ATR]</strong>, both <strong>[-high]</strong>, but with different <strong>[round]</strong> values. That is <code>oe</code>, <code>eo</code>, <code>Oa</code>, or <code>aO</code>.</li> | |
<li>(<code>+4ẒE</code>) whether all are from the same <strong>[ATR]</strong></li> | |
</ol> | |
<p> | |
<pre><code>ḟ”iOµPƝ+⁽D§ẒẸ^+4ẒEƊ - Link: list of characters, S (from 'aeoiuOU') | |
”i - an 'i' character | |
ḟ - S filter-discard 'i's | |
O - ordinal values | |
µ - start a new monadic chain, call that V | |
Ɲ - for neighbours in V: | |
P - product | |
⁽D§ - 18226 | |
+ - add (vectorises) | |
Ẓ - is prime? -> 1 if the neighbours are oe, eo, Oa, or aO | |
else 0 | |
Ẹ - any? -> X1 | |
Ɗ - last three links as a monad - f(V): | |
4 - four | |
+ - V add 4 (vectorises) | |
Ẓ - is prime? | |
E - all equal? -> X2 | |
^ - X1 XOR X2 | |
</code></pre> | |
<p>That is:</p> | |
<ol> | |
<li>Identifying those neighbours with the same <strong>[ATR]</strong> where both are <strong>[-high]</strong> but with different <strong>[round]</strong> values makes use of this table of ordinal products plus <span class=""math-container"">\$18226\$</span> with primes in bold:</li> | |
</ol> | |
<div class=""s-table-container""> | |
<table class=""s-table""> | |
<thead> | |
<tr> | |
<th style=""text-align: center;"">x×y+18226</th> | |
<th style=""text-align: center;"">u</th> | |
<th style=""text-align: center;"">e</th> | |
<th style=""text-align: center;"">o</th> | |
<th style=""text-align: center;"">U</th> | |
<th style=""text-align: center;"">a</th> | |
<th style=""text-align: center;"">O</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td style=""text-align: center;""><strong>u</strong></td> | |
<td style=""text-align: center;"">31915</td> | |
<td style=""text-align: center;"">30043</td> | |
<td style=""text-align: center;"">31213</td> | |
<td style=""text-align: center;"">28171</td> | |
<td style=""text-align: center;"">29575</td> | |
<td style=""text-align: center;"">27469</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;""><strong>e</strong></td> | |
<td style=""text-align: center;"">30043</td> | |
<td style=""text-align: center;"">28427</td> | |
<td style=""text-align: center;""><strong>29437</strong></td> | |
<td style=""text-align: center;"">26811</td> | |
<td style=""text-align: center;"">28023</td> | |
<td style=""text-align: center;"">26205</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;""><strong>o</strong></td> | |
<td style=""text-align: center;"">31213</td> | |
<td style=""text-align: center;""><strong>29437</strong></td> | |
<td style=""text-align: center;"">30547</td> | |
<td style=""text-align: center;"">27661</td> | |
<td style=""text-align: center;"">28993</td> | |
<td style=""text-align: center;"">26995</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;""><strong>U</strong></td> | |
<td style=""text-align: center;"">28171</td> | |
<td style=""text-align: center;"">26811</td> | |
<td style=""text-align: center;"">27661</td> | |
<td style=""text-align: center;"">25451</td> | |
<td style=""text-align: center;"">26471</td> | |
<td style=""text-align: center;"">24941</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;""><strong>a</strong></td> | |
<td style=""text-align: center;"">29575</td> | |
<td style=""text-align: center;"">28023</td> | |
<td style=""text-align: center;"">28993</td> | |
<td style=""text-align: center;"">26471</td> | |
<td style=""text-align: center;"">27635</td> | |
<td style=""text-align: center;""><strong>25889</strong></td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;""><strong>O</strong></td> | |
<td style=""text-align: center;"">27469</td> | |
<td style=""text-align: center;"">26205</td> | |
<td style=""text-align: center;"">26995</td> | |
<td style=""text-align: center;"">24941</td> | |
<td style=""text-align: center;""><strong>25889</strong></td> | |
<td style=""text-align: center;"">24467</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
<ol start=""2""> | |
<li><strong>[ATR]</strong> groups identified by whether four more than the ordinal is a prime:</li> | |
</ol> | |
<div class=""s-table-container""> | |
<table class=""s-table""> | |
<thead> | |
<tr> | |
<th style=""text-align: center;""></th> | |
<th style=""text-align: center;"">ordinal+4</th> | |
<th style=""text-align: center;"">prime?</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td style=""text-align: center;"">u</td> | |
<td style=""text-align: center;"">121</td> | |
<td style=""text-align: center;"">no</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">e</td> | |
<td style=""text-align: center;"">105</td> | |
<td style=""text-align: center;"">no</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">o</td> | |
<td style=""text-align: center;"">115</td> | |
<td style=""text-align: center;"">no</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">U</td> | |
<td style=""text-align: center;"">89</td> | |
<td style=""text-align: center;"">yes</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">a</td> | |
<td style=""text-align: center;"">101</td> | |
<td style=""text-align: center;"">yes</td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;"">O</td> | |
<td style=""text-align: center;"">83</td> | |
<td style=""text-align: center;"">yes</td> | |
</tr> | |
</tbody> | |
</table> | |
</div>" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒP+⁼ƭ3\Ạ$ƇṪLạL | |
</code></pre> | |
<p>A monadic Link that accepts the list of integers and yields the count of elements to remove.</p> | |
<p><strong><a href=""https://tio.run/##ATQAy/9qZWxsef//xZJQK@KBvMatM1zhuqAkxofhuapM4bqhTP///1sxLCAzLCA2LCAxMiwgMjRd"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///opADtR417jq01jnm4a4HKsfaHO1f5PNy10Of/4fZHTWv@/4@ONtRRMIrl0ok21VEw0VGwhPKAtLmOgi5Q0kxHAShlpKNgCOQYAnlG5iAFIGwBIkCiYHljsEILINcYIY5PCmwEWBhmkDHYOkOgDiOTWK5YAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ŒP+⁼ƭ3\Ạ$ƇṪLạL - Link: list of integers, A | |
ŒP - powerset of A -> all subsequences (Note: shortest to longest) | |
Ƈ - filter keep those for which: | |
$ - last two links as a monad: | |
3\ - three-wise overlapping reduction by: | |
ƭ - alternate between these two links: | |
+ - add -> first plus second element of the three-slice | |
⁼ - equals -> does that result equal the third element? | |
Ạ - all truthy? | |
Ṫ - tail -> (one of) the longest one(s) | |
L - length | |
L - length of A | |
ạ - absolute difference | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>’Œ!ðÄ%f⁸L | |
</code></pre> | |
<p>A monadic Link that accepts an integer and yields the count of permutations summing to permutations.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw8yjkxQPbzjcopr2qHGHz////y0A"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>’Œ!ðÄ%f⁸L - Link: integer, N | |
’ - decrement -> N-1 | |
Œ! - all permutations of [1..N-1] | |
ð - start a new dyadic chain, f(permutations, N) | |
Ä - cumulative sums (of each of the permutations) | |
% - modulo N | |
f⁸ - filter keep if in (the permutations) | |
L - length | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 25 </s> 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Saved three bytes using the allowance of excess whitespace (this also fixed a bug that meant an input with only left and/or right movements would have printed incorrectly since no space or newline characters were being introduced in such cases).</sup></p> | |
<pre><code>ı2½*Nx2ŻÆiNṠ+\+L$ŒṬo⁶Y | |
</code></pre> | |
<p>A full program that accepts the list of instructions and prints the result using <code>1</code> as the character.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///IRqNDe7X8KoyO7j7clun3cOcC7RhtH5Wjkx7uXJP/qHFb5P///6MNdRRMdRSMdRTMwQxDMMM4FgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Jelly has no canvas drawing built-ins, so instead this builds a matrix of zeros and ones, with ones at visited locations and prints it with spaces in place of zeros joined with newline characters.</p> | |
<pre><code>ı2½*Nx2ŻÆiNṠ+\+L$ŒṬo⁶Y - Main Link: list of integers from [0,7]: | |
ı2 - 2i (twice the square root of -1) | |
½ - square root | |
N - negate the input (vectorises) | |
* - exponentiate (vectorises) | |
x2 - repeat each element twice | |
Ż - prefix with a zero | |
Æi - convert each to [real, imaginary] parts | |
N - negate (vectorises) | |
Ṡ - sign (vectorises) | |
\ - cumulative reduce by: | |
+ - addition (vectorises) | |
$ - last two links as a monad: | |
L - length | |
+ - add (vectorises) | |
ŒṬ - matrix with 1s at the indicated [row, column]s | |
o⁶ - logical OR with space character | |
Y - join with newline characters | |
- implicit, smashing print | |
</code></pre> | |
<p>Note: <code>ı2</code> is a hack - <code>ı</code> should work but there are floating-point errors - for example, <code>ı½*-2</code> gives <code>2.220446049250313e-16-1j</code> rather than <code>0-1j</code>.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Rṡ"p/⁺€ɗⱮṚƬ}ẎŒPẎQƑ$ƇṪL | |
</code></pre> | |
<p>A dyadic Link that accepts the large rectangle dimensions, <code>[M, N]</code>, on the left and the small rectangle dimensions, <code>[A, B]</code>, on the right and yields the maximal count.</p> | |
<p><strong><a href=""https://tio.run/##AUIAvf9qZWxsef//UuG5oSJwL@KBuuKCrMmX4rGu4bmaxqx94bqOxZJQ4bqOUcaRJMaH4bmqTP///1s1LCA1Xf9bMiwgMl0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Too slow to complete on TIO for any other test case.</p> | |
<h3>How?</h3> | |
<p>Dumb brute-force...<br /> | |
Creates all possible sub-rectangles where each one is a list of the cell coordinates it covers in the <span class=""math-container"">\$M\$</span> by <span class=""math-container"">\$N\$</span> rectangle. Then filters the collection of every possible set of distinct sub-rectangles keeping only those with no overlap (repeated coordinate) and outputs the length of (one of) the longest one(s).</p> | |
<pre><code>Rṡ"p/⁺€ɗⱮṚƬ}ẎŒPẎQƑ$ƇṪL - Link: [M, N]; [A, B] | |
R - range -> [[1..M], [1..N]] | |
} - use right argument, [A, B], with: | |
Ƭ - collect up until no change applying: | |
Ṛ - reverse | |
-> [[A, B], [B, A]] ...or [[A, B]] if A==B | |
Ɱ - map - i.e. for [i,j] in those apply: | |
ɗ - last three links as a dyad - f([[1..M], [1..N]], [i,j]): | |
" - zip with - i.e. [f(l=[1..M], r=i), f(l=[1..N], r=j)]: | |
ṡ - all sublists of l of length r | |
/ - reduce by: | |
p - Cartesian product | |
€ - for each: | |
⁺ - repeat (reduce by Cartesian product) | |
Ẏ - tighten -> all possible A by B or B by A sub-rectangles | |
as 1-indexed coordinates | |
ŒP - powerset (Note: elements cardinality is non-decreasing) | |
Ƈ - filter keep those for which: | |
$ - last two links as a monad: | |
Ẏ - tighten | |
Ƒ - is invariant under?: | |
Q - deduplicate (i.e. we keep those with no overlap) | |
Ṫ - tail (the/one way to maximise small rectangles) | |
L - length | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>DẆṖ×\S$ƇḌḤ’BȦƲƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/l4a62hzunHZ4eE6xyrP3hjp6HO5Y8apjpdGLZsU3H2v8fbj866eHOGToOWY8a5ijo2ik8apirGfn/v6GBkbGBjoKhsZGJhY6CsbExiDAEEkYgDCQMDcyALAMgy8TMREfBzNTUGIwB"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<p>We use that fact that, if <span class=""math-container"">\$x = 2^n\$</span> for some <span class=""math-container"">\$n \in \mathbb N \cup \{0\}\$</span>, then the binary representation of <span class=""math-container"">\$2x-1\$</span> consists of all <span class=""math-container"">\$1\$</span>s. Note that the <span class=""math-container"">\$2x\$</span> is to handle <span class=""math-container"">\$x = 1\$</span>.</p> | |
<pre><code>DẆṖ×\S$ƇḌḤ’BȦƲƇ - Main link. Takes n on the left | |
D - Digits of n | |
Ẇ - All substrings | |
Ṗ - Remove n | |
$Ƈ - Keep those with no leading zeros: | |
×\ - Scan by product | |
S - Resultant sum is zero | |
Ḍ - Cast to digits | |
ƲƇ - Keep those that are a power of 2: | |
Ḥ - Unhalve; Double | |
’ - Decrement | |
B - Binary | |
Ȧ - All are non-zero? | |
</code></pre> | |
" | |
"25180","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code><;%ɗÞḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/GWvXk9MPzHu5Y9P///2gTHTMdCx1DAx1DIx0jg9j/pgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> ɗÞ Sort by... | |
< less than (return 0 if the set element is greater or equal to the range size) | |
; concatenated with | |
% modulus. | |
Ḣ Get the first element. | |
</code></pre> | |
<p>The same algorithm as <a href=""https://codegolf.stackexchange.com/a/248026/25180"">Jonah's answer in J</a>.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 46 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Œṗi@€o⁸Ṁ;ṢƊɗÞ:5×6Œ?Ɗ}Ḣị““&“la li“e & a”˹Ƈ€K€K | |
</code></pre> | |
<p>A full program that accepts the beats and the note-length and prints the result</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opIc7p2c6PGpak/@occfDnQ3WD3cuOtZ1cvrheVamh6ebHZ1kf6yr9uGORQ93dz9qmANEakCck6iQkwmkUxXUFBIfNcw9Mu3QzmPtQEO8Qfj///9Glv8NzQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Œṗi@€o⁸Ṁ;ṢƊɗÞ:5×6Œ?Ɗ}Ḣị“...”˹Ƈ€K€K - Main Link: beats, B; note-length L | |
Œṗ - all integer partitions of B | |
} - using L: | |
Ɗ - last three links as a monad - f(L): | |
e.g. 1,2,4,8,16 | |
:5 - integer divide by 5 -> 0,0,0,1,3 | |
×6 - multiply by six -> 0,0,0,6,18 | |
Œ? - shortest permutation of [1..N] which has that | |
lexicographic 1-based-index in a list of all | |
permutaions of [1..N] | |
-> [],[],[],[3,2,1],[3,4,2,1] | |
(our ordering) | |
Þ - sort (the partitions) by: | |
ɗ - last three links as a dyad - f(Partition, Ordering) | |
€ - for each (run-length, R) in the partition: | |
i@ - first 1-indexed index of R in Ordering or 0 | |
o⁸ - logical OR with the Partition (vectorises) | |
(replaces 0s with the larger, original Rs) | |
Ɗ - last three links as a monad - f(X): | |
Ṁ - maximum of X | |
Ṣ - sorted X | |
; - concatenate | |
Ḣ - head | |
“...” - ["", "&", "la li", "e & a"] | |
ị - index into | |
Ė - enumerate (i.e. [A, B, ...] -> [[1,A],[2,B],...]) | |
€ - for each: | |
¹Ƈ - keep truthy (i.e. drop the "" entries) | |
K€ - join each with spaces | |
K - join with spaces | |
- implicit print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>÷Ɱȷ2Ḃ2_«Ɗ§Ụ>Ƈ19Ḣ | |
</code></pre> | |
<p>A monadic Link that accepts a list of integers and yields an integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///w9kcb153YbvRwR5NR/KHVx7oOLX@4e4ndsXZDy4c7Fv3//z/a0MBAR8EYRJiDCENjE4NYAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>÷Ɱȷ2Ḃ2_«Ɗ§Ụ>Ƈ19Ḣ - Link: list of integers, A | |
ȷ2 - 10^2 = 100 | |
Ɱ - map across x in [1,100] with: | |
÷ - A divided by x (vectorises) | |
Ḃ - mod 2 (vectorises) | |
Ɗ - last three links as a monad - f(v=that): | |
2 - two | |
_ - subtract v (vectorises) | |
« - minimum with v (vectorises) | |
§ - sums | |
Ụ - grade-up (one-based indices sorted by the value at that index) | |
Ƈ - filter keep if: | |
> 19 - greater than 19 | |
Ḣ - head | |
</code></pre> | |
" | |
"36398","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>‘:Øp | |
</code></pre> | |
<p>Add 1 to the input and integer-divide by the golden ratio.</p> | |
<p><a href=""https://tio.run/##y0rNyan8//9RwwyrwzMK/v//b2wCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>⁴ɓObUḅỌ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9R45aTk/2TQh/uaH24u@f/w91bDm09OvnhzsWPGuYo2OjaKTxqmHu4/VHTmoc7Z6kcm6j5/39ScgpYQs3MjcvI2ATMVjZ25ipOLkotB/PMzdTDyrlSUpNK08F8tzC18DIuJ1dXNzBXJSQkhcs83MwszNwcLFBcmpycWlzMpaSsoqqmDjTT1MzcydnF1c09KDgkNCwcaGNqWnpRcUlpGcQCJSOnoKQioKXBycUqJi4hKSWqpq6hqaVAJ4Wllambu4enlwMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Not a palindrome, but still sounds kind of goofy.</p> | |
<pre><code> O Character codes. | |
b Convert to base | |
⁴ɓ 16, | |
U reverse each, | |
⁴ɓ ḅ convert from base 16, | |
Ọ and convert from character codes. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>16</s> 12 bytes</h1> | |
<pre><code>œlØḄṭ⁸¹?“shm | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o5JzDMx7uaHm4c@2jxh2Hdto/aphTnJH7/1HD3Ic7px1awvVwx6bD7Y@a1nj//59Wmpdckpmfp1BcAtScWKSQWFJZkJmcmKNQXl6ekZGRWKKQCAcKOUVABZlFBTmJealAHfmlJQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-4 thanks to ovs remembering there's a strip builtin</em></p> | |
<pre><code>œlØḄ Strip all leading consonants. | |
ṭ “shm Prepend "shm" | |
¹? if there's anything left, otherwise | |
⁸ give the original word. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒP§ọTL | |
</code></pre> | |
<p>A dyadic Link that accepts <span class=""math-container"">\$n\$</span> on the left and <span class=""math-container"">\$k\$</span> on the right and yields the count of subset sums of <span class=""math-container"">\$[1,n]\$</span> divisible by <span class=""math-container"">\$k\$</span>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opIBDyx/u7g3x@f//v6Hpf2MA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ŒP§ọTL - Link: n, k | |
ŒP - powerset of [1,n] | |
§ - sums | |
ọ - how many times is each divisible by k? | |
T - truthy indices | |
L - length | |
</code></pre> | |
<hr /> | |
<p>Alternatively, using filter-keep: <code>ŒP§ọƇL</code></p> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ŒP§%ċ0 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIBDy1WPdBv8P7xc/1HTmv//o6ONdYxidaJNdUyBpKGxjgWQMgILmeuYg4RMdExAlKmOoQGQtgSrMwcrMDSESRmDKDOIemOISYY6ZiDKCKQtFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How?</h2> | |
<pre><code>ŒP§%ċ0 Full program: Dyadic link f(n, k): | |
ŒP Powerset of n, which is implicitly converted to range [1..n] | |
§ Sum of each | |
% Modulo each by k | |
ċ0 Count the number of zeros | |
</code></pre> | |
<p>Edit: Whoops, Jonathan Allan beat me by one minute.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>BUz0ZUFsLBLƊ}Ḅt0ị | |
</code></pre> | |
<p>A dyadic Link that accepts the code on the left and the alphabet on the right and yields the plain text.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/98ptMogKtSt2MfJ51hX7cMdLSUGD3d3////P9rQ3EBHwdxMR8HIVEfBwlJHwcxCR8ESyDc31FEwBdKW5kA5kKQZUKEpEBsZgjBI1ACo3BAkDFJjaGgKMcjUGEgDsaGxAUyNIVCLGVDaxASkIfa/kkJiUnJKalp6RmZWdk5uXn5BYVFxSWlZeUVllRIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>BUz0ZUFsLBLƊ}Ḅt0ị - Link: code (list of integers in [1,255]), alphabet (list) | |
B - convert code numbers to binary lists | |
U - reverse each | |
z0 - transpose with filler zero | |
Z - transpose | |
U - reverse each | |
F - flatten | |
Ɗ} - last three links as a monad - f(alphabet): | |
L - length of alphabet | |
B - to binary list | |
L - length | |
s - split flattened bits into slices of that length | |
Ḅ - convert these from binary | |
t0 - trim zeros | |
ị - index into the alphabet | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ø+pḤUƬ | |
</code></pre> | |
<p>A niladic Link that yields this pair of lists of pairs of integers:</p> | |
<pre><code>[[[1, 2], [1, -2], [-1, 2], [-1, -2]], [[2, 1], [-2, 1], [2, -1], [-2, -1]]] | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wDO2ChzuWhB5b8/8/AA"" rel=""nofollow noreferrer"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ø+pḤUƬ - Link: no arguments | |
Ø+ - literal [1,-1] - set as the left argument | |
Ḥ - double -> [2,-2] | |
p - ([1,-1]) Cartesian product ([2,-2]) -> [[1,2],[1,-2],[-1,2],[-1,-2]] | |
Ƭ - collect up inputs while distinct, applying: | |
U - reverse each | |
</code></pre> | |
<hr /> | |
<p>Original seven byter (not abusing the very lose IO):</p> | |
<pre><code>Ø+pḤ;U$ - Link: no arguments | |
Ø+ - literal [1,-1] - set as the left argument | |
Ḥ - double -> [2,-2] | |
p - ([1,-1]) Cartesian product ([2,-2]) -> [[1,2],[1,-2],[-1,2],[-1,-2]] | |
$ - last two links as a monad - f(X=that): | |
U - reverse each of (X) | |
; - (X) concatenate (that) | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wDO2ChzuWWIeq/P8PAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>9</s> 8 bytes</h1> | |
<pre><code>Ø+pר½UƬ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wDO2Cw9MPzzi0N/TYmv//AQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 by stretching the output format a bit</em></p> | |
<pre><code>Ø+p Cartesian product of [1, -1] with itself. | |
ר½ Multiply each pair with [1, 2], | |
UƬ and pair with the reversed pairs. | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ı*Ɱ4×2ıṠƬ | |
</code></pre> | |
<p><a href=""https://tio.run/##ARoA5f9qZWxsef//xLEq4rGuNMOXMsSx4bmgxqz//w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/247680/85334"">Jonah's J solution</a>.</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>“ç©Ḅ’b5_2ṡ2 | |
</code></pre> | |
<p><a href=""https://tio.run/##AR4A4f9qZWxsef//4oCcw6fCqeG4hOKAmWI1XzLhuaEy//8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/247681/85334"">loopy walt's Python solution</a>.</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>“œƇØj_’ṃ“21- | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw5yjk4@1H56RFf@oYebDnc1AASND3f//AQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A fully hardcoded, no separator solution for comparison.</p> | |
" | |
"92689","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, <s>4</s> 3 bytes</h1> | |
<pre><code>ÆḞ⁺</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FisOtz3cMe9R464lxUnJxVDBJdGGBrFQNgA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<pre><code>ÆḞ⁺ | |
⁺ # Twice: | |
ÆḞ # Nth fibonacci | |
</code></pre> | |
<p><em>-1 byte thanks to Unrelated String</em></p> | |
<h1><a href=""https://github.com/Adriandmen/05AB1E"" rel=""nofollow noreferrer"">05AB1E</a>, 4 bytes</h1> | |
<pre><code>ÅfÅf | |
</code></pre> | |
<p><a href=""https://tio.run/##yy9OTMpM/f//cGsaEP3/b2gAAA"" rel=""nofollow noreferrer"" title=""05AB1E – Try It Online"">Try it online!</a></p> | |
<pre><code>ÅfÅf | |
Åf # Nth fibonacci | |
Åf # Nth fibonacci | |
</code></pre> | |
<h1><a href=""https://github.com/PyGamer0/flax"" rel=""nofollow noreferrer"">flax</a>, 4 bytes</h1> | |
<pre><code>;f;f | |
</code></pre> | |
<pre><code>;f;f | |
;f # Nth fibonacci | |
;f # Nth fibonacci | |
</code></pre> | |
<p><a href=""https://staging.ato.pxeger.com/run?1=m70kLSexYsGCpaUlaboWS6zTrNOWFCclF8MEog0NYqFsAA"" rel=""nofollow noreferrer"">Try it online!</a></p> | |
<h1><a href=""https://github.com/Mego/Seriously"" rel=""nofollow noreferrer"">Actually</a>, 2 bytes</h1> | |
<pre><code>FF | |
</code></pre> | |
<p><a href=""https://tio.run/##S0wuKU3Myan8/9/N7f9/QwMA"" rel=""nofollow noreferrer"" title=""Actually – Try It Online"">Try it online!</a></p> | |
<pre><code>FF | |
F # Nth fibonacci | |
F # Nth fibonacci | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>WẎƬṖḟFẈṀƲ€ | |
</code></pre> | |
<p>A monadic Link that accepts a ragged list of integers and yields a list of non-negative integers giving the depth-wise dimensions as required.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/84a6@Y2se7pz2cMd8t4e7Oh7ubDi26VHTmv@H249Oerhzxv//0dGGOgpGOgqWQBSroxAdDSSMYmMB"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>WẎƬṖḟFẈṀƲ€ - Link: ragged list of integers, L | |
W - wrap L in a list | |
Ƭ - (starting with that) collect up inputs while distinct applying: | |
Ẏ - tighten (drop first level of the inner lists) | |
Ṗ - pop (remove the final input) | |
€ - for each: | |
Ʋ - last four links as a monad: | |
F - flatten (to a list of integers) | |
ḟ - filter these out (only filters out integers at depth 1) | |
Ẉ - length of each | |
Ṁ - maximum | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>ŒgµŒlṁ3fØcȯaẆḢ) | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opPRDW49Oynm4s9E47fCM5BPrEx/uanu4Y5Hm/4e7txxuf9S0JvL//5CMVIW0/AqFysTyvGI9PT0FLtey1KLKkozMvHSFzGKF9Pz8FEUQAEqk5lXqKOSmQqhMMJmfyuXo6Bjk7sEVngoFGVCaK5ErEYjyuVxduVJJA7kgQykAoUAHAQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Œgµ ) For each run of consecutive equal elements: | |
Œl Lowercase it, | |
ṁ3 mold it to length 3, | |
fØc remove non-vowels, | |
ȯ and substitute the original run if that left it empty. | |
aẆḢ Fix the capitalization: | |
a vectorizing logical AND with | |
Ẇ each sublist of the run, individually | |
a because of something to do with how vectorization handles depth? | |
Ḣ and take the head of the resulting list. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŒJ’§-*ḋF | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///oJK9HDTMPLdfVerij2@3/4XbNyP//ow1jdaJ1QYShjhGQNNIx0DEB83RBXKA0mATLmehYgHm6QElDsFojMD8abAiEDdILVAURhxlpgqzZREfXBGynDsQMoD0w1SAxHagEnA2yC2orQkAHRTXEibh1xwIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ŒJ Enumerate the multidimensional indices of every element, in flat order. | |
’ Decrement each dimension (indexed from 1) of each index. | |
§ Sum each index, | |
-* and raise -1 to the power of each sum. | |
ḋF Take the dot product of that with the flattened input. | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>10</s> 9 bytes</h1> | |
<pre><code>߀ŒḊ¡U_@/ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///w/EdNa45Oerij69DC0HgH/f@H2zUj//@PNozVidYFEYY6RkDSSMdAxwTM0wVxgdJgEixnomMB5ukCJQ3Bao3A/GiwIRA2SC9QFUQcZqQJsmYTHV0TsJ06EDOA9sBUg8R0oBJwNsguqK0IAR0U1RAn4tYdCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>߀ Recur on each element of the argument | |
¡ as many times as | |
ŒḊ its depth. | |
U Reverse the list of results (or do nothing to the scalar argument) | |
_@/ and left-reduce by reversed subtraction. | |
</code></pre> | |
<p>Previous solution was <code>߀NÐeSµ)Ƒ¡</code>. Gaze upon it and despair.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŒP§œ-Q$Q | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIBDy49O1g1UCfx/uP3opIc7Z2hG/v8fbRiroxBtoqNgqqNgBGJa6igYGgCxIRCDBYx0FIzB0mYgniGQYWimo2AOpHQUTMBCOkY6xjomOqaxAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>ŒP§œ-Q$Q - Main link. Takes S on the left | |
ŒP - Powerset of S | |
§ - Sum of each | |
$ - To the list of sums: | |
Q - Deduplicate | |
œ- - Set difference | |
Q - Deduplicate | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>T%QL< | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z9ENdDH5n/eo4a5hoeXn5yu/6hpTeT//9FKBgaGhgaGINIQRCrpKBjH6ihEK0EEgVwjMBfEAwGQiDlEBASAPDMozxCMgAImsQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>Look ma, no Unicode!</em></p> | |
<p>Takes a list of 0 for lilies and 1 for water on the left, and the stride on the right.</p> | |
<pre><code> L The number of | |
Q unique | |
T indices of water | |
% modulo the stride | |
< is less than the stride. | |
</code></pre> | |
<p>The frog must traverse every index with some chosen residue modulo the stride; this checks if there's any residue which does not at any point correspond to water.</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>s׃R}Ẹ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/48PRjk4JqH@7a8d/2UcNcw8PLT07Xf9S0JvL//2glAwNDQwNDEGkIIpV0FIxjdRSilSCCQK4RmAvigQBIxBwiAgJAnhmUZwhGQAGTWAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes a list of 1 for lilies and 0 for water on the left, and the stride on the right. (Without having to handle strides longer than the pond itself, could just be <code>sPẸ</code>.)</p> | |
<pre><code>s Split the pond into stride-sized slices. | |
ƒ Reduce the list of slices by | |
× vectorizing multiplication | |
R} starting with [1..stride] (all-truthy and the appropriate length). | |
Ẹ Is any value truthy? | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>’⁵rŒḂƇÆEg/’ƊƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw8xHjVuLjk56uKPpWPvhNtd0faDQsa5j7f///zc0NTAwAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 byte thanks to Jonathan Allan!</p> | |
<p>In order for some <span class=""math-container"">\$k = p_1^{e_1}p_2^{e_2}\cdots p_i^{e_i}\$</span> to be a perfect power (for primes <span class=""math-container"">\$p_1, p_2, \dots\$</span>), we must have that <span class=""math-container"">\$\gcd(e_1, e_2, \dots, e_i) > 1\$</span>.</p> | |
<h2>How it works</h2> | |
<pre><code>’⁵rŒḂƇÆEg/’ƊƇ - Main link. Takes n on the left | |
’ - Decrement | |
⁵r - Range from 10 to n-1 | |
Ƈ - Keep those that are: | |
ŒḂ - Palindromic | |
ƊƇ - Keep those that are non-zero after: | |
ÆE - Prime exponents | |
g/ - Reduce by GCD | |
’ - Decremented | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>45</s> 38 bytes</h1> | |
<pre><code>ḷⱮjⱮƤ““ “-”ẎʋƤṖe@€i1ḣ@ȯ | |
ŒṖÇƑÐḟẈṢṚƲÞṪÇ€ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hju2PNq7LAuJjSx41zAEiBSDWfdQw9@GuvlPdx5Y83Dkt1eFR05pMw4c7FjucWM91dBJQ6HD7sYmHJzzcMf/hro6HOxc93Dnr2KbD8x7uXHW4Haj2/8PdWw5t1TncngUyT9dOAWTczhbNhztnAwX@/8/NLC4GoYKCTK5EGAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><s>Should be correct <a href=""https://tio.run/##y0rNyan8///hju2PNq7LAuJjSx41zAEiBSDWfdQw9@GuvlPdx5akOjxqWpNp@HDHYgeuo5Me7px2uP3YxMMTHu6Y/3BXx8Odix7unHVs0@F5D3euOtwOVPn/4e4th7bqHG7PAhmla6cAMmlni@bDnbOBAv//5ybmJhYAYQkIAgA"" rel=""nofollow noreferrer"">for real this time</a> thanks to Tanner Swett.</s></p> | |
<p>Should be correct <a href=""https://tio.run/##y0rNyan8///hju2PNq7LAuJjSx41zAEiBSDWfdQw9@GuvlPdx5Y83Dkt1eFR05pMw4c7FjucWM91dBJQ6HD7sYmHJzzcMf/hro6HOxc93Dnr2KbD8x7uXHW4Haj2/8PdWw5t1TncngUyT9dOAWTczhbNhztnAwX@/8/NLC4GoYKCTK5EGAAA"" rel=""nofollow noreferrer""><em>for real this time</em></a>.</p> | |
<p>It's <a href=""https://tio.run/##XYxNSsRAEIX3fYraCvbCC8hcpfJDumNMD0kGmd0gAxEEURcu/AWdlYiiKKbHncEg3qJykVgJkpnY1e@r19WPCv0omjYNFe/182PIqhb17JIvsGQ9u6Ll0c9htSB75o/q/Qe9RcXd6PtJfJ3yqMyrk/KYihtaHpC9JXtevZTXZO/LnLMNfbx@vm2Wedjuk9vQrrPzDbIXPGga5ON0EBHGAbQQrkL5J6G09LQc0IhskklWpjkcoTeFAAMUDsZc0jWuQeBB0kHsKQPjSQaZ8sExY9Bxb1NlzNCshz3dh1vr4VoTChMfdhKdqhhh8Pjfu88VEtzFNbdCHxGYdBVomWL8Cw"" rel=""nofollow noreferrer"">even less performant now</a>! Now designed from the ground up to handle spaces and hyphens, but there's got to be a shorter way to do <code>““ “-”</code>...</p> | |
<pre><code>ḷⱮjⱮƤ““ “-”ẎʋƤṖe@€i1ḣ@ȯ Monadic helper link: de-n-plicate an entire string | |
ʋƤ For each prefix of the argument: | |
Ɱ create a list of, for each element of the argument | |
Ṗ but one, | |
ḷ a copy of the prefix; | |
Ƥ for each prefix of that list, | |
j join the copies on | |
Ɱ ““ “-” each of the empty string, a space, and a hyphen; | |
Ẏ flatten the results. | |
e@€ Check if the argument is in each of those, | |
i1 get the first index of 1, | |
ḣ@ and return the argument truncated to that length | |
ȯ or unchanged if it's 1 long and got clobbered. | |
ŒṖÇƑÐḟẈṢṚƲÞṪÇ€ Main link | |
ŒṖ All ways to partition the input. | |
ƲÞ Sort them by | |
Ẉ the lengths | |
ṢṚ sorted descending of | |
Ðḟ the slices which are not | |
Ƒ unchanged by | |
Ç the helper link, | |
Ṫ take the last, | |
Ç€ and map the helper over its slices. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>2Æl2÷«ɓ÷l2Ḥ»0,+¥ | |
</code></pre> | |
<p>A monadic Link that accepts a positive number, <code>m</code> years, and yields a list of two numbers, <code>[wait, total]</code> in years.</p> | |
<p>Note: Input is strictly positive - inputting <code>0</code> will yield <code>[nan, nan]</code> which is <em>technically</em> true as one cannot do anything in zero time.</p> | |
<p><strong><a href=""https://tio.run/##ASYA2f9qZWxsef//MsOGbDLDt8KryZPDt2wy4bikwrswLCvCpf///zEwMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>2Æl2÷«ɓ÷l2Ḥ»0,+¥ - Link: number, M | |
2 - two | |
Æl - natural logarithm | |
2÷ - two divided by that | |
« - minimum with M | |
ɓ - start a new dyadic chain - f(M, CalculationTime=that) | |
÷ - M divided by CalculationTime | |
l2 - log-base-two | |
Ḥ - halved | |
»0 - maximum with zero | |
¥ - last two links as a dyad - f(WaitTime=that, CalculationTime) | |
+ - WaitTime add CalculationTime = TotalTime | |
, - WaitTime paired with that -> [WaitTime, TotalTime] | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>ṛ€j”+sLj”' | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hztmPmtZkPWqYq13sA6LU/z/cselwO1Aw8v//xKRkhZRUhZz8vHQgMyU1TaE4I7@oBAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/247001/85334"">DLosc's Pip solution.</a></p> | |
<pre><code> € For each element of the input, | |
ṛ the input. | |
j”+ Join the copies on +, | |
sL split into slices the length of the original input, | |
j”' and join those on '. | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>p”'$ṛ¦ⱮJj”+ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/gUcNcdZWHO2cfWvZo4zqvLCBX@//DHZsOtz9qWhP5/39iUrJCSqpCTn5eOpCZkpqmUJyRX1QCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>The implementation of <code>¦</code> is a bit questionable, so we can just abuse Cartesian product to make up for it.</p> | |
<pre><code>p”' Pair each element of the input with ', | |
$ṛ¦ and substitute elements of that into the input at | |
ⱮJ each index, individually. | |
j”+ Join the results on +. | |
</code></pre> | |
<p>Just for fun, without preserving the order within each term, <code>ṭ-Ƥ”'ż@j”+</code> is 10.</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>J‘œṖ€j€”'j”+”' | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJK4oCYxZPhuZbigqxq4oKs4oCdJ2rigJ0r4oCdJyIsIiIsIiIsWyJhYmMiXV0="" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>J‘œṖ€j€”'j”+”' Full Program | |
J [1, 2, ..., len] | |
‘ [2, 3, ..., len + 1] | |
œṖ€ For each of these, partition (*) | |
j€”' Join each partition on ' (**) | |
j”+ Join on + | |
”' An unparseable nilad forces the current string to be printed | |
(And then the ' is printed at the end) | |
(*) partition takes a list on the left but since we give it a single number, | |
it auto-wraps it so we just get all needed splits | |
(**) the last partition only has one sublist so join doesn't work properly here | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 21 bytes</h1> | |
<pre><code>JBUz0ZU⁸,yFŻ8¡s8z0ZḊḄ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJKQlV6MFpV4oG4LHlGxbs4wqFzOHowWuG4iuG4hCIsIiIsIiIsWyIgYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXoiLCJ0aGUgZm94Il1d"" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<pre><code>JBUz0ZU⁸,yFŻ8¡s8z0ZḊḄ Main Link | |
J Generate [1, 2, ...] as long as the encoding list | |
B Convert to binary | |
Uz0ZU Reverse, transpose padding with 0, transpose, reverse (*) | |
⁸, Pair the encoding list with the padded binary list | |
y Use this to translate the message into binary strings | |
F Flatten | |
Ż8¡ Prepend 0 8 times (in case the list is shorter than 8) | |
s8 Slice into blocks of 8 | |
z0Z Transpose padding with 0, transpose (**) | |
Ḋ Remove the block of 8 zeroes at the start | |
Ḅ Convert from binary into numbers | |
(*) this is a common pattern used to left-pad everything to the same length | |
(**) this is a common pattern used to right-pad everything to the same length - | |
because we prepended a block of 8 zeroes, there is at least one sublist | |
of length 8, so everything will be padded to length 8 | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>O%4µÞṪ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJPJTTCtcOe4bmqIiwiIiwiIixbIlRVIl1d"" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<pre><code>O%4µÞṪ Main Link | |
Þ Sort by | |
O ord (codepoint) | |
%4 modulo 4 | |
Ṫ Take the last character | |
</code></pre> | |
<p>-1 byte thanks to emanresu A by not closing the string<br /> | |
-3 bytes thanks to Kevin Cruijssen by sorting the original characters instead of indexing back into "FUT"</p> | |
<p>This at its core works the same as the original "map by <code>O%4</code> → take max → index back into <code>FUT</code>" but instead of actually indexing it just sorts by the <code>O%4</code> key which puts the max (the answer) at the end which is extracted with <code>Ṫ</code>.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>;”/;ⱮßW⁹?}ʋ/€Ẏ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists where each is a key-value pair where the key is a list of characters and the value is a, possibly empty, list of the same type* and yields a list of lists of characters - the paths.</p> | |
<p>* i.e. uses the option <em>a list or array of tuples, where each tuples contains the name/key and the value (which is itself a list of tuples)</em>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/6UcNcfetHG9cdnh/@qHGnfe2pbv1HTWse7ur7f7g98v//6GilxLzM3MQcJR0FIDs5sQTCCEgtKs5MzANxYmOBhJJTUWZJZnFGfHBGflFJRmJmEUQKIpmSnw7VVpqO0BKQWZJUmpMDUwgRLEvNyEzOSYVZVwRh@KYWJaempBYj2ecbjtAYCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>;”/;ⱮßW⁹?}ʋ/€Ẏ - (recursive) Link: list, J | |
€ - for each key-value pair in J: | |
/ - reduce by: | |
ʋ - last four links as a dyad - f(Key, Value) | |
”/ - '/' character | |
; - (Key) concatenate ('/') | |
} - use right argument, Value with: | |
? - if... | |
⁹ - ...condition: chain's right argument, Value | |
ß - ...then: call this recursive Link with that (non-empty) Value | |
W - ...else: wrap that (empty) Value in a list -> [[]] | |
Ɱ - map across the recursive call result (or the [[]]) with: | |
; - concatenate | |
Ẏ - tighten | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 4 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>BHḅ. | |
</code></pre> | |
<p>A monadic Link that accepts a non-negative integer and yields the element of the binary <a href=""https://en.wikipedia.org/wiki/Van_der_Corput_sequence"" rel=""noreferrer"" title=""Wikipedia"">Van der Corput sequence</a> at that 0-indexed index.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/J4@GOVr3///9bAgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Uses the definition given at Wikipedia's entry for a <a href=""https://en.wikipedia.org/wiki/Van_der_Corput_sequence"" rel=""noreferrer"" title=""Wikipedia"">Van der Corput sequence</a> using base two:</p> | |
<p><span class=""math-container"">$$\text{Corput}_2(n) = \sum_{k=0}^{\text{bitLength}(n)-1}{\text{bit}(n, k)\cdot 2^{-k-1}}$$</span> | |
<span class=""math-container"">$$\text{Corput}_2(n) = \sum_{k=0}^{\text{bitLength}(n)-1}{\frac{1}{2}\text{bit}(n, k)\cdot \frac{1}{2^k}}$$</span></p> | |
<pre><code>BHḅ. - Link: non-negative integer, I | |
B - binary digits of I | |
H - halve them all | |
. - a half | |
ḅ - convert (the list of zeros and halves) from base (one half) | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>×3‘$HḂ?’пḂṙ-Ḅ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wdONHDTNUPB7uaLJ/1DDz8IRD@4HMhztn6j7c0fLf@nC7pvv//4amAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>×3‘$HḂ?’пḂṙ-Ḅ - Main link. Takes n on the left | |
п - While loop, collecting each iteration i: | |
’ - Condition: i > 1 | |
? - Body: If: | |
Ḃ - Condition: Bit; i % 2 | |
$ - True: | |
×3 - 3i | |
‘ - 3i+1 | |
H - False: Halve | |
Ḃ - Bit of each i | |
ṙ- - Rotate the final 1 to the front | |
Ḅ - Convert from binary | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>-rṀṗL‘a*@ɗ⁸§‘ḟ$Ṃ;@ | |
⁸Ç¡ | |
</code></pre> | |
<p>A full program that accepts an integer, <code>n</code>, from STDIN and prints the Jelly representation of the first <code>n</code> terms so STDOUT.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1@36OHOhoc7p/s8apiRqOVwcvqjxh2HlgM5D3fMV3m4s8nagQsocrj90ML//00B"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (6 will time out on TIO.)</p> | |
<h3>How?</h3> | |
<pre><code>-rṀṗL‘a*@ɗ⁸§‘ḟ$Ṃ;@ - Link 1, getNext: list KnownTerms | |
Ṁ - maximum of KnownTerms (given an empty list yields 0) | |
- - -1 | |
r - inclusive range -> Exponents (-1 is an indicator to exclude the base) | |
L - length of KnownTerms | |
ṗ - Cartesian power -> all sets of exponents of size NumberOfTerms | |
ɗ⁸ - last three links as a dyad - f(Sets, KnownTerms) | |
‘ - increment all Exponents in the Sets | |
*@ - KnownTerms exponentiate Sets (vectorises) | |
a - logical AND (vectorises) (i.e. replace with 0 when the exponent was -1) | |
§ - sums | |
$ - last two links as a monad: | |
‘ - increment all the found values | |
ḟ - filter out the found values | |
Ṃ - minimum | |
;@ - concatenate to KnownTerms | |
⁸Ç¡ - Main Link: no arguments | |
⁸ - empty list | |
¡ - repeat... | |
- ...times: implicitly take an integer from STDIN | |
Ç - ...action: call Link 1 as a monad | |
- implicit print | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>24</s> 22 bytes</h1> | |
<pre><code>*þṀŻ$ZŒpŒP€Ẏ§‘ḟ$Ṃ; | |
⁸Ç¡ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATUAyv9qZWxsef//KsO@4bmAxbskWsWScMWSUOKCrOG6jsKn4oCY4bifJOG5gjsK4oG4w4fCof//NA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <span class=""math-container"">\$n\$</span> via STDIN and outputs the first <span class=""math-container"">\$n\$</span> terms in reverse order. <a href=""https://tio.run/##AToAxf9qZWxsef//KsO@4bmAxbskWsWScMWSUOKCrOG6jsKn4bmA4oCYUuG4n8ay4biiO0AKMcOHwqH///8z"" rel=""nofollow noreferrer"">+1 byte</a> if the output has to be in ascending order.</p> | |
<p>Incredibly slow, can handle up to <span class=""math-container"">\$n = 4\$</span> on TIO. If <span class=""math-container"">\$a_n\$</span> is our sequence so far, then, to generate <span class=""math-container"">\$a_{n+1}\$</span>, the code runs in approximately <span class=""math-container"">\$O((2a_n + 2)^n)\$</span> time.</p> | |
<p>-2 bytes thanks to <a href=""https://codegolf.stackexchange.com/questions/246671/sequence-of-integers-not-the-sum-of-powers-of-earlier-terms#comment552682_246684"">Jonathan Allan</a></p> | |
<h2>How it works</h2> | |
<pre><code>*þṀŻ$ZŒpŒP€Ẏ§‘ḟ$Ṃ; - Helper link. Given a list L of integers, returns the list with the next term prepended | |
$ - To L: | |
Ṁ - Maximum | |
Ż - [0, ..., max(L)] | |
þ - Over each pair (l, i), l ∈ L, i ∈ [0, ..., max(L)]: | |
* - Raise l to the ith power | |
Z - Transpose | |
Œp - Cartesian product of rows | |
ŒP€ - Powerset of each | |
Ẏ - Collapse into a list of lists | |
§ - Sums | |
$ - To our list of sums: | |
‘ - Increment | |
ḟ - Remove elements in the list of sums | |
Ṃ - Minimum | |
; - Prepend it to L | |
⁸Ç¡ - Main link. No arguments. | |
⁸ - Set the return value to [] | |
¡ - Read n from STDIN. Starting with [], do n times: | |
Ç - Call the helper link, updating the argument with the previous return value each time | |
</code></pre> | |
<hr /> | |
<p>Alternatively, a much faster version at <a href=""https://tio.run/##y0rNyan8///hzgaPQ7uNj@7m0jq873B7lM2x9kdNa4If7liiEghkHJ1UcHRSAJDxcFffoeVAxY8aZgQ93DH/2KaHOxZZcz1q3HG4/dDC//8tAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">36 bytes</a> that can do up to <span class=""math-container"">\$n = 8\$</span> on TIO.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>9</s> 8 bytes</h1> | |
<pre><code>ḣƬ5ŒV€ĊƑ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjsXH1pgenRT2qGnNka5jE/8/3L3l0Najkx/uXPyoYY6Crp3Co4a5D3csOtyuGfn/v6GCtoIREBuDJEqKSlO5jBS0gDxtBVO4iLGCPlgEocYEKAJSZ4SiywgoaoKmRl/BEC5iCjQDIgoTMQTzoCanJeYUgxQhGQ0RMoYKmSCEIJr0IY6ECJmAbddHUgUA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/246634/85334"">tsh's (old) JavaScript answer.</a></p> | |
<pre><code>ḣ 5 Take the first 5 characters | |
Ƭ repeatedly while unique. | |
ŒV€ Eval each result as Python. | |
ĊƑ Are they the same if ceiled? | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>Ḥẹ¦”/ŒV=ŒV | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjiUPd@08tOxRw1z9o5PCbIH4/8PdWw5tPTr54c7FjxrmKOjaKQAlH@5YdLhdM/L/f0MFbQUjIDYGSZQUlaZyGSloAXnaCqZwEWMFfbAIQo0JUASkzghFlxFQ1ARNjb6CIVzEFGgGRBQmYgjmQU1OS8wpBilCMhoiZAwVMkEIQTTpQxwJETIB266PpAoA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Have been trying to think of an <em>interesting</em> solution, but a Python eval builtin is a Python eval builtin. Was at least interesting to golf, starting from <code>”/=kj”/,¹ŒV€E</code>.</p> | |
<pre><code>Ḥ Double the characters of the input | |
¦ at indices | |
ẹ ”/ of slash. | |
ŒV Concatenate and eval as Python. | |
=ŒV Is it equal to the input evaluated as Python? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 26 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ærm2ÆṛJ}¹?×AṪ½Ɗ×þ`ŒdṙLƊṚ§⁼ | |
</code></pre> | |
<p>A monadic Link that accepts a non-empty list of coefficients ordered by degree* and yields <code>1</code> if the input represents the square of an integer polynomial, or <code>0</code> if not.</p> | |
<p>* i.e. the reverse order to the examples in the question, and <span class=""math-container"">\$0\$</span> being <code>[0]</code> rather than <code>[]</code></p> | |
<p><strong><a href=""https://tio.run/##AUoAtf9qZWxsef//w4ZybTLDhuG5m0p9wrk/w5dB4bmqwr3GisOXw75gxZJk4bmZTMaK4bmawqfigbz///9bMSwtMiwxLDQsLTQsMCw0XQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Same approach as loopy walt's <a href=""https://codegolf.stackexchange.com/a/246544/53748"">Python answer</a>:</p> | |
<ul> | |
<li>get the polynomial with every other root of the polynomial defined by the input</li> | |
<li>rescale using the square root of the coefficient of the highest degree in the input</li> | |
<li>get the coefficients of the square of that polynomial</li> | |
<li>check if that is equal to the input</li> | |
</ul> | |
<p>Just a little fiddly when the input defines a constant since we find no roots whereupon finding coefficients would error (this is why <code>J}¹?</code> is there).</p> | |
<pre><code>Ærm2ÆṛJ}¹?×AṪ½Ɗ×þ`ŒdṙLƊṚ§⁼ - Link: list of coefficients, C | |
Ær - get the roots of the polynomial P defined by C | |
m2 - modulo-2 slice | |
? - if... | |
¹ - ...condition: no-op (falsey if P is just a constant) | |
Æṛ - ...then: get polynomial coefficients | |
} - ...else: use the right argument (implicitly C) with: | |
J - range of length (in this case that's [1]) | |
(call this list NewCoefficients) | |
Ɗ - last three links as a monad - f(C): | |
A - absolute values | |
Ṫ - tail (absolute of coefficient of highest degree) | |
½ - square root | |
× - (NewCoefficients) multiplied by (that) | |
` - use as both arguments of: | |
þ - table of: | |
× - multiplication | |
Ɗ - last three links as a monad - f(X=that) | |
Œd - anti-diagonals of X (starts with main, sweeps South-East) | |
(has the effect of grouping product coefficients by degree) | |
L - length of X | |
ṙ - rotate (the anti-diagonals) left by (length of X) | |
(ensures that the groups are sorted by degree descending) | |
Ṛ - reverse | |
§ - sums (sum each group of like-degree product coefficients) | |
⁼ - equals C? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 71 bytes</h1> | |
<pre><code>Dœṗ`ḊĖF€ṚµḢỊ;ȦḄị“ðỌÇƭḌ€h»s2¤ṭḢị“÷mƬ@wƇ75Ẉ⁸f0¦mḃ⁾æÑdṛƁ/.ⱮṾ»s3¤Ɗ,Lß$K⁸¡)K | |
</code></pre> | |
<p>A full program that accepts a positive integer and prints the result</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/l6OSHO6cnPNzRdWSa26OmNQ93zjq09eGORQ93d1mfWPZwR8vD3d2PGuYc3vBwd8/h9mNrH@7oAarKOLS72OjQkoc714KVglVszz22xqH8WLu56cNdHY8ad6QZHFqW@3BH86PGfYeXHZ6Y8nDn7GON@nqPNq57uHMfUL/xoSXHunR8Ds9X8QaqPrRQ0/v///@mBgYGhkBkZGxiYAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##LYyxSgNBEEB/xiZhiLuby4YjjYWkufyABMFCRSSpLIKdZ4STS5oQiKCCKOGqRLQQdz1JsWsWf2P2R9bhsBgG3nsz5yeDwWUI@9s56rsjVPnPouuvV6jvzQeqFyzzzm@B6gbLib96tG9YTm3m1qimVJ2Z8kKYJep1lVbF59Ct9kYua7fw69an6pSZYohq7NONLezsGPWDS3cb/v0V9Ybum2bpcujZp52EavNcS8L222b0PaE5CKHPQUAbOAPOgQvgMQgGkQAZEyTKYogiBlJKclGLLFHBhCBcBWSrrl6X/6t5@Ac"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Dœṗ`ḊĖF€ṚµḢỊ;ȦḄị“...»s2¤ṭḢị“...»s3¤Ɗ,Lß$K⁸¡)K - Main Link: positive integer, N | |
D - decimal digits of N | |
` - use as both arguments of: | |
œṗ - partition before truthy indices | |
Ḋ - dequeue (remove leading empty list) | |
Ė - enumerate (e.g. [a,b,c]->[[1,a],[2,a],[3,c]]) | |
F€ - flatten each | |
Ṛ - reverse | |
µ ) - for each "Part": | |
Ḣ - head (i.e. the original index) - Note: this removes it too | |
Ị - is insignificant (i.e. are we dealing with the final d? = NOT B) | |
Ȧ - any and all? (0 if any zeros else 1 = NOT A) | |
; - concatenate -> [NOT B, NOT A] | |
Ḅ - from binary -> 2(NOT B)+(NOT A) | |
¤ - nilad followed by link(s) as a nilad: | |
“...» - "atehemom" | |
s2 - split into twos -> ["at","eh","em","om"] | |
ị - index into -> appropriate suffix | |
Ɗ - last three links as a monad - f( | |
Ḣ - head -> d - Note: again, this removes it too | |
¤ - nilad followed by link(s) as a nilad: | |
“...» - "QunPisTelKalPanSohSetQokNof" | |
s3 - split into threes -> ["Qun","Pis","Tel","Kal","Pan","Soh","Set","Qok","Nof"] | |
ị - index into -> appropriate prefix | |
ṭ - tack -> [prefix,suffix] | |
$ - last two links as a monad - f(Part): | |
L - length (number of trailing zeros, since we've removed the index and d) | |
ß - call this Link (the whole Main Link) | |
, - pair -> [current, recursed] | |
¡ - repeat... | |
⁸ - ...times: chain's left argument - treated as True if we have zeros | |
K - ...action: join with space characters | |
K - join with space characters | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 7 </s> 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Thanks to @ovs for suggesting looking at swapping the argument order and hence saving a byte!</p> | |
<pre><code>J+i@€ị | |
</code></pre> | |
<p>A dyadic Link that accepts the instruction on the left and the wrapping characters on the right and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/99LO9PhUdOah7u7////rx4VFeUSlZaarv5fPTEpOSU1LT0jMys7Jzcvv6CwqLiktKy8orLK0cnZxdXN3cPTy9vH188/IDAoOCQ0LDwiMkodAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>J+i@€ị - Link: instruction, I; wrapping characters W | |
J - range of length of I -> [1,2,3,...,length(I)] | |
€ - for each c in I: | |
@ - with swapped arguments - f(W, c): | |
i - first index of c in W | |
+ - add together -> [index(i1 in W)+1,index(i2 in W)+2,...] | |
ị - index into W (modular) | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ṬŒḄ¬Ƭ) | |
</code></pre> | |
<p><a href=""https://tio.run/##AR8A4P9qZWxsef//4bmsxZLhuITCrMasKf/Dh0vigqxZ//81"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Add another byte if the pairs can't be backwards.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>IṠŒɠ1;ÄrƝị | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/z4c4FRyedXGBofbil6Njch7u7/x9uPzrp4c4ZmpH//0dHG@oYxepwgSgdQwgDxDSGMHVBbF0gV0cXLGKgA4ImOoYGOpZmOqYmOsZAXYZgQQOQvK6pqY6umbmOroWBjikYWkKhoYmOkYGOkWlsLAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> Ṡ Take the signs of the | |
I differences between adjacent elements. | |
Œɠ Count the lengths of consecutive runs of equal signs, | |
1; prepend a 1, | |
Ä take the cumulative sums, | |
rƝ get the inclusive ranges between each pair of adjacent values, | |
ị and index each number in each range back into the input. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“Mḅṗʋ’D⁸ṃS | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer and yields the Roman numeral count as a positive integer.</p> | |
<p><strong><a href=""https://tio.run/##ASMA3P9qZWxsef//4oCcTeG4heG5l8qL4oCZROKBuOG5g1P///8xOA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>“Mḅṗʋ’D⁸ṃS - Link: positive integer, N | |
“Mḅṗʋ’ - base 250 integer = 1232123420 | |
D - to decimal -> X = [1,2,3,2,1,2,3,4,2,0] | |
⁸ - N | |
ṃ - base-decompress using X as the the new digits [1,...,9,0] | |
S - sum | |
</code></pre> | |
<hr /> | |
<p>Note that <code>“Mḅṗʋ’D</code> saves one byte over using the pattern of the lengths themselves with <code>3,4R;0j2</code><br /> | |
i.e. <code>[3,4] -> [[1,2,3],[1,2,3,4]] -> [[1,2,3],[1,2,3,4],0] -> [1,2,3,2,1,2,3,4,2,0]</code>.</p> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>D‘ị“ȤɱȯẎ’DU¤S</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FrtdHjXMeLi7-1HDnBNLTm48sf7hrr5HDTNdQg8tCV5SnJRcDFW3LFrJ2EIpFsoDAA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<pre><code>D digits | |
‘ add 1 to each (because Jelly uses 1-based indexing) | |
ị ¤ index into: | |
“ȤɱȯẎ’ compressed integer 2432123210 | |
D digits | |
U reversed | |
S sum | |
</code></pre> | |
" | |
"30164","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>ȯWṚUṭḢ;¥Ɱ¥@/ṚU | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///E@vCHO2eFPty59uGORdaHlj7auO7QUgd9kNj/w@1HJz3cOeP//@hoMx0LHUsdMx1TIG0UqxNtqGOuY6JjDGYbAWnD2FgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> (The TIO comes with a footer that prints the Python repr, to ensure empty arrays are visible; but the bare link works as a function.)</p> | |
<p>This is very likely to be suboptimal, since I do four (!) reversals of arrays, but I couldn't find a better solution with Jelly's functions. There could also be a shorter way to handle <code>[]</code> than <code>ȯW</code>, and I might be able to drop the <code>@</code>. However, it feels like this challenge <em>really</em> happened to hit some weak points in Jelly, as the core of the solutions is tiny.</p> | |
<ul> | |
<li>The first <code>Ṛ</code> (and the <code>@</code>) gives us a right-associative reduce. There's no single-byte right-associative reduce in Jelly.</li> | |
<li>The <code>@</code> also allows us to use <code>Ḣ</code>/<code>Ṫ</code> to pop stuff from the new J-bracket, since we can only apply monads to the left arg of dyadic chains.</li> | |
<li>The last <code>Ṛ</code> reverses the order of the output lines. Since things popped from the J-bracket's end go to the bottom, we have build the output backwards. Also, unfortunately, there's no <em>prepend to</em> like <code>ṭ</code>, so we have to append the "rest" of the J-bracket to the bottom of the matrix (<code>;</code> would require a <code>W</code>).</li> | |
<li>The <code>U</code>'s reverse each input and output line. <code>ȯWṚṭṪṭ¥Ɱ¥@/Ṛ</code> is <em>very</em> close to correct, but unfortunately gets the innermost J-bracket in the wrong order. I'd need to <code>U</code> or <code>W</code> it somehow to make the output correct.</li> | |
</ul> | |
<pre><code>ȯW ȯr Wrap (replace [] with [[]]) | |
Ṛ Ṛeverse order of J-brackets | |
U Upend (reverse) each J-bracket | |
/ reduce lines with: | |
@ (swap args: left=next J-bracket, right=matrix) | |
Ɱ Ɱap over lines of matrix: | |
Ḣ remove Ḣead (first) of J-bracket | |
; append that to matrix line | |
ṭ ṭack (append) remaining J-bracket to matrix | |
Ṛ Ṛeverse order of lines | |
U Upend (reverse) each line | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>60Ḷ12pד<¿‘Hạ/eʋƇذ_,Ɗ | |
</code></pre> | |
<p>A monadic Link that accepts a non-negative integer in <span class=""math-container"">\$[0,180]\$</span> and yields a list of pairs of <code>[hour, minute]</code> of a twelve-hour analogue clock.</p> | |
<p><strong><a href=""https://tio.run/##ATgAx/9qZWxsef//NjDhuLYxMnDDl@KAnDzCv@KAmEjhuqEvZcqLxofDmMKwXyzGiv/Dh8WS4bmY//80NA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/M4OGObYZGBYenP2qYY3No/6OGGR4Pdy3UTz3Vfaz98IxDG@J1jnX9P9x@dNLDnTN0HLKAqhR07RQeNczVjPz/P9pAx9JAx9DCQMfEVMfYQMcMyDECYlMdQ2Mg1jEx0jG31DE0s9AxBNGGprEA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>If we label straight up (12:00) as <span class=""math-container"">\$0\$</span> degrees, then at a given exact minute of <span class=""math-container"">\$h\$</span> hours and <span class=""math-container"">\$m\$</span> minutes, the minute hand is at <span class=""math-container"">\$\frac{360 m}{60}\$</span>, while the hour hand is at <span class=""math-container"">\$\frac{360 h}{12}+\frac{360m}{60 \times 12}\$</span> degrees. A clockwise angle between the hour hand and minute hand is, therefore:</p> | |
<p>$$A=\frac{360 h}{12}+\frac{360m}{60 \times 12}-\frac{360 m}{60}$$ | |
$$A=30h+\frac{m}{2}-6m$$ | |
$$A=30h-\frac{11m}{2}$$</p> | |
<p>The code makes all of the times as <code>[h, m]</code> pairs and filters them for when the absolute value of the above angle <span class=""math-container"">\$A\$</span> is either equal to the input or <span class=""math-container"">\$360\$</span> minus the input.</p> | |
<pre><code>60Ḷ12pד<¿‘Hạ/eʋƇذ_,Ɗ - Link: integer, A in [0,180] | |
60 - sixty | |
Ḷ - lowered range -> [0..59] | |
12 - twelve | |
p - Cartesian product -> Times = [[1,0],...,[1,59],...,[12,59]] | |
Ɗ - last three links as a monad - f(A): | |
ذ - 360 | |
_ - minus A | |
, - paired with A -> Angles=[360-A,A] | |
Ƈ - filter keep those Times for which: | |
ʋ - last four links as a dyad - f(Time,Angles): | |
“<¿‘ - code-page indices = [60,11] | |
× - Time times [60,11] -> [60h,11m] | |
H - halve -> [30h,11m/2] | |
/ - reduce by: | |
ạ - absolute difference -> abs(30h-11m/2) | |
e - exists in Angles? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ßȯŒḊ?"ḣL{ | |
ç⁹⁼ | |
</code></pre> | |
<p>A dyadic Link that accepts the pattern (with <code>0</code> as the wildcard) on the left and the potential match on the right and yields <code>1</code> for a match or <code>0</code> for no match.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///w/BPrj056uKPLXunhjsU@1VyHlz9q3Pmocc//w8v1HzWt@f8/Ojo6VkchOjaWSyc62gDENISwDXUUIFwgNtJRMI6FC4O4ICkTFGkQH2IIUMQEiE1jQcpAakCKgGqijcE8mFy0GRCbx4IAF9hkhDuiwQqNoRwTiDZkJwLNQ7gS7kDsrjUAKcbpWoiBpLo3FgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ßȯŒḊ?"ḣL{ - Helper Link: pattern P; potential A | |
" - P zip A applying: | |
? - if... | |
ŒḊ - ...condition: depth (of element of P) | |
ß - ...then: call this Helper Link (with element of P and element of A) | |
ȯ - ...else: (element of P) logical OR (element of A) | |
L{ - get length of P | |
ḣ - head (the zip result) to index (length of P) | |
ç⁹⁼ - Link: pattern P; potential A | |
ç⁹ - P Helper Link A | |
⁼ - equals A? | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>17</s> <s>15</s> 14 bytes</h1> | |
<pre><code>O’4ḍ-*Ä+ƲỤs2Ṣị | |
</code></pre> | |
<p><a href=""https://tio.run/##AUYAuf9qZWxsef//T@KAmTThuI0tKsOEK8ay4bukczLhuaLhu4v/4biyw4figqxL//8oKSAofXtdIChbe31dKSB7XShbKH1deyl9"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Function returning a list of pairs, or full program smash-printing with no separator. Uses Maltysen's mod 4 trick.</p> | |
<pre><code>O’ Decrement the codepoints of the input, | |
4ḍ and test divisibility by 4. | |
O’4ḍ That is, for each bracket, is it closing? | |
-* Raise -1 to the power of each, | |
Ä take cumulative sums, | |
+Ʋ and add the ones back in. | |
O’4ḍ-*Ä+Ʋ This gives the depth of each bracket. | |
Ụ Grade up: sort the indices by the obtained depths. | |
s2 Split the indices into adjacent pairs, | |
Ṣ sort the pairs lexicographically, | |
ị and index back into the original list. | |
</code></pre> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>ċⱮⱮṂ€</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FuuOdD_auA6IHu5setS0ZklxUnIxVOpmT7RSkKu3n2NMXohjhKdXTF6QY5CrX0yeY4ijq2dMXqRzpKOfko6CUnSMkqNnUAyQCWT4ebtCma6OIRAGSB2E5efp5-UIYYLMgrBAhkNZQY6REFYEnBUJtFEpVikW6igA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>Hmmm.</p> | |
" | |
"30164","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>11</s> 10 bytes</h1> | |
<p><em>-1 thanks to @Jonathan Allan.</em></p> | |
<pre><code>1,Æs×ṭʋE¥# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/99Q53Bb8eHpD3euPdXtemip8n@gkInBf2MA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h3>Explanation</h3> | |
<p>Jelly's <code>#</code> parsing is <em>really</em> confusing. <code>#</code> doesn't consume the first link <code>1</code>, since it's a nilad. (This, as it turns out, works really weirdly if you use chain separators; the equivalent code would be <code>ø1ð,,Æs$ÆḊ¬ð#</code>.)</p> | |
<p>The code is essentially parsed from postfix notation to the following, where <code>[]</code> represent chains:</p> | |
<pre><code>[1 #(filter=¥[ʋ[, Æs × ṭ] E])] | |
</code></pre> | |
<p>This chain is then applied to the arguments <code>(n, k)</code>. The value is first initialized to <code>n</code>.</p> | |
<p>The <code>#</code> operation is then used as a dyad, as if it's the <code>+</code> in <code>1+</code>. It receives <code>(1, n)</code> as arguments and starts passing those to its <code>filter</code> chain, incrementing the <code>1</code> until <code>k</code> matches are found. (Since <code>#</code> only consumed one link, the last command-line argument is used as the count.)</p> | |
<p>The filter chain then does this, where <code>x</code> is the candidate number:</p> | |
<ul> | |
<li><code>,</code>: make pair <code>[x, n]</code>.</li> | |
<li><code>Æs</code>: compute <code>[sigma(x), sigma(n)]</code>.</li> | |
<li><code>ṭ</code>: make pair <code>[n, x]</code>.</li> | |
<li><code>×</code>: elementwise multiply, i.e. <code>[sigma(x)*n, sigma(n)*x]</code>.</li> | |
<li><code>E</code>: see if the values equal. This is pretty clearly true iff <code>x/sigma(x)=n/sigma(n)</code>.</li> | |
</ul> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ḊÆfḢ$ÞẒÐḟ⁸0¦i | |
</code></pre> | |
<p>A monadic Link that accepts an integer, <code>n</code>, and yields an integer.</p> | |
<p><strong><a href=""https://tio.run/##AScA2P9qZWxsef//4biKw4Zm4biiJMOe4bqSw5DhuJ/igbgwwqZp////MTU"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ḊÆfḢ$ÞẒÐḟ⁸0¦i - Link: n | |
Ḋ - dequeue n -> [2,3,4,...,n] | |
Þ - sort by: | |
$ - last two links as a monad: | |
Æf - prime decomposition e.g. 63 -> [3,3,7] | |
Ḣ - head -> minimum prime factor ^ | |
Ðḟ - filter discard those for which: | |
Ẓ - is prime? | |
¦ - sparse application... | |
0 - ...to indices: zero (rightmost) | |
⁸ - ...apply: chain's left argument, n | |
...(this makes the rightmost entry, if there is one, become n) | |
i - first 1-indexed index of n (zero if n is not found) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4? 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>With a strict interpretation of Rule 1 (can't take as a program argument due to the "single line" part) - a full program that reads from STDIN and writes to STDOUT:</p> | |
<pre><code>ɠḲVµS÷4_ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///kgoc7NoUd2hp8eLtJ/P//5pYWCuaWJgoWhsYKFgZmCuYWlgA"" rel=""nofollow noreferrer"">Try it online!</a></p> | |
<p>...or with site default IO instead - a monadic Link that accepts a list of five numbers and yields a list of five numbers:</p> | |
<pre><code>S÷4_ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/48HaT@P///0ebW1roKJhbmugoWBgaAwkDMyDXwjIWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ɠḲVµS÷4_ - Main Link: no arguments | |
ɠ - read a line from STDIN | |
Ḳ - split that at spaces | |
V - evaluate that as Jelly code -> list of the five four-apple-weights, W | |
µ - start a new monadic chain - f(W) | |
S - sum W | |
4 - four | |
÷ - divide -> sum(W)/4 | |
_ - subtract W (vectorises) -> [sum(W)/4-w1, sum(W)/4-w2, sum(W)/4-w3, sum(W)/4-w4, sum(W)/4-w5] | |
- implicit print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>Œ!ạJ{Ṁ<ʋƇ | |
</code></pre> | |
<p>A dyadic Link that accepts the length, <code>n</code>, on the left and the minimum illegal distance, <code>k+1</code>, on the right and yields a list of all permutations as 1-indexed indices.</p> | |
<p><strong><a href=""https://tio.run/##AR0A4v9qZWxsef//xZIh4bqhSnvhuYA8yovGh////zX/Mw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Œ!ạJ{Ṁ<ʋƇ - Link: n; k+1 | |
Œ! - all permutations of [1..n] | |
Ƈ - filter keep those for which: | |
ʋ - last four links as a dyad - f(P, k+1): | |
{ - use k+1 with: | |
J - range of length -> I = [1..k+1] | |
ạ - P absolute difference I (vectorises) -> distances | |
Ṁ - maximum | |
< - is less than k+1? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<p>Uses <a href=""https://codegolf.stackexchange.com/a/245904/53748"">Jonah's method</a> of precalculating the Manhattan distance matrix and then filtering for equality with the step number.</p> | |
<pre><code>;ạ⁵SƲþ/‘=Ɱ | |
</code></pre> | |
<p>A full-program that accepts <code>[w, h] f [x, y]</code> and prints a list of frames which are each lists of lists of integers <code>1</code> (ripple) and <code>0</code> (calm). The coordinates, <code>w h x y</code> are all 1-indexed (top-left = <code>[1,1]</code>).</p> | |
<p><strong><a href=""https://tio.run/##ATsAxP9qZWxsef//O@G6oeKBtVPGssO@L@KAmD3isa7/w6dH4oKsauKBvsK2wrb//1s1LCA1Xf83/1syLCAzXQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (Footer formats the result for ease on the eyes.)</p> | |
<h3>How?</h3> | |
<pre><code>;ạ⁵SƲþ/‘=Ɱ - Main Link: [w, h]; f | |
/ - reduce [w, h] by: | |
þ - table between i in [1..w] and j in [1..h] of: | |
Ʋ - last four links as a monad - f(i, j): | |
; - concatenate -> [i, j] | |
⁵ - third program argument = [x, y] | |
ạ - absolute difference (vectorises) -> [abs(i-x), abs(j-y)] | |
S - sum -> Manhattan distance of [i, j] from [x, y] | |
‘ - increment (vectorises) | |
Ɱ - map across (implicit range) [1..f] with: | |
= - equals? (vectorises) | |
- implicit print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>+ⱮØ⁷%Ø⁷ỌfƑƇØẠ;⁶¤ | |
</code></pre> | |
<p>A monadic Link that accepts a list of code-points and yields a list of lists of characters.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1/70cZ1h2c8atyuCiYf7u5JOzbxWPvhGQ93LbB@1Ljt0JL/h9sj//@PNjQw1lEwNAITBjoKpoY6CpbmII4JkIAKmkNpCAHlG0MUW5iCODA1sQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>+ⱮØ⁷%Ø⁷ỌfƑƇØẠ;⁶¤ - Link: list of code-points C | |
Ø⁷ - 128 | |
Ɱ - map (across v in [1..128]) with: | |
+ - C add v (vectorises) | |
%Ø⁷ - modulo 128 | |
Ọ - convert to characters (list of potentials, P) | |
¤ - nilad followed by link(s) as a nilad: | |
ØẠ - alphabetic characters | |
⁶ - space character | |
; - concatenate (list of characters "A..Za..z ", A) | |
Ƈ - filter keep those p in P for which: | |
Ƒ - is invariant under: | |
f - p filter keep only those in A | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Œ¿’Æ!S | |
</code></pre> | |
<p>A monadic Link that accepts the shuffled list of <span class=""math-container"">\$[1,n]\$</span> and yields the swap count.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opEP7HzXMPNymGPz/cLvm///R0cY6RjqGsVw60YZAhrGOCYgJFEFmmugYQ5gmIHEQ0wSs1hDCRDdBx0zHVMdcxwIhZAYURBEyA6tDEjKDakUTAhkOF7LQQRGM5YoFAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Œ¿’Æ!S - Link: list of [1,n] in some order, L | |
Œ¿ - 1-indexed index of L in a sorted list of all permutations of L | |
’ - decrement -> same but 0-indexed | |
Æ! - convert to factorial number system (mixed-radix base using ..., 2!, 1!, 0!) | |
S - sum | |
</code></pre> | |
<hr /> | |
<p>I <em>think</em> that the method employed by ovs is also six, but perhaps there is a five or better out there. For example:</p> | |
<pre><code>Œc>/€S | |
</code></pre> | |
<p>or (counting swapping from the other end):</p> | |
<pre><code><";\FS | |
</code></pre> | |
<p>or</p> | |
<pre><code>>Ṫ$ƤFS | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ZL_Lṙ@ŒdŒḍ | |
</code></pre> | |
<p>A monadic Link that accepts a rectangular list of lists and yields its J-bracket-twin as a list of lists.</p> | |
<p><strong><a href=""https://tio.run/##pZGxUcQwEEVzV/EL@IF3JfvsjAKuAjQakiNhrgEqICK5CDrhYuYKuUrMX9kHM0TMkMjvW6vd/6Wnx@PxeVnu9w/76/n97nI6XE7Xj9fl80Xf89tSCoxwIhGZGIiR2BFT7VjMaE5LtEwbaCNNW3Pbmuk93ehOT3QVTLS@drXrSpmIqPRciSLQSXgKIVAnuIcQqDPcQgg0Cd6HEGgybA4R0ErWpRXM@jfVNuwW4Mcx8mYxGg7B8hqTxsYWYbBr7JFqTasY3/F@5fmjHcH/kle9x5omb11TmFsvJB5mQw@b9Qs"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##pZExbsMwDEV3n4JrgT@YlGxLWw@QC7SC0CVZglygJ@jUJVN7k2QucpCcxP2UkyboVKCL9b75TfLL281u9zrPz6uX1fn4@Xjar0/78@F9/nrjefx4eJpLEYUYJEAiZICMkAmSaoeiCjVogEboAB2hLOVWyrAepjCDBRgNCdrXrnZdKQniTosVUgj8Uiy4ILCTmLkgsLOYuiBwkljvgsDJotmFQ7Msj2bIfJdqG3YNcNtY4mVFbzg4c1efNDZWDyNTY/NUS1rG@In3K88f1yH8L3nl/yhWfYPCq0W4YQT7c07AiIkUSIZ8Z7iUUyteTYulfgM"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ZL_Lṙ@ŒdŒḍ - Link: list of lists, A | |
Z - transpose A | |
L - length of that -> columnCount(A) | |
L - length of A -> rowCount(A) | |
_ - columnCount(A) subtract rowCount(A) = N | |
Œd - anti-diagonals of A | |
ṙ@ - rotate this list of anti-diagonals left by N | |
Œḍ - create a matrix with these anti-diagonals | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>ßest Friends Forever?!</sup></p> | |
<pre><code>Ḣ;Ṫ€W;ßFF? | |
</code></pre> | |
<p>A monadic Link that accepts a rectangular list of lists and yields a list of lists.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjkXWD3euetS0Jtz68Hw3N/v/h9uPTnq4c8b//9HRhjpGOiY6FrE60ZY6xjpmOuZAljGQZaRjGRsLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hjkXWD3euetS0Jtz68Hw3N/v/h9uPTnq4c4Zm5P//0dHRRrGxXDrR0YY6RrE60cY6JnCujomOBVDIUsdYx0zHHCxpDBS1RFevE22qY4ZdUCfaHKw@FgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Ḣ;Ṫ€W;ßFF? - Link: list of lists, X | |
Ḣ - head -> top row of X (mutates X) | |
€ - for each of (the remaining rows of) X: | |
Ṫ - tail -> last element of the row (mutates X) | |
; - concatenate these together | |
W - wrap that list in a list -> Z | |
? - if... | |
F - ...condition: flatten (the mutated) X (falsey once empty or only empty rows) | |
ß - ...then: call this Link with (the mutated) X | |
F - ...else: flatten (the mutated) X -> an empty list | |
; - Z concatenate that | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ż+⁵fŻ}0ṚE?.ị | |
</code></pre> | |
<p>A full program that accepts <code>fz bz i</code> and prints the line as <code>[l, r]</code>.</p> | |
<p><strong><a href=""https://tio.run/##ASMA3P9qZWxsef//xbsr4oG1ZsW7fTDhuZpFPy7hu4v///8y/zT/MQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ż+⁵fŻ}0ṚE?.ị - Main Link: fz, bz | |
Ż - zero range fz -> [0,1,2,...,fz] (call this F) | |
⁵ - 3rd argument, i | |
+ - add -> [i,i+1,...,i+fz] | |
} - use right argument, bz: | |
Ż - zero range -> [0,1,2,...,bz] (call this B) | |
f - F filter keep if in B | |
? - if... | |
E - ...condition: all equal? (i.e. is that a single point) | |
0 - ...then: yield zero | |
Ṛ - ...else: reverse | |
. - 0.5 | |
ị - index into -> [last value, first value] (when given 0 this is [0,0]) | |
- implicit print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 26 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>¬Ø[iⱮT,ƝịJƑ¥ƇƊFƲ¦ÐLe€Ø[oḟ1 | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///QmsMzojMfbVwXonNs7sPd3V7HJh5aeqz9WJfbsU2Hlh2e4JP6qAmkJP/hjvmG////V4pNTIpOTklNi41Nz4jOzIrOzsmNzcuPjVVQSIyuiK6MrYpOjc2OVlCIjgYKRScmJSsBAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Finds any <code>"[...]"</code> where the middle has no <code>'['</code> or <code>']'</code> and replaces the <code>'['</code> and <code>']'</code> with zeros. Repeats that until no change happens. Checks each value in the result for existence in <code>"[]"</code>, giving a list of zeros and ones where the ones identify any <code>'['</code> or <code>']'</code> to remove. Logical ORs these with the input characters, to give a list of ones and characters, and then removes the ones.</p> | |
<pre><code>¬Ø[iⱮT,ƝịJƑ¥ƇƊFƲ¦ÐLe€Ø[oḟ1 - Link: list of characters | |
ÐL - loop while distinct applying: | |
¦ - sparse application... | |
¬ - ...of: logical NOT (i.e. replace with a zero) | |
Ʋ - ...to indices: last 4 links as a monad - f(Current): | |
Ø[ - "[]" | |
Ɱ - map across c in Current with: | |
i - first 1-indexed index of c in "[]" or 0 | |
e.g. "]ab[c]d[" -> [2,0,0,1,0,2,0,1] | |
Ɗ - last 3 links as a monad - f(X=that): | |
T - truthy indices [1,4,6,8] | |
Ɲ - for neighbours: | |
, - pair [[1,4],[4,6],[6,8]] | |
Ƈ - keep those for which: | |
¥ - last 2 links as a dyad - f(Neighbours, X) | |
ị - Neighbours index into X (vectorises) | |
Ƒ - is invariant under?: | |
J - range of length | |
(i.e. =[1,2]? hence outer indices of "[...]" | |
with no '[' or ']' in the middle) | |
F - flatten -> indices of some valid []s | |
Ø[ - "[]" | |
€ - for each value in the loop result: | |
e - exists in "[]"? | |
o - logical OR with the input (vectorises) | |
1 - one | |
ḟ - filter - discard ones | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 28 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>z0_ṚŻ€$Ṗ€Ɗ€1¦»0ZȦƇ€µƬẈ€ẠÞḢIṠ | |
</code></pre> | |
<p>A monadic Link that accepts a list of the teams as lists of animals each of which is a list of positive integers, <code>[attack, health]</code>, and yields <code>[-1]</code> if the first team wins, <code>[0]</code> if there is a draw, or <code>[1]</code> if the second team wins.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/7/KIP7hzllHdz9qWqPycOc0IHWsC0gYHlp2aLdB1Illx9qBvENbj615uKsDyHq4a8HheQ93LPJ8uHPB////o6M1DHUUjDV1FDSMdRQMobQRiDaC0mY6CqYg2lRHwVwzlksnGq7SEEEbIdMmIBNjuWIB"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>z0_ṚŻ€$Ṗ€Ɗ€1¦»0ZȦƇ€µƬẈ€ẠÞḢIṠ - Link: teams | |
µƬ - collect up input while distinct, repeatedly applying: | |
z0 - transpose the teams with filler 0 (pair up animals) | |
Ɗ€1¦ - apply to the first pair of animals: | |
$ - last two links as a monad: | |
Ṛ - reverse | |
Ż€ - prefix each with a zero | |
_ - animals subtract that (vectorises) | |
Ṗ€ - remove the last (third) value from each | |
»0 - max with zero (vectorises) | |
Z - transpose back to teams | |
ȦƇ€ - for each team keep those without zeros | |
Ẉ€ - length of each for each collected input | |
ẠÞ - sort by: all? | |
Ḣ - head | |
I - forward differences | |
Ṡ - sign (vectorises) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>żḢS€E?ƝẎ)Z$⁺Ạ€€ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of <code>1</code>s and <code>0</code>s and yields a list of lists of <code>1s</code> and <code>0</code>s.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///onoc7FgU/alrjan9s7sNdfZpRKo8adz3ctQAoBET/H@7e8nDHJiAr7HC7@///hgqGCgYQzAUiIWwDLigNIpHYEDUQngEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///onoc7FgU/alrjan9s7sNdfZpRKo8adz3ctQAoBET/H@7e8nDHJiAr7HC7O9fRyQ93Lj7cDuRmnZz@qHHfoW2Htv3/b6hgwGWgYMjFZQgk4AxDhIgBmKFgAMFcIBLCBuuD8ZDYEDUQngEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>The basic idea is to insert a value, <code>f(left,right)</code>, between each neighbouring pair, <code>[left,right]</code>, of each row then to transpose, and then to repeat the same thing again (insert values, transpose).</p> | |
<p>In order to handle the diagonal requirement, we must have an <code>f(left,right)</code> that maintains the necessary information between the steps. That is, when neighbours are not equal we need to remember which one was a one during the first pass and have those values work for us during the second pass.</p> | |
<p>The code below implements <code>f(left,right)</code> as "if <code>left</code> equals <code>right</code> then yield <code>left</code> else yield the sum of each of <code>[left,right]</code>" (<code>ḢS€E?</code>). This means that the first pass can yield <code>[1,0]</code> or <code>[0,1]</code> (to be treated as <code>0</code>s in the end) in addition to <code>0</code> and <code>1</code>, and the second pass can then yield <code>[1,1]</code> too (to be treated as a <code>1</code> in the end).</p> | |
<pre><code>żḢS€E?ƝẎ)Z$⁺Ạ€€ - Link: list of list of 1s and 0s, M | |
$⁺ - do this twice - f(Current=M): | |
) - for each Row in Current: | |
Ɲ - for neighbouring pairs of elements in Row: | |
? - if... | |
E - ...condition: equal? | |
Ḣ - ...then: head | |
first pass: [0,0]->0 | |
[1,1]->1 | |
second pass: [ 0 , 0 ]-> 0 | |
[ 1 , 1 ]-> 1 | |
[[1,0],[1,0]]->[1,0] | |
[[0,1],[0,1]]->[0,1] | |
S€ - ...else: sum each | |
first pass: [0,1]->[0,1] | |
[1,0]->[1,0] | |
second pass: [ 0 , 1 ]->[0,1] | |
[ 0 ,[0,1]]->[0,1] | |
[ 0 ,[1,0]]->[0,1] | |
[ 1 , 0 ]->[1,0] | |
[ 1 ,[0,1]]->[1,1] | |
[ 1 ,[1,0]]->[1,1] | |
[[0,1], 0 ]->[1,0] | |
[[0,1], 1 ]->[1,1] | |
[[0,1],[1,0]]->[1,1] | |
[[1,0], 0 ]->[1,0] | |
[[1,0], 1 ]->[1,1] | |
[[1,0],[0,1]]->[1,1] | |
ż - zip Curent and those together | |
Ẏ - tighten (flattens by one level, to counter the zip) | |
Z - transpose | |
Ạ€€ - all? for each element in each row | |
0->0 1->1 [0,1]->0 [1,0]->0 [1,1]->1 | |
</code></pre> | |
<hr /> | |
<p>Implementing <code>f(left,right)</code> as a hash function, with Jelly's <code>ḥ</code> built-in, I've only found a 16:</p> | |
<pre><code>ż⁽7&,14ḥ$ƝẎ)Z$⁺Ḃ | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>Ḥ’⁵*ƽ‘ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLhuKTigJnigbUqw4bCveKAmCIsIjEww4figqwiLCIiLFsiIl1d"" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<pre><code>Ḥ’⁵*ƽ‘ Main Link | |
Ḥ Double | |
’ Decrement | |
⁵* 10 ^ that (smallest number with 2n digits) | |
ƽ Floor square root | |
‘ Increment | |
</code></pre> | |
<p>Square root + ceiling is one byte shorter but has floating point issues at n = 17 so Jonathan Allan provided a fix for +1 byte that avoids this issue.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 8 </s> 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<p>-2 Thanks to <a href=""https://codegolf.stackexchange.com/users/85334/unrelated-string"">Unrelated String</a>!</p> | |
<pre><code>Bḅ4S+$ | |
</code></pre> | |
<p>A monadic Link that accepts a pair of non-negative integers and yields a pair of non-negative integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/p4Y5Wk2Btlf///5voWAIA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/p4Y5Wk2Btlf9H9xxuf9S05uikhztnAGkgygJRDXMUdO0UHjXMjfzPlZiUrKDg6OTswsVl4JjolOSc7KKg8D862lDHIFYHSBoBSSMdYyBpomMJEjHSMTQCy4DEzHUMDcGUcWwsAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Bḅ4S+$ - Link: integers A e.g. [4, 9] | |
B - convert A to binary [[1,0,0],[1,0,0,1]] | |
ḅ4 - convert from base 4 [16,65] | |
...i.e. insert zeros between the binary digits | |
[16,65] = [[1,0,0,0,0],[1,0,0,0,0,0,1]] | |
$ - last 2 links as a monad - f(x): | |
S - sum x 81 | |
+ - add x (vectorises) [97,146] | |
...i.e. the above S+$ is a rearrangement of | |
[(16+16)+65,(65+65)+16] | |
where 16+16 is the zero spaced bits of 4 | |
shifted one place to the left & similarly | |
for (65+65) with respect to 9. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 4 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>N1¦Ḅ | |
</code></pre> | |
<p>A monadic link that accepts a list of <code>1</code>s and <code>0</code>s and yields an integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/P8NCyhzta/v//H22oY6hjoGMYCwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/P8NCyhzta/h9uf9S05v//6GiDWJ1oQxDWAUIgbQClDXUMdAxgNFQGwooFAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>N1¦Ḅ - Link: list of 1s and 0s, A | |
¦ - sparse application to A... | |
1 - ...indices: 1 | |
N - ...action: negate | |
Ḅ - convert from binary (conversion from base functions allow non-base digits) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 12 11 </s> 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-3 thanks to @KevinCruijssen (take the wordsearch as a mulitline list of characters).</p> | |
<pre><code>=Ḣ¥ƝŻḋẇ€ | |
</code></pre> | |
<p>A dyadic Link that accepts the list of words on the left and the wordsearch (a multiline list of characters) on the right and yields a non-negative integer.</p> | |
<p><strong><a href=""https://tio.run/##FU45DsIwEOz3TxTrxHGOTTbBi5Dd0yA@QEtDwRtokBANJUVEOhD8I3zE2MWMRiPNsd3sdvsQFvN4eV2/5880j6f5efwd7mGeHu9bCAqJQKGA0riMRFGxgyw6Ga8hZwMGCUrs8kgCbZVpsCVrEO4jnAWPfaipUn3nB8Y6h0YV2HqbGhkYG0mhTAYDjihlc2SzAktlnPBKHJbQpgWLXFnCVF0VrndoagHtJd3SKOj/"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>=Ḣ¥ƝŻḋẇ€ - Link: words W (list of lists of characters); wordsearch P (list of characters) | |
Ɲ - for neighbouring words in W: | |
¥ - last two links as a dyad - f(left, right): | |
= - left equals right (vectorises) | |
Ḣ - head | |
Ż - prepend a zero | |
-> E = a list of 1s and 0s identifying whether the previous | |
word stated with the same letter. | |
€ - for each Word in W: | |
ẇ - is Word a sublist of P? | |
-> F = a list of 1s and 0s identifying whether the current | |
word is in the wordsearch | |
ḋ - E dot-product F | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 24 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Assuming that we must handle uppercase <code>S</code> and <code>H</code> too and that we must/may return the leftmost distinct "s-words"</sup></p> | |
<pre><code>ḣ2ŒliⱮ⁼Ø. | |
ḲQçƇ⁾hsḣJf7ḢƊ$ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields a list of the words.</p> | |
<p><strong><a href=""https://tio.run/##LUw9CsIwFN49xRucHVy8g07SE0R95UVjE/Kalo6dCo5Ozjq4CTp1EJdi79FeJKZY@H754NujUoX3XX2bf89K9s9HX76by2zS1a91c2@rvvwQh3kZL7r62p6mvqlW3rNB3MGoQEAMIoCAhSFpEZi0U2EjYYYiAoF57AnmsBUWNlofIMIME2B3BKNztBC7BCJnQmIRDiSnQ5Qq@5sqgFNh0x8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ḣ2ŒliⱮ⁼Ø. - Helper Link, valid word?: list of characters, Word; identifiers ("hs") | |
ḣ2 - head Word to index two - e.g. "Child" -> "Ch" | |
Œl - lower-case -> X -> X = "ch" | |
Ɱ - map across C in identifiers with: | |
i - first (1-indexed) index of C in X -> [2,0] | |
('h' at index 2, no 's' exists) | |
Ø. - [0,1] | |
⁼ - equal? | |
ḲQçƇ⁾hsḣJf7ḢƊ$ - Link get s-words: list of characters, T | |
Ḳ - split T at space characters -> Words | |
Q - deduplicate | |
⁾hs - set the right argument to "hs" | |
Ƈ - filter keep those Words for which: | |
ç - call the helper Link as a dyad - f(Word, "hs") | |
$ - last two links as a monad - f(ValidWords): | |
Ɗ - last three links as a monad - g(ValidWords): | |
J - range of length -> [1,2,...,number of valid words] | |
7 - seven | |
f - filter-keep -> [7] or [] if less than seven valid words | |
Ḣ - head -> 7 or 0 | |
ḣ - head of ValidWords to that index | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 4 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>;UŒṬ | |
</code></pre> | |
<p>A monadic Link that accepts a list of pairs of positive integers (the vertex list) and yields a list of lists of <code>1</code>s and <code>0</code>s (the adjacency matrix).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9869OikhzvX/P//PzraUMcoVifaSMcYSJrqmMXGAgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9869OikhzvX/D/c7m79qHG7jgOIOyNSM/L//@joaEMdo1idaGMdk9hYHQUQ1xjINQJyUQSNwIIgKVMdM4QgkqyJjimEC2bEAgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>;UŒṬ - Link: list of pairs of positive integers, V | |
U - reverse each pair in V | |
; - V concatenate that | |
ŒṬ - multi-dimensional array with 1s at those coordinates and 0s elsewhere | |
</code></pre> | |
" | |
"25180","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>bḅ²×¥@b× | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/p4Y7WQ5sOTz@01CHp8PT///8bGoAAkAIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><code>²×¥@</code> seems too long for what it does. I hope there is a shorter way.</p> | |
<h3>Explanation</h3> | |
<pre><code>b Convert A (the input number) to base B (the input base). | |
ḅ²×¥@ Convert from base A×B² | |
b× Convert to base A×B | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 33 </s> 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>;⁶ȧ®ṪOịʋ;ɼȧ$e?€“] } )” | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters (from <code>(){}[]</code>) and yields a list of characters (with one of <code>)}}</code> inserted/appended),</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/6UeO2E8sPrXu4c5X/w93dp7qtT@45sVwl1f5R05pHDXNiFWoVNB81zP3//79SdXR0rEa0hoamJpBVXRuroRlbC0RKAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Forms a string by keeping open <em>brackets</em> and closing the last, as yet unclosed, open <em>bracket</em> when a close <em>bracket</em> (or the end of the string) is encountered.</p> | |
<pre><code>;⁶ȧ®ṪOịʋ;ɼȧ$e?€“] } )” - Link: list of (){}[] characters, A: | |
;⁶ - concatenate a space | |
- will be identified as a closing bracket later | |
“] } )” - set the right argument to "] } )" | |
€ - for each in the augmented A: | |
? - if... | |
e - ...condition: exists in "] } )"? | |
ʋ - ...then: last four links as a dyad: | |
ȧ® - logical AND with the register | |
Ṫ - tail (last, as yet unclosed opening bracket) | |
O - ordinal | |
ị - index into "] } )" (1-indexed & modular) | |
- gives the matching closing bracket | |
$ - ...else: last two links as a monad: | |
ɼ - apply to register (initially 0) | |
; - concatenate | |
ȧ - logical AND (to get back the single bracket) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 12 </s> 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ṖȯfƑ⁵*Ɱ%Ɗµ# | |
</code></pre> | |
<p>A full program that accepts an integer, <code>n</code>, from STDIN and prints the Jelly representation* of a list of the first <code>n</code> numbers which have a <a href=""https://en.wikipedia.org/wiki/Primitive_root_modulo_n"" rel=""nofollow noreferrer"" title=""Wikipedia"">primitive root</a> of <span class=""math-container"">\$10\$</span>.</p> | |
<p><strong><a href=""https://tio.run/##ASAA3/9qZWxsef//4bmWyK9mxpHigbUq4rGuJcaKwrUj//82MA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p><sup>* the Jelly representation of a list with a single element is just that element.</sup></p> | |
<h3>How?</h3> | |
<pre><code>ṖȯfƑ⁵*Ɱ%Ɗµ# - Main Link: no arguments | |
µ# - implicitly takes input - call this N | |
µ# - collect the first N values of K (in [0,1,2,...]) for which: | |
Ṗ - pop -> [1,2,...,K-1] | |
ȯ - logical OR with K (so we get K when K is 0 or 1, rather than []) | |
(let's call this list of integers (or 0 or 1) P) | |
Ɗ - last three links as a monad - f(K): | |
⁵ - 10 | |
Ɱ - map across (implicit [1,2,...,K]) with: | |
* - exponentiation | |
% - modulo K (vectorises) | |
(let's call this list of integers M) | |
Ƒ - is P invariant under?: | |
f - P filter keep M | |
- implicit print | |
</code></pre> | |
<hr /> | |
<p>A couple of other 11 byters:</p> | |
<pre><code>⁵*Ɱ%i1=ṖṪµ# | |
⁵*Ɱ%=1Ḅ⁼2µ# | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>+Ø%X÷¤Ḟ | |
</code></pre> | |
<p>A monadic Link that accepts a number and yields an integer.</p> | |
<p>Note: given an integer there is a one in <span class=""math-container"">\$2^{32}\$</span> chance of outputting an integer one greater than the input, this is within the <span class=""math-container"">\$0.01\%\$</span> specified.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1/78AzViMPbDy15uGPe////dU31jEwB"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>+Ø%X÷¤Ḟ - Link: number, N | |
¤ - nilad followed by link(s) as a nilad: | |
Ø% - 4294967296 | |
X - random integer from [1..4294967296] | |
÷ - divide by 4294967296 | |
+ - N add that | |
Ḟ - floor | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ṙ1ßI¡€ | |
ÇƬ | |
</code></pre> | |
<p>A monadic Link that accepts a ragged list of numbers and yields the recursivesly rotated states in a list.</p> | |
<p><strong><a href=""https://tio.run/##AT4Awf9qZWxsef//4bmZMcOfScKh4oKsCsOHxqz/w4fFkuG5mP//WzEsMTAsWzIsMiw0XSw2LFtbNSw2XSw3XSwxXQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>Note that this still works if ragged lists and their sublists may be empty.</p> | |
<h3>How</h3> | |
<pre><code>ṙ1ßI¡€ - Helper Link, one recursive rotation: ragged list of numbers A | |
ṙ1 - rotate A left by one | |
€ - for each element: | |
¡ - repeat... (utilised as an if statement, as described below) | |
I - ...number of times: forward differences | |
given either a number or a list containing up to one | |
number and nothing else we get an empty list which | |
is falsey, so we don't do the "action" | |
given any other list get a non-empty list | |
which is truthy, so we do the "action" once | |
ß - ...action: call this Link (with the element) | |
ÇƬ - Main Link: ragged list of numbers, R | |
Ƭ - start with R and collect inputs up while distinct applying: | |
Ç - call the last Link (our helper) as a monad - f(current) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>‘ð;ׯ€⁸ḍn€/ị⁾# Y | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw4zDG6wPTz@6@1HTmkeNOx7u6M0DsvQf7u5@1LhPWSHy////xgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<pre><code>‘ð;ׯ€⁸ḍn€/ị⁾# Y - Main Link: integer, N | |
‘ - increment -> N+1 | |
ð - start a new dyadic chain - f(N+1, N) | |
× - multiply -> (N+1)×N | |
; - concatenate -> [N+1, (N+1)×N] | |
Ż€ - zero range each -> [[0..N+1], [0..(N+1)×N] | |
⁸ - chain's left argument -> N+1 | |
ḍ - divides? (vectorises) -> [[1,0,...,0,1], [1,0,...,0,1,0,...,0,1,0,...,1]] | |
/ - reduce by: | |
€ - for each: | |
n - not equal (vectorises) | |
ị⁾#. - index into "# " (vectorises) | |
Y - join with newline characters | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>O^1Ọ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of characters (from <code> </code> and <code>!</code>) and yields a list of lists of characters with these characters swapped.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/98/zvDh7p7/D3dvOdwe@f@/urp6DJeCoqKCAphQhAAIBwyQGFApuCiaBkydEAEU4zFNVUAzEc14rAxkNVxobiDOeEV0U7H6G2o8ya5XVFBEdzQ2h6EbjxmU6AxcYY/dCAUFYPQCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>O^1Ọ - Link: list of lists of characters | |
O - ordinal (vectorises) : ' ' -> 32 and '!' -> 33 | |
1 - one : 1 | |
^ - XOR (vectorises) : 32 -> 33 and 33 -> 32 | |
Ọ - character (vectorises) : 33 -> '!' and 32 -> ' ' | |
</code></pre> | |
<hr /> | |
<p>If integers are allowed in place of characters as I/O then the one byte Link <code>¬</code> would suffice (vectorising loginal NOT).</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Much of this post is in spoiler blocks, just in case anyone wants to try to find it for themselves since I mentioned it in the question.</p> | |
<blockquote class=""spoiler""> | |
<p><pre><code>ịⱮẆ²S</code></pre></p> | |
</blockquote> | |
<p><strong><a href=""https://tio.run/##AR4A4f9qZWxsef//4buL4rGu4bqGwrJT/8OH4oKs//8xMDA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<blockquote class=""spoiler""> | |
<p> Unrelated String got to the method <a href=""https://codegolf.stackexchange.com/a/243269/53748"">in their answer</a>, just not to the golfed code! | |
<pre><code>ịⱮẆ²S - Link: integer, N | |
Ẇ - all sublists of [1..N] | |
e.g. N=6 -> [[1],[2],[3],[4],[5],[6] | |
,[1,2],[2,3],[3,4],[4,5],[5,6] | |
,[1,2,3],[2,3,4],[3,4,5],[4,5,6] | |
,[1,2,3,4],[2,3,4,5],[3,4,5,6] | |
,[1,2,3,4,5],[2,3,4,5,6] | |
,[1,2,3,4,5,6] | |
] | |
i.e. for size in [1..N]: | |
for start in [1..N+1-len] | |
[start..start+size] | |
Ɱ - for each sublist: | |
ị - N index into sublist | |
- indexing in Jelly is 1-indexed and modular so... | |
e.g 6 ị [3,4,5,6] -> 4 | |
i.e N ị [start..start+size] | |
-> (N mod size)+start-1 if (N mod size) != 0 else start+size | |
e.g. 6 ịⱮ (6Ẇ) -> [1,2,3,4,5,6,2,3,4,5,6,3,4,5,6,2,3,4,1,2,6] | |
...if these were grouped in lengths of [N..1] they | |
are our tower level side lengths: | |
[[1,2,3,4,5,6] (height 6: [top..bottom]) | |
,[2,3,4,5,6] (height 5: [top..bottom]) | |
,[3,4,5,6] (height 4: [top..bottom]) | |
,[2,3,4] (height 3: [top..bottom]) | |
,[1,2] (height 2: [top..bottom]) | |
,[6] (height 1: [top..bottom]) | |
] | |
² - square (vectorises) | |
S - sum | |
</code></pre></p> | |
</blockquote> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 22 </s> 20 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>żSH$ƝẎ)ṭfƇ@ẎQʋ€ÐL`QL | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of pairs of integers - the full list of coordinates for each word - and yields the island count.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///onmAPlWNzH@7q03y4c23asXYHIDPwVPejpjWHJ/gkBPr8//8/OjraQMcgVifaUMcwFkhFG@kYASljHWMwzwAoCpIzgMoZg@WMYmNjAQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (Two islands each being two words crossing at cell corners, where equal-island words are non-adjacent in the input list.)</p> | |
<p>Or see the <a href=""https://tio.run/##zZE9TgMxEIV7zkGD5MK7Y4/tjpIiTUQZrUQDBcoFaGlSICEuwA3gACC6iBTcIlzE2F@c7HYgUcAWbz1/783P9eVyeZPz@9v52fHmcft6f7J9eb7arE7Lc/5x93n7tH6YXcxneb0q75wX5bPGDqZgB/ZD@S06rK5ZgtUXq/qk@Xp8xRqOzLc008Ifk9XyGraNxu7DnUnkVxTQgR5UMICxYKWIRvEpcSVXqVM4FD5FRlvvDp8/xJ0JRBLNRZoKdK6l88royPITxgBjZCep8VoilixLhaXawmTJUtg97A52Kew79aqSUEmoJFQSKqmpjHeoKKADPahgAGPjFaYSppLJVDLpQdqdxtuNp9pfVVqFo9ofNh7Qi2Ofu2P@n9P8dul/ssLhCw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p><em>Needs updating</em>:</p> | |
<pre><code>ṭfƇ@ẎṢQ - Link 1, add crossing words: Coordinates, (all) Word Coordinates | |
@ - with swapped arguments: | |
Ƈ - filter keep (those Word Coordinate lists) for which: | |
f - filter keep (i.e. contain some of the same entries) | |
ṭ - tack to Coordinates | |
Ẏ - tighten | |
Ṣ - sort | |
Q - deduplicate | |
żSH$ƝẎ)ç€ÐL`QL - Main Link: Word Coordinates | |
) - for each list in Word Coordinates: | |
$Ɲ - for neighbours: | |
S - sum (vectorises) | |
H - halve | |
ż - Word Coordinates zip-with those "intermediate coordinates" | |
Ẏ - tighten | |
` - use as both arguments of: | |
ÐL - loop until no change with: | |
ç€ - call Link 1 for each | |
Q - deduplicate | |
L - length | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>FṢṁ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/t4c5FD3c2/j/cfnTSw50zNCP//4/mio420VEwj9VRiDbVUTAGUiCmGRAbxQKBDle0EZANEjcEyUGEgNJAxdHRlkAeSC9XtCFIlQlQmakhSH@0EZBpAmRZggwyQugE8oHWGQGZsQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>FṢṁ - Main link. Takes a ragged list R on the left | |
F - Flatten R | |
Ṣ - Sort the flattened R | |
ṁ - Mold the sorted flattened R into the same shape as R | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Œ!IẠ$Ƈ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///oJEXPh7sWqBxr////f7ShjoGOoY5RLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Œ!IẠ$Ƈ - Link: list of numbers, A | |
Œ! - all permutations of A | |
Ƈ - filter keep those for which: | |
$ - last two links as a monad: | |
I - forward differences | |
Ạ - all non-zero? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 31 30 </s> 29 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>FµḢ“¤ı¶“Œ’ḥ;ṪV×12Ʋ;=”#Ḥ’ƊSµ$Þ | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of characters and yields a sorted version.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/t0NaHOxY9aphzaMmRjYe2ARlHJz1qmPlwx1LrhztXhR2ebmh0bJO17aOGucoPdywByhzrCj60VeXwvP8Pd2w63O79/7@rqYKLsqkCgnIyUXAxVXA2VXA0AQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>FµḢ“¤ı¶“Œ’ḥ;ṪV×12Ʋ;=”#Ḥ’ƊSµ$Þ - Link: notes | |
$Þ - sort by: last two links as a monad: | |
µ - monadic chain: | |
F - flatten (this is to get a copy so we don't | |
alter what we are sorting in place) | |
µ - monadic chain: | |
Ḣ - head of note (removes it too) | |
ḥ - hash with salt & domain: | |
“¤ı¶“Œ’ - base 250 numbers = [256628,20] | |
X = CDEFGAB -> 4,6,8,9,11,13,15 | |
Ʋ - last four links as a monad: | |
Ṫ - tail of note (removes it too) | |
V - evaluate as Jelly code -> integer | |
12 - twelve | |
× - multiply | |
Y = 12 × octave | |
; - concatenate -> [X,Y] | |
Ɗ - last three links as a monad - f(v): | |
(v being one of [], ['#'], or ['b']) | |
=”# - equals '#'? (vectorises) | |
Ḥ - double | |
’ - decrement | |
O = accidental offsets [], [1], or [-1] | |
; - concatenate -> [X,Y]+O | |
S - sum -> note number | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<p>Uses Kevin Cruijssen's method from their <a href=""https://codegolf.stackexchange.com/a/244065/53748"">05AB1E answer</a>.</p> | |
<pre><code>z⁶FḲḢ | |
</code></pre> | |
<p>A monadic Link that accepts a pair of lists, <code>[a, b]</code>, and yields a zipped list.</p> | |
<p><strong><a href=""https://tio.run/##ASkA1v9qZWxsef//euKBtkbhuLLhuKL/w4fFkuG5mP//W1s5LDgsN10sWzRdXQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/7/qUeM2t4c7Nj3csei/zuH2o5Me7pzxqGmNZhaQeNQwR0HXTuFRw9zI//@jo6NjdaJjY7l0wAxDHSMdYwgPwoTJAXlANrKUjomOKUiHoY6CoREQQ@UsdYAQKG6hA4SoJgE16JjpmAMFYwE"" rel=""nofollow noreferrer"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>z⁶FḲḢ - Link: pair of lists [a,b] | |
⁶ - space character | |
z - transpose [a,b] with space-filler | |
F - flatten | |
Ḳ - split at spaces | |
Ḣ - head | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>p`‘*/Þḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/78g4VHDDC39w/Me7lj8//9/QwMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of my Vyxal. -1 thanks to ovs.</p> | |
<pre><code>p` Cartesian product with (implicit) range from 1 to self | |
‘ Increment anything | |
Þ Sort by... | |
/ Reduce by... | |
* Exponentiation | |
ḣ Get first n. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>,<s>19</s> <s>18</s> 17 bytes</h1> | |
<pre><code>ɓŒgċ”^ịṭʋ€Ṛ}Fṭðƒḟ | |
</code></pre> | |
<p><a href=""https://tio.run/##RY2xSsRAEIb7fYrprjl8BUFBSGVjY7OyyU6SvUtmQ3bjkUJQG8F0d50gFrYKFhaGA5vTg/MtNi8SdwU5mGLm4/vnn2FRtOO4W30vs69uuH7kbt25/vWnG25fXP9wdeKPzdt26T6exuHmkzGvrlz/7Nbvm7vz7b3XZuMoGBOMx4zz/yVhHHgYT46FNSBqhLQhasHoEq0q0TDuA1OIGwvR5BLBYzBYK90YSELGan0Qfp5WipQmA5rAWGFVArb1LDtkkZ14PBetFyGyILFCkn@mzRFUWRVYIoWQpqlnusny4B6pDKRKU6yREoQY7QKRINNagiAJsZD7LsZDGzvLBc0N8Av@Cw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 thanks to Jonathan Allan</em></p> | |
<p><em>-1 thanks to Jonathan Allan again</em></p> | |
<p>Takes and returns lists of lines.</p> | |
<pre><code> ð ḟ Starting with the input without any of its elements, | |
ƒ reduce by: | |
ɓ with reversed arguments: (line on left, lines on right) | |
Œg Runs of consecutive equal elements. | |
ʋ€ For each run: | |
ṭ append the run to | |
} the accumulated lines | |
Ṛ reversed | |
ị and get the item at the 1-index of | |
ċ”^ the number of carets. | |
F Flatten the runs and substitutions back together, | |
ṭ and append to the list of accumulated lines. | |
</code></pre> | |
<p>Love when I shave two bytes off (from <code>ɓŒg=”^Sị⁸¹?ɗ€Ṛ}Fṭµƒ“”</code>) in the course of writing an explanation :P</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ẋɓL:L}‘ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hru6Tk32sfGofNcz4f3i5/tFJD3fO0Iz8/z862lDHSMc4Vkch2kjHJBZEI4sYY4gZWugYmemYGOtYmEFkQIpMwTI6YPU6pjpmOuYwXYZGEF1ABogNwkATAQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Nothing all too original.</p> | |
<pre><code>ẋ Repeat a by | |
ɓL the length of b | |
:L} floor divided by the length of a | |
‘ plus 1. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 30 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“\ɓ^‘ẋ“£×“Œ¥‘jṃ“|/.\^””_;Ɱz⁶ṚY | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw5yYk5PjHjXMeLirG8g5tPjwdCB1dNKhpUCxrIc7m4G8Gn29GKCSuUAUb/1o47qqR43bHu6cFfn//39DcwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>“\ɓ^‘ẋ“£×“Œ¥‘jṃ“|/.\^””_;Ɱz⁶ṚY - Main Link: integer, N | |
“\ɓ^‘ - Code-page indices = [92, 155, 94] | |
ẋ - repeat N times | |
“£×“Œ¥‘ - Code-page indices = [[2, 17], [19, 4]] | |
j - join -> [2, 17, 92, 155, 94, ..., 92, 155, 94, 19, 4] | |
“|/.\^” - list of characters = "|/.\^" | |
ṃ - convert to base 5 using "|/.\^" in place of the digits 12340 | |
Ɱ - map across these lists of characters with: | |
”_; - concatenate to an '_' character | |
z⁶ - transpose with space characters as filler | |
Ṛ - reverse | |
Y - join with newlines | |
- implicit print | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>9</s> 7 bytes</h1> | |
<pre><code>t"ƑÐƤi1 | |
</code></pre> | |
<p><a href=""https://tio.run/##VYy9DcIwFIRXQa5pGME/z3mOXxwrduQsQAFKScMWQMUASExAQUtE9mASg6ngq@47nW67Hsd9zjs2H6fDfNms8nRlj9vz9Lqfc2YCK9BD0tH03kRE8hBjlNRCaoEatlwwLqQCXaGpLRWHH4oPADqQCECqbrhyXFnlQ/CdA5EMOK/LCq1Flln63EMnoDMS47cHovYvKOhjkEjcqaJ1gb0B"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> ÐƤ For each suffix, | |
Ƒ is it the same after | |
t trimming off | |
" the corresponding letter of the word from each of its letters? | |
i1 Find the first index of 1. | |
</code></pre> | |
<h3>Wait, what?</h3> | |
<p>This beats the original, <code>W€ḟ"ƑÐƤi1</code>, by completely dropping the step of wrapping each letter into a singleton list. As for <em>how</em>:</p> | |
<p>A Jelly string is a list of characters, which is to say it's a Python list of length-1 Python strings. For example, <code>“this”</code> is really <code>["t","h","i","s"]</code>.</p> | |
<p>Most list builtins are built to handle lists whether that's what they got or not, by passing all arguments through <a href=""https://github.com/DennisMitchell/jellylanguage/blob/master/jelly/interpreter.py#L373"" rel=""nofollow noreferrer""><code>iterable</code></a>, and in the case of a single character this wraps it in a singleton list to obtain a length-1 Jelly string. <a href=""https://github.com/DennisMitchell/jellylanguage/blob/master/jelly/interpreter.py#L234"" rel=""nofollow noreferrer""><code>ḟ</code></a> does this, and as a result its output is also always a list--so <code>ḟ"</code>, mapped over corresponding pairs, gives a list of lists, and for it to ever not change a suffix of the ciphertext each of its characters has to be pre-wrapped to match.</p> | |
<p>However, <a href=""https://github.com/DennisMitchell/jellylanguage/blob/master/jelly/interpreter.py#L1772"" rel=""nofollow noreferrer""><code>t</code> <em>does not call <code>iterable</code> on its left argument</em></a>, so here <code>t"</code> operates on <em>the Python string characters themselves</em> of the ciphertext suffix, and either leaves them alone or trims them to <code>''</code>.</p> | |
<p>Finally, <code>Ƒ</code> performs a strict, non-vectorizing equality check, and <code>"</code> only maps its given link over pairs of corresponding elements up to the length of the shorter argument, placing the remainder of the longer argument into the result verbatim. If the ciphertext suffix is longer, the remainder automatically matches itself leaving only the prefix of length equal to the word to be considered, but if the word is longer, the result cannot be equal to the suffix because it is itself longer than the suffix.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ṗ@Ż€I% | |
</code></pre> | |
<p>A dyadic Link that accepts the length, <span class=""math-container"">\$k\$</span>, on the left and the number of symbols, <span class=""math-container"">\$N\$</span> on the right and yields a list of lists of non-negative integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hzukOR3c/alrjqfr//3/j/6YA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>This is the same cyclic Gray code that the algorithm displayed on <a href=""https://en.wikipedia.org/wiki/Gray_code#n-ary_Gray_code"" rel=""noreferrer"">Wikipedia</a> will produce (for values <span class=""math-container"">\$[1,N^k]+[0]\$</span>) with each result reversed.</p> | |
<pre><code>ṗ@Ż€I% - Link: k, N | |
@ - with swapped arguments: | |
ṗ - [1..N] Cartesian product [1..k] | |
Ż€ - prefix a zero to each | |
I - incremental differences | |
% - modulo N | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 35 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>z⁶Z)µẎ«”-$⁹R¤¦Fṁ”|LHĊƊ¦€ḟƑ¡"⁸Zj€⁾ | |
</code></pre> | |
<p>A dyadic Link that accepts the list of lists of words on the left and the number done on the right and yields a <a href=""https://codegolf.meta.stackexchange.com/a/17095/53748"">list of lines</a>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/7/qUeO2KM1DWx/u6ju0@lHDXF2VR407gw4tObTM7eHORqBAjY/Hka5jXYeWPWpa83DH/GMTDy1UetS4IyoLyH/UuE9B4f/h5ZH//0dHKzkq6Sg5OjkDSRdXN3cPTy8gy80dSHj7@PopxepEKwUGBYeEhoUDhaCsiMgoICc4BEhEgnAUWBlILAoElGJj/xsaAgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>z⁶Z)µẎ«”-$⁹R¤¦Fṁ”|LHĊƊ¦€ḟƑ¡"⁸Zj€⁾ - Link: W, N | |
) - for each list in W: | |
z⁶ - transpose with space filler | |
Z - transpose | |
µ - start a new monadic Link, call that X | |
Ẏ - tighten (to a list of padded words) | |
$⁹R¤¦ - apply to indices [1..N]: | |
”- - a '-' character | |
« - minimum (vectorises) -> '-' if not ' ' | |
F - flatten | |
ṁ - mould like X | |
"⁸ - zip with X applying: | |
ḟƑ¡ - if invariant under filter-discard: | |
Ɗ¦€ - for each apply to indices... | |
L - ...length | |
H - halved | |
Ċ - ceiling | |
”| - ...a '|' character | |
Z - transpose | |
j€⁾.. - join each with " " | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ŒHṪẇṖ | |
</code></pre> | |
<p>A monadic Link that accepts a list and yields <code>1</code> (≈rational) or <code>0</code> (≈irrational).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///oJI@HO1c93NX@cOe0////RxvqGOlY6JjrGAAhCexYAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///oJI@HO1c93NX@cOe0/zqH248tyXrUMEdB107hUcNczcj//6OVDI2M8SIlBQVlBRNDfWNjYy4dJWNDE0NTSyMzU2NTC0tzS2MjYwsTMyMzE2NjC2Mjc1MLsOqCTKBKI0tDM3wArNJc38gEqNbQwNDQAAgMocAAFRiC1SoBKW0FJQMQaaOQX5KRWuSSmZ5ZogHUrqSjUFCUWpaZX1ocnwIS1NQy0oKL5KTmpZdkKFhZ2QHtAlptgA@A7QJ6Vt/UwADkNCMLc6ALcJJg5UAH65ubm3PFAgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a> (results being the application to each prefix of each input).</p> | |
<h3>How?</h3> | |
<p>Identify a list, <code>L</code>, as rational if the last half is a sublist of <code>L</code> without its final element (i.e. appears anywhere earlier).</p> | |
<pre><code>ŒHṪẇṖ - Link: list, L | |
ŒH - split L into two halves (first half longer when odd in length) | |
Ṫ - tail -> X = last half of L | |
Ṗ - pop L -> Y = L without its final element | |
ẇ - is Y a sublist of X? | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>18</s> 17 bytes</h1> | |
<pre><code>o@= | |
çW;œ-\⁻Ɲʋç@+= | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/fwZbr8PJw66OTdWMeNe4@NvdU9@HlDtq2/x/u2ARkPGpaE/n/f7BzkGOAgoerj4@/gmuAv7OHgrNnmKePgpOrD5Ad5e/vG6zg4@Po66jg6hrk6arg4ejj6AMU8YmIAJE@Pv/BegE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 because there was a completely extraneous <code>ɗ</code></em></p> | |
<p>Target on left, guess on right; <code>0</code> for gray, <code>1</code> for yellow, <code>2</code> for green.</p> | |
<p>Absolutely dreadful... There ought to be some sort of <code>=þ</code>-based solution, but I've had no luck yet.</p> | |
<pre><code>o@= Dyadic helper link: mask out exact matches | |
= For each pair of corresponding elements, are they equal? | |
o@ Replace 0s with elements from the left argument, leaving 1s unchanged. | |
çW;œ-\⁻Ɲʋç@+= Main link | |
ç Mask matches out of the target, | |
ç@ mask matches out of the guess, | |
ʋ and with those on the left and right: | |
W; \ Scan across the guess, starting with the masked target, by | |
œ- multiset difference; | |
Ɲ for each pair of adjacent scan results, | |
⁻ are they not equal? | |
+= Add that to the mask of exact matches. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>xŻI$ | |
</code></pre> | |
<p>A monadic Link that accepts a strictly increasing list of positive integers and yields a non-strictly increasing list of positive integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/7/i6G5Plf9H9xxuf9S05uikhztnAGkgcv//PzraMJZLJ9oYRBjqKBjpKMCYxjoKJjoKliCeEZhnqqNgrqNgCFQfCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>If the input is <code>A=[a1, a2, a3, ...]</code> then the output needs to be <code>a1</code> <code>a1</code>s followed by <code>a2-a1</code> <code>a2</code>s then <code>a3-a2</code> <code>a2s</code> etc.</p> | |
<pre><code>xŻI$ - Link: strictly increasing list of positive integers, A | |
$ - last two links as a monad - f(A=[a1, a2, a3, ...]): | |
Ż - prepend a zero -> [0, a1, a2, a3, ...] | |
I - incremental differences -> [a1, a2-a1, a3-a2, ...] | |
x - times (vectorises) -> [a1, ..., a1, a2, ..., a2, a3, ...] | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>J_»0;1ż)M | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/98r/tBuA2vDo3s0ff8fbteM/P8/mis62iBWRyE6NlYHyASxDJGYOkY6QAwRADIhYlAFBmApoIgBSBVEzFgHbJgxgg/WYww1AcQ2gpsH5cEkdYxM0EUMUQUQ7gTbYgBhG6K5ywjmLiS3QzwCFYdxDFHlTJHlTHDLIclgF0U3ywxVzgxZzjw2lisWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Direct port of grc's Python solution. Monadic link taking a pair of its arguments and returning <code>[1]</code> for <code>1</code>, <code>[1, 2]</code> for <code>0</code>, and <code>[2]</code> for <code>-1</code>.</p> | |
<pre><code> ) For each element of the input: | |
_ Subtract each element from | |
J its 1-index, | |
»0 take the maximum of each of those and 0, | |
;1 append 1, | |
ż and zip those with the original elements. | |
M Return the list of maximal indices. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>x)o/ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/79CM1///@F2b83I//@jDWN1FKKNQYShjpEOlGGsY6JjCWICRXRMdcx1DA1jAQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Shamelessly sandbox sniped, <a href=""https://chat.stackexchange.com/transcript/240?m=60581858#60581858"">but I didn't start it :P</a></p> | |
<pre><code> ) For each element of the input, as a monadic chain: | |
x repeat it by itself. | |
o/ Reduce the resulting list of lists by logical OR. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ŒṗUQƑƇṂ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASYA2f9qZWxsef//xZLhuZdVUcaRxofhuYL/w4dLKVn//zQsOSwxMCwyMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>The only real difference from lyxal's Vyxal solution is that Jelly's integer partitions builtin generates them in nondecreasing order, requiring them to be reversed before finding the minimum.</p> | |
<pre><code>ŒṗU Nonincreasing integer partitions. | |
Ƈ Filter to those which | |
Ƒ are unchanged by | |
Q uniquification. | |
Ṃ Take the minimum. | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>_JQƑ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/eK/DYxP@H2x81rfn/P9pQx0jHOFZHIdpYB8iEMIx0DEEMMx0THXMdYx1TmACIawbhAvUAAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>_J -- difference between each element and its 1-based index | |
Ƒ -- is this list invariant under: | |
Q -- removing duplicates? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22*? 27 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ÆḞ€R¬W€1¦t⁶;ɗ€0¦Ṛz⁶ʋ/ZṚ$⁸¡Y | |
</code></pre> | |
<p>A full program that accepts an integer and prints a spiral using <code>1</code>s.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9w28Md8x41rQk6tCYcSBkeWlbyqHGb9cnpQI7BoWUPd86qAvJPdetHAZkqjxp3HFoY@f//fzMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ÆḞ€R¬W€1¦t⁶;ɗ€0¦Ṛz⁶ʋ/ZṚ$⁸¡Y - Main Link: integer, N | |
ÆḞ€ - first N Fibbonacci numbers | |
R - range -> [[1],[1],[1,2],[1,2,3],[1,2,3,4,5],...] | |
¬ - logical NOT -> [[0],[0],[0,0],[0,0,0],[0,0,0,0,0],...] | |
W€1¦ - wrap the first one | |
ʋ/ - reduce by - f(Current, Next): | |
ɗ€0¦ - apply to the final entry of Current: | |
t⁶; - trim spaces and concatenate Next | |
Ṛ - reverse | |
z⁶ - transpose with spaces | |
$⁸¡ - repeat N times: | |
Z - transpose | |
Ṛ - reverse | |
Y - join with newline characters | |
- implicit print | |
</code></pre> | |
<hr /> | |
<p>* Awaiting clarification on whether "output can be rotated so that the last segment is always in the same direction" - <a href=""https://tio.run/##y0rNyan8//9w28Md8x41rQk6tCYcSBkeWlbyqHGb9cnpQI7BoWUPd86qAvJPdetH/v//3wIA"" rel=""nofollow noreferrer"">22</a>:</p> | |
<pre><code>ÆḞ€R¬W€1¦t⁶;ɗ€0¦Ṛz⁶ʋ/Y | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>+2ÆḞ€DżṖ©;⁾+=Ɗ⁶ṁ$®¦F)Y | |
</code></pre> | |
<p>A full program that accepts an integer and prints the result.</p> | |
<p><strong><a href=""https://tio.run/##ATQAy/9qZWxsef//KzLDhuG4nuKCrETFvOG5lsKpO@KBvis9xorigbbhuYEkwq7CpkYpWf///zIw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>+2ÆḞ€DżṖ©;⁾+=Ɗ⁶ṁ$®¦F)Y - Main Link: integer, N | |
) - for each V in [1..N]: | |
+2 - V add two | |
ÆḞ€ - Fibbonacci of each of [1..V+2] | |
D - to decimal digits -> [[1],[1],[2],...,Digits(Fib(V+2))] | |
call this FibDigits | |
Ɗ - last three links as a monad - f(V): | |
Ṗ - pop -> [1..V-1] | |
© - (copy this to the register) | |
⁾+= - ['+', '='] | |
; - concatenate -> [1,2,3,...,V-1,'+','='] | |
call this Fillers | |
ż - FibDigits zip with Fillers | |
¦ - sparse application... | |
® - ...to indices: recall from register -> [1..V-1] | |
$ - ...action: last two links as a monad: | |
⁶ - space character | |
ṁ - mould like (e.g. [[1,4,4],12] -> [[' ',' ',' '], ' '] | |
F - flatten | |
Y - join with newlines | |
- implicit print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 7 </s> 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>2ȮX$’¿ | |
</code></pre> | |
<p>A niladic Link that prints <code>2</code>s as a side-effect (it also yields <code>1</code>). Only prints strictly positive numbers (as allowed in the specification).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/oxLoIlUcNMw/t/39oUdr//wA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (The footer suppresses the printing of <code>1</code> that a full program would otherwise do implicitly.)<br /> | |
Or <a href=""https://tio.run/##ASAA3/9qZWxsef//MsiuWCTigJnCv//CouG4nzHhuYQp//80MA"" rel=""nofollow noreferrer"">see forty at once</a> (plus a single trailing newline).</p> | |
<h3>How?</h3> | |
<pre><code>2ȮX$Ḋ¿ - Link: no arguments | |
2 - two - let's call this V | |
¿ - while... | |
’ - ...condition: decrement V (V=2 -> 1 (truthy); V=1 -> 0 (falsey)) | |
$ - ...do: last two links as a monad - f(V): | |
Ȯ - print V, yield V | |
X - random integer in [1,V] -> next V = 1 or 2 (probability = 0.5) | |
</code></pre> | |
<hr /> | |
<p>Previous @ 7 bytes:</p> | |
<pre><code>2XȮß$Ị¡ | |
</code></pre> | |
<p>A niladic Link that prints <code>1</code>s as a side-effect (it also yields <code>2</code>). This one includes the empty output (i.e. zero).</p> | |
<p><a href=""https://tio.run/##ARkA5v9qZWxsef//MljIrsOfJOG7isKh/8KiZv//"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> (The footer suppresses the printing of <code>2</code> that a full program would otherwise do implicitly.)</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 27 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“£f{ẋ’b5⁸ị+19>_@⁸_3%12+⁽#1Ọ | |
</code></pre> | |
<p>A dyadic Link accepting an integer, <code>month</code>, on the left and an integer, <code>day</code>, on the right that yields a character.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw5xDi9OqH@7qftQwM8n0UeOOh7u7tQ0t7eIdgOx4Y1VDI@1HjXuVDR/u7vn//7/xfyNDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see <a href=""https://tio.run/##y0rNyan8//9Rw5xDi9OqH@7qftQwM8n0UeOOh7u7tQ0t7eIdgOx4Y1VDI@1HjXuVDR/u7vl/ePmjxp3WDienP9q4Tt/a4eHOad6akf//R0cb6hgbxupEG@kYWQIpYwjPRMfYAEiZQnhmEJ45hGcBoSwhgoYGEK6hIZRvBOLHAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">a whole year</a>.</p> | |
<h3>How?</h3> | |
<pre><code>“£f{ẋ’b5⁸ị+19>_@⁸_3%12+⁽#1Ọ - Link: M; D | |
“£f{ẋ’ - 53343748 | |
b5 - to base five -> [1, 0, 2, 1, 2, 3, 4, 4, 4, 4, 4, 3] | |
⁸ị - get the item at 1-indexed index M | |
+19 - add nineteen to it | |
> - is that greater than D? -> 1 or 0 | |
_@⁸ - subtract from M -> M-1 or M | |
_3 - subtract three (offset since characters start at March) | |
%12 - modulo twelve | |
⁽#1 - 9800 | |
+ - add | |
Ọ - cast to character | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>+⁹\Ṗ;@ḣʋƑⱮJTḢ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1/7UePOmIc7p1k7PNyx@FT3sYmPNq7zCnm4Y9H///@jDXUUjHQUTHQUzHUULIBsEMcYyASKGJoBCWMjw1gA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/1/7UePOmIc7p1k7PNyx@FT3sYmPNq7zCnm4Y9H/w@2Pmtb8/x8dbRzLpRNtpKMAQiCmIYIJpI11FEx0FMyhElCejoIhkGNoARVFQ2ZQrUCVphCVRgZArWZAGZBOI6AhRkZAnomhGcI@iLEWICkgB6jEAihiaAYkjI0MEcqMYcaawdRbApUZxHLFAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>+⁹\Ṗ;@ḣʋƑⱮJTḢ - Link: list of integers, A | |
J - range of length of A -> [1,2,3,...,length(A)] | |
Ɱ - map (for L in [1,2,3,...,length(A)]) with: | |
Ƒ - is A invariant under?: | |
ʋ - last four links as a dyad - f(A, L) | |
⁹\ - L-wise overlapping cumulative reduce A with: | |
+ - addition | |
Ṗ - remove the final value | |
ḣ - head A to index L | |
;@ - concatenate -> first L terms of A then summed terms | |
T - truthy (1-indexed) indices | |
Ḣ - head | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 20 </s> 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup><s>I can't help but think that more of the manipulation could be put inside the reduction <code>ƒ</code></s> - done</sup></p> | |
<pre><code>xs€⁴Z¹ƭL¤ZÆmðƒ | |
</code></pre> | |
<p>A full-program accepting <code>[w, h]</code> and <code>A</code> that prints a representation of <code>B</code>.</p> | |
<p><strong><a href=""https://tio.run/##AUAAv/9qZWxsef//eHPigqzigbRawrnGrUzCpFrDhm3DsMaS////WzIsNV3/W1sxLCAyLCA0XSwgWzgsIDE2LCAzMl1d"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong><br /> | |
Or see the <a href=""https://tio.run/##y0rNyan8/7@i@FHTmkProg7tPLbW59CSqMNtuYc3HJv0//DyR407D608OV0fKO8OxFmPGvcd2nZo2///0dHRRjpGsToK0dGGOkAYqwOkDaA0iB8by6WDX40BVI2xjjFUjQFQxgCu1xiuF0k8FgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a> (this uses the register <code>®</code> in place of the 2nd program argument, <code>⁴</code> to make a reusable Link, and formats each result as a grid).</p> | |
<h3>How?</h3> | |
<p>We repeat row elements <code>w</code> times, split these into chunks of length <code>n</code> transpose the result, and take the means, then we do the same to the result, but with <code>h</code> and <code>m</code> instead of <code>w</code> and <code>n</code>.</p> | |
<pre><code>xs€⁴Z¹ƭL¤ZÆmðƒ - Main Link: [w,h]; A | |
ðƒ - reduce [A,w,h] by: | |
x - repeat (row elements) ([[1,2]]x3->[[1,1,1,2,2,2]]) | |
¤ - nilad followed by links as a nilad: | |
⁴ - 2nd program argument, A | |
ƭ - call in turn: | |
Z - ...1st time: transpose | |
¹ - ...2nd time: do nothing | |
L - length -> 1st=n; 2nd=m | |
s€ - split each (row) into chunks of length (n or m) | |
Z - transpose | |
Æm - arithmetic mean (vectorises) | |
- implicit print | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>ŒṪIAṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIc7V3k6PtzZ8P9w@6OmNf//R3NFRxvGxupwgWgdAx0DIFMh2kDHEM4CsuHyRnAVxjomOqZwNWZAcXO4egsdS7gOhJkgtiEK2xBulyHCDjMdQwsdC7AMkGmiY2QEZEcbAVUBkRFUFcgWVDcaILmdGF4sVywA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ŒṪ -- indices of non-zero values | |
I -- reduce each index by subtraction | |
A -- get the absolute values | |
Ṁ -- select the maximum | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Or only 5 bytes for a count of the ways - <code>ŒPỤ€ċ</code></sup></p> | |
<pre><code>ŒPỤ€e@ | |
</code></pre> | |
<p>A dyadic Link accepting the permutation on the left and the potential sub-permutation on the right (both 1-indexed).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opICHu5c8alqT6vD/UcOMw8sd9IGc//@jo6NjdaINdAx1jGJjuXSiow3QuDqGGAJAJoqQoY4BFjU6xqiCQJ6RDkgp3BpkLtgaJAGImSgqjNDVwISMdbAImoIFTXSMkawAOxxDAqIZXSIWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ŒPỤ€e@ - Link: permutation, P; potential sub-permutation, S | |
ŒP - powerset (i.e. all sub-sequences) of P | |
€ - for each: | |
Ụ - grade up (1-based indices sorted by their respective values) | |
@ - with swapped arguments - f(S, that): | |
e - S exists in that? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>4RðḤ‘ṁ"@>z⁶Ṛx4Y | |
</code></pre> | |
<p>Prints with <code>o</code> as <code>0</code> and <code>.</code> as <code>1</code>.</p> | |
<p><strong><a href=""https://tio.run/##ASUA2v9qZWxsef//NFLDsOG4pOKAmOG5gSJAPnrigbbhuZp4NFn///8x"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>4RðḤ‘x"@>z⁶Ṛx4Y - Main Link: integer, L | |
4 - four | |
R - range -> [1,2,3,4] | |
ð - new dyadic chain - f(X=[1,2,3,4], L) | |
Ḥ - double X -> [2,4,6,8] | |
‘ - increment -> [3,5,7,9] | |
> - X greater than L? -> [1>L,2>L,3>L,4>L] | |
@ - with swapped arguments - f([1>L,2>L,3>L,4>L], [3,5,7,9]): | |
" - zip with: | |
x - times -> [[1>L,1>L,1>L],[2>L,2>L,2>L,2>L,2>L],[3>L,...],[4>L...]] | |
z⁶ - transpose with filler of space characters | |
Ṛ - reverse | |
x4 - times four (vectorises) | |
Y - join with newline characters | |
- implicit, smashing print | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 2 bytes</h1> | |
<pre><code>œi | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o5Mz/h5frP2qYeXTSw50zNCP//4@OjtVRMFQAEtFAYGIQGwtkAikw31AnGsiNjjYGksY6YErBGCxlCiRNIYpACmJBCsFCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Just the builtin. 1-indexed and outputs an empty list if not found.</p> | |
<p>Marginally less built in:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>=ŒṪṂ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/26KSHO1c93Nn0//By/UcNM0HcGZqR//9HR8fqKBgqAIloIDAxiI0FMoEUmG@oEw3kRkcbA0ljHTClYAyWMgWSphBFIAWxIIVgIQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>1-indexed and outputs 0 if not found.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>ŒQa | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opMDE/4fbvTUj//@PjjbQMdSBYCAZqxMNRAZgjgGYBZEEQYPYWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><code>ŒQ</code> was added to the language about two months after the previous Jelly solution.</p> | |
<pre><code>ŒQ Nub sieve: for each element, is it the first occurrence of that value? | |
a Take the logical AND of that and the original list. | |
</code></pre> | |
<p><a href=""https://codegolf.stackexchange.com/a/119511/85334"">user62131's solution</a> can also be 3 bytes with a newer builtin:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>Ä=a | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wi23i/8Pt3pqR//9HRxvoGOpAMJCM1YkGIgMwxwDMgkiCoEFsLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ịṡ¥Ɱ¹²FS | |
</code></pre> | |
<p><a href=""https://tio.run/##ASIA3f9qZWxsef//4buL4bmhwqXisa7CucKyRlP/w4cpWf//MTAw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Uses the very clever tip supplied, but I'm not sure this quite inspires the description "surprisingly terse" yet... that <code>¹</code> just smells wrong!</p> | |
<p>More equivalent 8-byters:</p> | |
<ul> | |
<li><code>ṡR⁸ịⱮ²FS</code></li> | |
<li><code>ịⱮṡR$²FS</code></li> | |
<li><code>ịⱮṡⱮ`²FS</code></li> | |
<li><code>RɓịⱮṡ²FS</code></li> | |
</ul> | |
<pre><code> Ɱ¹ For each n in [1 .. N], | |
ṡ get a list of all substrings of [1 .. N] of length n, | |
ị ¥ and take the one at modular 1-index N. | |
² Square each, | |
F flatten, | |
S and sum. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>’æċ⁵_)S | |
</code></pre> | |
<p>A monadic Link accepting a non-negative integer that yields a non-negative integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw8zDy450P2rcGq8Z/P//f0NDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>’æċ⁵_)S - Link: non-negative integer, n | |
) - for each i in [1..n] (if n is 0 this will yield []): | |
’ - decrement -> i-1 | |
⁵ - 10 | |
æċ - ceil i-1 to the nearest (positive integer) power of 10 | |
_ - subtract i | |
S - sum | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>Rr_"N%RƊF²S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z@oKF7JTzXoWJfboU3B////NwMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>R Range [1..n] | |
r Range each to n: [[1..n], [2..n], …, [n]] | |
N%RƊ [(-n)%1, …, (-n)%n] | |
_" Vectorize subtract | |
F²S Flatten, square, sum | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 57 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“ṾÆxÑ3øḤC⁵ịJYSLẇɱ⁼’Bs3ŒBJṫ⁴Ɗ¦z1m€0Ṛs€9 | |
⁽HṠ,17ḥⱮịⱮ¢j€⁶ẋ3¤Y | |
</code></pre> | |
<p>A full program accepting a string as the first program argument that prints the result, using <code>0</code> for ink and <code>1</code> for no ink.</p> | |
<p><strong><a href=""https://tio.run/##AYsAdP9qZWxsef//4oCc4bm@w4Z4w5Ezw7jhuKRD4oG14buLSllTTOG6h8mx4oG84oCZQnMzxZJCSuG5q@KBtMaKwqZ6MW3igqww4bmac@KCrDkK4oG9SOG5oCwxN@G4peKxruG7i@KxrsKiauKCrOKBtuG6izPCpFn/w4fhuaMxS///IixbKys@KzxdPi4i"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (The footer just replaces the <code>1</code>s with spaces to make it easier to inspect.)</p> | |
<h3>How?</h3> | |
<pre><code>“...’Bs3ŒBJṫ⁴Ɗ¦z1m€0Ṛs€9 - Link 1: no arguments | |
“...’ - 43552819895870853685529620449548093603391 | |
B - in binary | |
s3 - split into chunks of length 3 | |
-> columns of the bottom half of 5 of the 7 characters | |
the '[' and '>' are created using reflection later | |
the comma is reversed too, we'll use its reflection | |
¦ - sparse application... | |
Ɗ - ...to indices: last three links as a monad: | |
J - range of length | |
⁴ - 16 | |
ṫ - tail (covers the columns containing ',' and '.') | |
ŒB - ...apply: bounce ("something" -> "somethingnihtemos") | |
z1 - transpose with filler 1 (fills where we didn't reflect) | |
m€0 - reflect each (constructing our ']', '>', and ',') | |
Ṛ - reverse | |
-> a list of the lines of a representation (without | |
any spacing) of ",.+<][>+.," where the first | |
comma is reversed. | |
s€9 - split each line into chunks of length 9 | |
⁽HṠ,17ḥⱮịⱮ¢j€⁶ẋ3¤Y - Main Link: list of characters, C | |
⁽HṠ,17 - [19206,17] | |
Ɱ - map across C with: | |
ḥ - hash with salt 19206 and domain [1,2,...,17] | |
-> maps: ".[,+<]>" to 2,6,10,13,14,15,17 | |
¢ - call Link 1 as a nilad | |
Ɱ - map across the lines of the result with: | |
ị - index into | |
-> 1-indexed and modular, so e.g. 17 gets the 7th item, | |
the part of the line for a '>'. | |
¤ - nilad followed by links as a nilad: | |
⁶ - space character | |
ẋ3 - repeated three times | |
j€ - join each list of line parts with three spaces | |
Y - join with newline characters | |
- implicit, smashing print | |
</code></pre> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, <sup><s>5</s></sup> 4 bytes</h1> | |
<pre><code>>ƝṢƑ</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6Fivsjs19uHPRsYlLipOSi9ccm3y4_eHOlkNLDA_thyhYcIuxLdpQR8FIR8FYR8EklgvKMQHy4RwoyxgsbAThmID5RnAZKAtEGcGUGkI4EKWGcBkQC2oWhAM1Cy5jBFcNomBMZBdCFJlAlBvCOVDz4TJGcA6UBfeLCdxjJjADjOGuNYTLGME5CJYxzCgjuG6o_41huo3gnjKEyyBYRvDAMYEFPJADiQ8A"" rel=""noreferrer"">Attempt This Online!</a></p> | |
<p>Explanation:</p> | |
<pre><code>(implicit input) [1, 4, 5, 3, 2] | |
Ɲ for each neighouring pair: [(1, 4), (4, 5), (5, 3), (3, 2)] | |
> is left greater than right? [0, 0, 1, 1] | |
ṠƑ is it the same after sorting? | |
(implicit output) | |
</code></pre> | |
<p>This tests if the list is increasing and then decreasing again.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 23 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>=”|µZṣ€0Ẏ¹Ƈ,<ƝT€Fr2/ƲẈ€ | |
</code></pre> | |
<p>A monadic Link accepting a list of lines that yields a list of lists of leg lengths and tabletop lengths.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/2UcPcmkNbox7uXPyoaY3Bw119h3Yea9exOTY3BMh3KzLSP7bp4a4OIPv/w91bDrf//68ABLpgAGJxgYgaOMGliwK4IDI1UAzlYsqCaQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>=”|µZṣ€0Ẏ¹Ƈ,<ƝT€Fr2/ƲẈ€ - Link: list of lists of characters, L | |
=”| - L equals '|'? (vectorises) | |
µ - new monadic chain - f(X=that) | |
Z - transpose X | |
ṣ€0 - split each at zeros | |
Ẏ - tighten | |
¹Ƈ - keep truthy (non-empty) ones | |
-> our legs (as lists of 1s) | |
Ʋ - last four links as a monad - f(X): | |
Ɲ - for neighbours: | |
< - less than? | |
T€ - truthy indices of each | |
F - flatten | |
2/ - reduce pairs by: | |
r - inclusive range | |
-> our tabletops (as lists of positive integers) | |
, - pair legs and tabletops | |
Ẉ€ - for each: length of each | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>Bḅ-ı=ʋ1# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/p4Y5W3SMbbU91Gyr/P9z@qGnN//8GOoY6RjrGOiY6pjpmOuY6FjqWAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Let <span class=""math-container"">\$f(n)\$</span> be the function described in the question. We use the fact that <span class=""math-container"">\$f(n) \ge n\$</span> for al <span class=""math-container"">\$n = 0,1,2,...\$</span> to save a couple of bytes.</p> | |
<h2>How it works</h2> | |
<pre><code>Bḅ-ı=ʋ1# - Main link. Takes n on the left | |
ʋ - Group the last 4 links into a dyad g(k, n): | |
B - Convert k to binary | |
ḅ-ı - Convert this to base -ı (-1+1j) | |
= - Does this equal n? | |
1# - Find the first k ≥ n, such that g(k,n) is true | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>All-ASCII jelly code to boot...</sup></p> | |
<pre><code>Ob3Uz0ZUK | |
</code></pre> | |
<p>A full program accepting a string that prints the result.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/98/yTi0yiAq1Pv///9KHkCxfB2F8vyinBRFJQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ob3Uz0ZUK - Main Link: list of characters | |
O - ordinals | |
b3 - to base three | |
U - upend (reverse each) | |
z0 - transpose with filler of zero | |
Z - transpose | |
U - upend (reverse each) | |
K - join with spaces | |
- implicit, smashing print | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>ṪṭaɗƤ⁶»Ṛ$G | |
</code></pre> | |
<p><a href=""https://tio.run/##ASYA2f9qZWxsef//4bmq4bmtYcmXxqTigbbCu@G5miRH////UFJPR1JBTQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Erik's existing answer ties with minor modifications to also use <code>G</code>: <code>LḶ⁶ẋ;"µ»ṚG</code>.</p> | |
<pre><code> Ƥ For each prefix of the input, | |
Ṫ remove the last element | |
ṭ and append it back onto | |
aɗ ⁶ the remaining elements replaced with spaces. | |
» Take the maximum of each element of that and | |
Ṛ$ its reverse. | |
G Grid format: join each row on spaces then join the rows on newlines. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ø0jẆµḢ»Ṫ<aṂ)ȦƇ§Ṃ | |
</code></pre> | |
<p>A monadic Link accepting a list of positive integers that yields a positive integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wDIOsh7vaDm19uGPRod0Pd66ySXy4s0nzxLJj7YeWA1n///@PNtcxBEJjIATSsQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///wDIOsh7vaDm19uGPRod0Pd66ySXy4s0nzxLJj7YeWA1n/D7c/alrz/390tGEsl060oQ6YMtIBQhDDGMgwhjHAUmY6xjqGOqYQxaYgCGKCGTpQI4BadEyQmDDVIGgKJiEKDcBGwSCQbQCxCcQGWhoLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Ø0jẆµḢ»Ṫ<aṂ)ȦƇ§Ṃ - Link: list of positive integers, H | |
Ø0 - [0,0] | |
j - join with S -> [0,h1,h2,...,hn,0] | |
Ẇ - all contiguous sublists | |
µ ) - for each sublist, S: | |
Ḣ - remove & yield the head from S | |
Ṫ - remove & yield the tail from S (yields 0 if S was empty) | |
» - maximum | |
< - less than? (vectorises across the altered S) | |
Ṃ - minimum (of the altered S; 0 if S is empty) | |
a - logical AND (vecorises) | |
Ƈ - filter keep those for which: | |
Ȧ - any and all? (i.e. non-empty and all non-zero) | |
§ - sums | |
Ṃ - minimum | |
</code></pre> | |
<hr /> | |
<p>Also at 16 (<a href=""https://tio.run/##y0rNyan8/9/u0cZ1jxpmJj7cufhR0xqDh7v6Du081v5wZ9Ph6T7HuoBCQOb/w@1Axv//0dGGsVw60YY6YMpIBwhBDGMgwxjGAEuZ6RjrGOqYQhSbgiCICWboQI0AatExQWLCVIOgKZiEKDQAGwWDQLYBxCYQG2hpLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">TIO</a>), and perhaps more elegant:</p> | |
<pre><code>>Ɱ’aṣ€0Ẏ¹ƇṂ×LƊ€Ṃ - Link: H | |
Ɱ’ - map across decremented values of H with: | |
> - H greater than? (vectorises) | |
a - logical AND H (vectorises) | |
ṣ€0 - split each at zeros | |
Ẏ - tighten | |
¹Ƈ - keep the truthy (i.e. non-empty) ones | |
Ɗ€ - for each: | |
Ṃ - minimum | |
L - length | |
× - multiply | |
Ṃ - minimum | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22 bytes</h1> | |
<pre><code>>Ḣ×\׫\ŒɠÄ×QƲ | |
ŻÇÐƤẎ¹ƇṂ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/u4Y5Fh6fHHJ5@aHXM0UknFxxuOTw98NgmrqO7D7cfnnBsycNdfYd2Hmt/uLPp/@F2zcj//6MNY3WiDXVApJEOEAJpYyBtDKUhsqYgCGSBaagYUI2OCYIFlgeaowNSDaZBfAOglCEcAtkGQFEzsKAp2AaQoHEsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>Should</em> work now. Filters each suffix to the longest prefix which wouldn't contain suffixes of other suffixes' rectangles, computes the area of each maximal rectangle sharing its left edge with each of those substrings, and returns the smallest non-zero such area.</p> | |
<pre><code>>Ḣ×\׫\ŒɠÄ×QƲ Monadic helper link: compute areas from "maximal zone" of suffix | |
Ḣ Remove the first item | |
> and compute the mask of which remaining items are greater. | |
×\ Zero any ones after the first zero, | |
× then multiply with corresponding elements of | |
«\ the cumulative minima. | |
Œɠ Compute the lengths of runs of equal minima, | |
Ä take the cumulative sums of those, | |
× and multiply with corresponding elements of | |
QƲ the nub of the cumulative minima. | |
ŻÇÐƤẎ¹ƇṂ Main link | |
Ż Prepend a 0. | |
ÇÐƤ Call the helper on each suffix, | |
Ẏ concatenate the resulting lists of areas, | |
¹Ƈ remove 0s, | |
Ṃ and return the minimum. | |
</code></pre> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>IḊw@</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6Fss8H-7oKndYUpyUXAwV2hitFG2so2Cio2Cuo2BoFKsUC5UAAA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<pre><code>I differences between consecutive elements | |
Ḋ remove the first item | |
w@ find the sublist index of this in the input | |
</code></pre> | |
<p><code>1</code> is truthy and all other values are falsey.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>J_r+ɗ⁸ŒPFḟ@LɗÞTḢL | |
</code></pre> | |
<p>A monadic Link accepting a list of non-negative integers that yields a non-negative integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/98rvkj75PRHjTuOTgpwe7hjvoPPyemH54U83LHI5////9HGOgY6hiAYCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/98rvkj75PRHjTuOTgpwe7hjvoPPyemH54U83LHI5//h9kdNa/7/j4420IHCWC4dMMcQwjTWMdIxAXKMgdgIJGCpY6ljaKBjCWIbwqUMdEwhAlCIwtExhbNMwGoNsCkwQ1cQCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>I <em>think</em> brute force is tersest for this one, but maybe not...</p> | |
<pre><code>J_r+ɗ⁸ŒPFḟ@LɗÞTḢL - Link: bombs | |
J - range of length of bombs -> I = [1,2,...] | |
ɗ⁸ - last three links as a dyad - f(I, bombs) | |
_ - I subtract bombs (vectorises) | |
+ - I add bombs (vectorises) | |
r - inclusive range -> list of blast zones | |
(includes out of bounds, but that's OK...) | |
ŒP - powerset | |
T - truthy indices of bombs -> T = indices we need to affect | |
Þ - sort the powerset by: | |
ɗ - last three links as a dyad - f(set, T) | |
F - flatten the set | |
ḟ@ - filter those values out of T | |
L - length | |
Ḣ - head | |
L - length | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>9</s> 8 bytes</h1> | |
<pre><code>=⁶Pi0’⁶ẋ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/2UeO2gEyDRw0zgYyHu7r/P9y95XD7w537NCP//1dXV4/hUlBIzs8rLlGoULBV0NBUsLUDiigoVOoVF@RklmhognkKCnq5iQUaxTBZECjWy0nNSy/JgArAFWblZ@ZBtUHNzs9J1cvJT9eo0ARaqAO1lGxD4WYkJiVzKaSkpiEZSgufKOjr@6VWlCjkZOalAi3ILchJLUnNqVRIyknMy1YoycgsVijJzE1VSCzKL81L4cLrZxgG8gE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 thanks to Jonathan Allan reminding me of meta consensus on being able to take a list of lines.</p> | |
<pre><code>=⁶ For each character on each line, is it a space? | |
P Take the product along each column, | |
i0 and find the first 1-index of 0 (or 0 if not found). | |
’ Decrement | |
⁶ẋ and yield a space repeated that many times (or none if not positive). | |
</code></pre> | |
<p><code>n⁶SĬS⁶ẋ</code> works similarly, but does not ignore all-whitespace lines if there's nothing else.</p> | |
<p>If we can assume the input contains no codepoints under 32 other than newlines, this <em>almost</em> works:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>7</s> <s>6</s> 5 bytes</h1> | |
<pre><code>Ṁ»\f⁶ | |
</code></pre> | |
<p><a href=""https://tio.run/##tY8xDoJAEEV7TvE7IDFwAjyCvYkNwgCrwy5x1wQ6rbyQMSEkFnoSvMiKBo2VhYmTTDF/Zt7PXxFzY23f7i7dIrvtT7bvjtdD3579ubWu6y4cIFFSG9SI4PmIpoMCNIGuWBjPf05AUMaVp1/bR@mASeamGIX34UoJOb6NbMUUsMq92h8MJ6Ppz9A3I14mDlLKPqD/SIIwnFFtwELSYFBWTIa4wZJjuYYphIYRJSHeqK1Mna@ZXz3Mdw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 because I tried replacing <code>»/</code> with <code>Ṁ</code> just in case that would work, and after further consideration, of course it would work--the lexicographically greatest line is precisely some line with the fewest leading spaces that has something else after them (under the assumption stated above).</p> | |
<p>-1 thanks to Jonathan Allan reminding me of meta consensus on being able to take a list of lines.</p> | |
<p>Fails to ignore all-whitespace lines if there's nothing else. A fix in fewer than 3 bytes seems unlikely (though <code>Ṁ»\ḟȧfɗ⁶</code> in 3 bytes seems worth mentioning).</p> | |
<pre><code>Ỵ Split on newlines. | |
Ṁ Take the lexicographically greatest row, | |
»\ find the largest character in each of its prefixes, | |
f⁶ and remove any that aren't spaces. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 10 </s> 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-1 by using the default ruling that <a href=""https://codegolf.meta.stackexchange.com/a/17095/53748"">Submissions may use list of strings instead of multi-line strings</a>.</p> | |
<pre><code>n⁶T€FṂ’⁶ẋ | |
</code></pre> | |
<p>A monadic Link accepting a list of lines (lists of characters) that yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/vUeO2kEdNa9we7mx61DATyHu4q/v/w91bDrc/3Lnv/391dfUYLgWF5Py84hKFCgVbBQ1NBVs7oIiCQqVecUFOZomGJpinoKCXm1igUQyTBYFivZzUvPSSDKgAXGFWfmYeVBvU7PycVL2c/HSNCk2ghQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>n⁶T€FṂ’⁶ẋ - Link: list lists of characters, Lines | |
⁶ - space character | |
n - not equals? (vectorises across all the characters in Lines) | |
€ - for each: | |
T - truthy indices (1-indexed) | |
F - flatten | |
Ṃ - minimum (minimum of the empty list is 0) | |
’ - decrement -> number of "common" leading spaces, N | |
⁶ - space character | |
ẋ - repeat N times (repeating -1 or 0 times gives an empty list) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 26 22 </s> 21 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-1 thanks to <a href=""https://codegolf.stackexchange.com/users/64121/ovs"">ovs</a>! (Use the outer-product quick, <code>þ</code> rather thank <code>€Ɱ</code>.)</p> | |
<pre><code>ŒdU$ŒḌƭƬw€þ§T€F’ŻI%8S | |
</code></pre> | |
<p>A dyadic Link accepting the Wordsearch on the left and the sorted word-list on the right that yields an integer.</p> | |
<p><strong><a href=""https://tio.run/##NY8/TkMxDMb3HiOCrQdgdWO/PitpXDkpkYrYYEHdEVvVmakbJ2ApOxISA@j1HvQi4SVVJ/vnP58/Pz1uNi@lDPuH1dWw//t8PX4cD8@n3eH3@@c9jbE7bd@GL76@iaWUO5NvSRNb8N5MpkZFoOt8hFklsMqeIQlUCijoJGS0lVAdRRFEV0mIlmuae86VFpG5FyBte@DVqbKSVnKCjIRqsVJPPkdPq9Sbyf3oZgbWZdDWQ4a5BGi@Og7neVFeS0jnqsLoaVGzSNR8XLSm5vJWzTM7XtKo10AUI4HaevIf"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>This would need tweaking to handle multiple instances of a word in the Wordsearch (would need to account for multiple results in the result of <code>T€</code>) but luckily, we don't need to handle that.</p> | |
<pre><code>ŒdU$ŒḌƭƬw€þ§T€F’ŻI%8S - Link: Wordsearch grid, G; word-list W | |
Ƭ - collect input (initially G) while distinct applying: | |
ƭ - alternating calls to: | |
$ - ...1: last two links as a monad: | |
Œd - anti-diagonals | |
U - reverse each | |
ŒḌ - ...2: reconstruct from forward-diagonals | |
þ - table - i.e. [[f(o,w) for o in orientations] for w in W]: | |
w€ - first index of w in each row of o | |
§ - sums (sum each of the orientation results) | |
T€ - truthy (1-indexed) indices of each | |
F - flatten | |
’ - decrement | |
Ż - prepend a zero | |
I - forward differences | |
%8 - modulo eight | |
S - sum | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ẆṂ×LƊ€Ṁ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hrraHO5sOT/c51vWoac3DnQ3/D7drRv7/H20YqxNtpKNgBKSMgZSOAkjAEMwyhrBMgWJAEsIxAXNM4MpMwPIIvilMCMkYmBFQ84zBCK7XCE0UimIB"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Ẇ Ɗ€ For each contiguous sublist of the input, | |
Ṃ× multiply its smallest element by | |
L its length. | |
Ṁ Return the largest product. | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>ÄṬSÄ÷Ṁ$×+.ḞṬ€G | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wy8Oda4IPtxze/nBng8rh6dp6D3fMAwo9alrj/j862lDHSMc4VifaSMdExxxMo0CgiKWOoQGQMtQx1DEGCsQeXm5s8B8A"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A dyadic link that outputs a bar graph (sorta).</p> | |
<p>I'm quite proud of <code>ÄṬSÄ</code> which generates the numbers before stretching. I'm also somewhat annoyed that the code to stretch the numbers is six bytes. I feel like there's got to be a better way to do that, but I'm not sure what.</p> | |
<p>The below explanation uses <code>[[1,1],[2,1],[3,2],[4,1]]</code> and <code>16</code> as an example.</p> | |
<pre><code>Ä Take the cumulative sums of each item | |
Generating a list of lists of indices at which another task segment completes. | |
For the example list, [[1,2],[2,3],[3,5],[4,5]] | |
Ṭ Take the untruth of each item | |
Turning each into a boolean list with 1s at the specified indices | |
Each task is now a boolean list where 1s represent that a task will be represented at that instant | |
For the example, [[1,1],[0,1,1],[0,0,1,0,1],[0,0,0,1,1]] | |
S Reduce the list by vectorised addition | |
The result becomes a single list where the number at each index | |
Is the number of tasks completed at that instant | |
[1,2,2,1,2] | |
Ä Take the cumulative sum, getting the total tasks completed at that instant | |
[1,3,5,6,8] | |
--$ Run what's next on the result of the above | |
÷ Float divide the list by... | |
Ṁ Its maximum | |
Producing a list of floats between 0 and 1 | |
[.125,.375,.625,.875,1] | |
× Multiply the result of the above by the other input | |
+.Ċ Round the results. | |
[2,6,10,14,16] | |
Ṭ€G Format into a grid | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 57 52 51 49 </s> 47 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“mtr”;€⁾aa;“kou“koor”⁽ñỌ,ḥ;Lị““ua“tou”Ɗ | |
Ṣḣ3ÇḢḊ? | |
</code></pre> | |
<p>A monadic Link accepting a list of lists of characters that yields a list of characters, the pronoun.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw5zckqJHDXOtHzWtedS4LzHRGiiUnV8KJvNBMo8a9x7e@HB3j87DHUutfR7u7gZKAVFpIpAoASmce6yL6@HORQ93LDY@3P5wB5DRZf////9o9cxEdR0FFDKxFMqOBQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8//9Rw5zckqJHDXOtHzWtedS4LzHRGiiUnV8KJvNBMo8a9x7e@HB3j87DHUutfR7u7gZKAVFpIpAoASmce6yL6@HORQ93LDY@3P5wB5DRZf//4e4tD3dsAhp6uB1IRP7/n5nIlZ2fCsIKiaVcmYkKEAEFNAyRASoByUPYqAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>“mtr”;€⁾aa;“kou“koor”... - Link 1: list of lists of characters, X | |
“mtr” - "mtr" | |
⁾aa - "aa" | |
;€ - concatenate each -> ["maa", "taa", "raa"] | |
“kou“koor” - ["kou", "koor"] | |
; - concatenate | |
-> domain = ["maa", "taa", "raa", "kou", "koor"] | |
...⁽ñỌ,ḥ;Lị““ua“tou”Ɗ - Link 1 (continued) | |
⁽ñỌ - 7932 | |
, - pair | |
ḥ - hash X with a salt of 7932 and our domain (from above) | |
Ɗ - last three links as a monad - f(X): | |
L - length (2 or 3) | |
““ua“tou” - ["", "ua", "tou"] | |
ị - index into | |
; - concatenate | |
Ṣḣ3ÇḢḊ? - Main Link: list of lists of characters, I | |
Ṣ - sort I | |
ḣ3 - keep up to the first three | |
? - if... | |
Ḋ - ...condition: dequeue (i.e. is length > 1 ?) | |
Ç - ...then: call Link 1 | |
Ḣ - ...else: head of I | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ḢCɓŻṙ⁹^ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjkXOJycf3f1w58xHjTvj/h9uPzrp4c4ZmpH//0cb6EBhrA6UbQhnG8LZhnBxQx0oBLMhMkhqYgE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Another port of tsh's idea:</p> | |
<pre><code>ḢC h = 1 - input.pop(0) | |
ɓŻ input.prepend(0) | |
ṙ⁹ .rotate_left(h) | |
^ .xor(h) | |
</code></pre> | |
<p>I've rearranged it a bunch of ways looking for a 6-byte formulation, but I can't find one.</p> | |
<p>In J, this is something like <code>{.(-.@[|.=)0,}.</code> (15 bytes).</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ݬ;1ƊḢ? | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o7kNrrA2PdT3cscj@/@H2o5Me7pyhGfn/f7SBDhTG6kDZhnC2IZxtCBc31IFCMBsig6QmFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/242708/85334"">Jonah's excellent J solution</a>.</p> | |
<pre><code> Ḣ Remove the first element of the input. | |
Ż ? If it's 1, prepend 0 to the remaining elements, else | |
¬ negate the remaining elements | |
;1Ɗ and append a 1. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 52 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“ṭ½IṾFhĿ_)Wẓȷ⁻⁸ẉ»ḲŒP“7dx‘ịK€ŒuƤŻoƊ€Ẏ;þḶ”!xⱮƊẎOS⁼ɗƇ⁸Ḣ | |
</code></pre> | |
<p>A monadic Link accepting a positive integer that yields a list of characters (or 0). Or a full program that prints a valid result (or 0).</p> | |
<p><a href=""https://tio.run/##AXgAh/9qZWxsef//4oCc4bmtwr1J4bm@RmjEv18pV@G6k8i34oG74oG44bqJwrvhuLLFklDigJw3ZHjigJjhu4tL4oKsxZJ1xqTFu2/GiuKCrOG6jjvDvuG4tuKAnSF44rGuxorhuo5PU@KBvMmXxofigbjhuKL///85ODk"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Don't Try it online!</a> (it won't finish)</p> | |
<p>Rather, see this slightly altered <strong><a href=""https://tio.run/##y0rNyan8//9Rw5yHO9ce2uv5cOc@t4wj@@M1wx/umnxi@6PG3Y8adzzc1Xlo98Mdm45OCgAqNE@peNQw4@Hubu9HTWuOTio9tuTo7vxjXUDOw1191of3WRkbP9yx7VHDXMWKRxvXHdsEFPUPftS45@T0Y@0gw3Ys@n90z@F2oPpIEP7/P9rSwlJHwdDc0hRIWkJJCzAJFDcyMDQBkpaW5rEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a></strong> which considers fewer possible strings (by using <span class=""math-container"">\$\frac{1}{33}\$</span> as many optional trailing <code>!</code>s).</p> | |
<h3>How?</h3> | |
<pre><code>“...»ḲŒP“7dx‘ịK€ŒuƤŻoƊ€Ẏ;þḶ”!xⱮƊẎOS⁼ɗƇ⁸Ḣ - Link: integer, N | |
“...» - "have a happy new year to you" | |
Ḳ - split at spaces | |
ŒP - powerset | |
“7dx‘ - [55,100,120] | |
ị - index into -> [["happy", "new", "year"], ["have", "a", "happy", "new", "year"], {"happy", "new", "year", "to", "you"]] | |
K€ - join each with spaces -> ["happy new year", "have a happy new year", "happy new year to you"] | |
Ɗ€ - last three links as a monad for each: | |
ŒuƤ - upper-case prefixes | |
Ż - prefix with a zero | |
o - logical OR (the full lower-case) | |
Ẏ - tighten | |
Ɗ - last three links as a monad - f(N): | |
Ḷ - [0..N-1] | |
”! - '!' | |
xⱮ - map with times -> ["", "!", "!!", ..., '!'*(N-1)] | |
;þ - table with concatenate | |
Ẏ - tighten | |
⁸ - use N as the right argument of... | |
Ƈ - filter keep those for which: | |
ɗ - last three links as a dyad - f(possibles, N): | |
O - ordinals | |
S - sum | |
⁼ - equals N? | |
Ḣ - head -> valid result or 0 if none exists | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>16</s> <s>15</s> 12 bytes</h1> | |
<pre><code>eƬ“ch“ll”µƝÞ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/12JpHDXOSM4BETs6jhrmHth6be3je/8Ptkf//q@fkJOYmqusoqCfnJ2ekghg5panp@VCRzDyIXGJOSj6UkZNYBGVB9WUk5qWDNaYk5uapAwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Previous 12-byter sorted leading digraphs incorrectly, since the index took precedence over the actual character data.</p> | |
<pre><code> Þ Sort the input by: | |
µƝ for each pair of adjacent characters as a list, | |
Ƭ apply while unique (collecting all results): | |
e is it an element of | |
“ch“ll” ['ch', 'll']? | |
</code></pre> | |
<p><code>eƬ2ƤÞ“ch“ll”</code> also works for 12 bytes, doing precisely the same thing.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 28 </s> 25 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>o8r4¤+⁹ị@%⁵ | |
ȷŒPḂo-烳⁼ɗƇḢ | |
</code></pre> | |
<p>A full program that accepts the from and to values which prints a list of <code>-1</code>s and <code>1</code>s.</p> | |
<p><a href=""https://tio.run/##AToAxf9qZWxsef//bzhyNMKkK@KBueG7i0Al4oG1Csi3xZJQ4biCby3Dp8aSwrPigbzJl8aH4bii////OP80"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Don't try it online</a> (it's checking <span class=""math-container"">\$2^{1000}\$</span> instruction strings, for golf!)</p> | |
<p><strong><a href=""https://tio.run/##AToAxf9qZWxsef//bzhyNMKkK@KBueG7i0Al4oG1CjEyxZJQ4biCby3Dp8aSwrPigbzJl8aH4bii////OP80"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (with a reduction from the powerset of <span class=""math-container"">\$1000\$</span> items to just <span class=""math-container"">\$12\$</span> so it runs in time)</p> | |
<p>Or <a href=""https://tio.run/##AV0Aov9qZWxsef//bzhyNMKkK@KBueG7i0Al4oG1CjEyxZJQ4biCby3Dp8aSwq7igbzJl8aH4bii/@KBuMKpw6figbkKOcW7cEBXwrUsw6cvxZLhuZjigqwpS@KCrFn//zg"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">try 10 at a time</a>, from the given value to all others. (Takes about 20 seconds; as above, but also uses the register, <code>®</code>, in place of the second program argument, <code>⁴</code>, since that's not mutable.)</p> | |
<p>Lastly, <a href=""https://tio.run/##AWkAlv9qZWxsef//bzhyNMKkK@KBueG7i0Al4oG1CjbFu8OYLeG5l@KxruG6jsOnxpLCs@KBvMmXxofhuKL/4oG4wqnDp@KBuQo5xbtbMCwxLDIsOCw5XXDCtSzDpy/FkuG5mOKCrClL4oKsWf8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">this 26 byter</a> that only forms strings up to length six is much faster.</p> | |
<h3>How?</h3> | |
<pre><code>o8r4¤+⁹ị@%⁵ - Link 1, make a move: current value, V ([0,9]); button, B (+/-1) | |
8r4¤ - [8,7,6,5,4] | |
o - V logical OR that (either [V,V,V,V,V] or [8,7,6,5,4] if V=0) | |
+⁹ - add B to each of those values | |
ị@ - use B to index into that list | |
(1-indexed and modular: if B=1 the first; if B=-1 the fourth) | |
%⁵ - modulo 10 | |
ȷŒPḂo-烳⁼ɗƇḢ - Main Link: from, F ([0,9]); to, T ([0,9]) | |
ȷ - 1000 (saves a byte over `12`) | |
ŒP - powerset (shorter strings come first) | |
Ḃ - modulo 2 | |
o- - logical OR -1 (vectorises) | |
Ƈ - filter keep those for which: | |
ɗ - last three links as a dyad - f(instruction, T) | |
³ - first program argument, V | |
ƒ - reduce [V]+instruction by: | |
ç - call last Link (Link 1) as a dyad | |
⁼ - equals T? | |
Ḣ - head (gets a/the shortest string) | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>iÐƤ¹Ƈ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/z8IRjSw7tPNb@P9pQx0jHWMcQCE1iDy83/A8A"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Returns values 1-indexed. Tack on a <code>’</code> for 0-indexed values. Port of my Vyxal answer.</p> | |
<pre><code> ÐƤ Map over the suffixes... | |
i Find the first index of the other value in each | |
¹Ƈ Filter out zeroes | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒPḊfƑɓẆṢ€ | |
</code></pre> | |
<p>A dyadic Link accepting the alphabet size, <code>N</code>, on the left and the candidate string, <code>S</code>, on the right as a list of integers that yields <code>1</code> if the string is a superpowerset of that alphabet size.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opICHO7rSjk08OfnhrraHOxc9alrz//9/k//RhjpGOsY6JkDSRMdQxzgWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ŒPḊfƑɓẆṢ€ - Link: integer, N; list of integers, S | |
ŒP - powerset of [1..N] | |
Ḋ - dequeue - removes the empty list | |
ɓ - new chain with swapped arguments: | |
Ẇ - all sublists of S | |
Ṣ€ - sort each | |
Ƒ - is the dequeued powerset invariant under: | |
f - filter keep the sorted sublists | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>ŒPŒ!ẇ€SɗƇƑ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opICjkxQf7mp/1LQm@OT0Y@3HJv4/vNyl9tBSpaOTHu6cARSO/P/fREfB9L@hkbGJkYmhsY4CiGVqCGIDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <span class=""math-container"">\$n\$</span> on the left, and a list of integers up to <span class=""math-container"">\$n\$</span> on the right</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>Żpݲ§i | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o7oKjuw9tOrQ8E8g8tPVw@7F2ncPthyc83DHf/f9/IwMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Outputs <code>0</code> for falsy, and a non-zero positive integer for truthy. The Footer in the TIO link simply splits the range <span class=""math-container"">\$[0, n]\$</span> into truthy (top line) and falsey (bottom line)</p> | |
<h2>How it works</h2> | |
<pre><code>Żpݲ§i - Main link. Takes n on the left | |
Ż - Zero range; [0, 1, ..., n] | |
Ż - Zero range; [0, 1, ..., n] | |
p - Cartesian product | |
² - Square everything | |
§ - Sums of each pair | |
i - Index of n, or 0 | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 40 bytes</h1> | |
<pre><code>®ṗ4’S⁼®ƊƇṀ>12ƊƇ | |
4⁻þ`×26©;¢ṗ⁴+\Ṁ>99ƊƇḢƊ€ċ | |
</code></pre> | |
<p>A monadic Link accepting a list of integers that yield <code>0</code> (falsey) if not a possible Hearts result or a positive integer (truthy) if it is.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///Quoc7p5s8apgZ/Khxz6F1x7qOtT/c2WBnaARicZk8atx9eF/C4elGZodWWh9aBFT7qHGLdgxIiaUlWPGORce6HjWtOdL9////aBMdBQMdBUMDIGEQq6CgrFCSkVqUql6skJevUJCfmVeiUFJUmZmXDhTPLNZRyCxRKM/PUy9RSMvMyyzOUAQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Don't Try it online!</a></strong> ...it won't finish (Maybe I'll golf one that will too...).</p> | |
<h3>How?</h3> | |
<pre><code>®ṗ4’S⁼®ƊƇṀ>12ƊƇ - Helper link: no arguments | |
® - recall 26 from the register | |
ṗ4 - All length 4 lists of [1..26] | |
’ - decrement (vectorises) | |
S⁼®ƊƇ - keep those with sum 26 | |
Ṁ>12ƊƇ - keep those with a maximum value over 12 | |
4⁻þ`×26©;¢ṗ⁴+\Ṁ>99ƊƇḢƊ€ċ - Link: list of four integers, X | |
4⁻þ` - table of not-equal between [1,2,3,4] and itself | |
26© - place 26 in the register | |
× - multiply the table values by 26 | |
;¢ - concatenate all the other scores by calling the helper Link | |
ṗ⁴ - All length 16 lists with those lists as elements | |
note: games take at most 15 rounds (and ⁴ is shorter than 15) | |
Ɗ€ - for each, last three links as a monad: | |
+\ - cumulative reduce by addition (non-vectorising, unlike Ä) | |
Ƈ - keep those for which: | |
Ṁ>99Ɗ - maximum is greater than 99 | |
Ḣ - head (first reached winning score list) | |
ċ - count occurrences of X | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>Ụ>ƝS‘ | |
</code></pre> | |
<p><a href=""https://tio.run/##LY47DsJADEQv5CLe/za0HIAySkmDcgE6RENPlYaOkgsg6FC4R3IRM/YirWTPG2tmD/txPIosr/vme9utp0nm9@eynh/zdXlOmHhbkd4RD9R7apMxPQVsgZiiKuyJGo/meFPYKVOCztDF3ATmQAqmXlWQrCnG0NABIv6Pq2ENZ1bPgVYL1lKACCupWdu3iB2aMkyVRfthBb1jTUEDarvhBw"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Ụ -- Grade up. Indices that would sort the input | |
>Ɲ -- For each pair of adjacent values, is the left larger than the right? | |
S -- Sum the boolean results | |
‘ -- Increment by 1 | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 27 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Is there something shorter than the <code>¬ȦƇẈƊ</code> this uses?</sup></p> | |
<pre><code>ŒṖṚ¬ȦƇẈƊÞṪḢ’$Ȧ¡€ | |
ŒJẈÇŒṪ¿ṁ@F | |
</code></pre> | |
<p>A monadic Link accepting a ragged list that yields a ragged list.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opIc7pz3cOevQmhPLjrU/3NVxrOvwvIc7Vz3csehRw0yVE8sOLXzUtIbr6CQvoNzhdpDyVYf2P9zZ6OD2H8Kd8f9/dHS0QWysDpAyjAXSRrEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///opIc7pz3cOevQmhPLjrU/3NVxrOvwvIc7Vz3csehRw0yVE8sOLXzUtIbr6CQvoNzhdpDyVYf2P9zZ6OD2XwfCnwFU8HDHfCD5qHFb1qOGOQq6dgqPGuZqRv7/Hx0dqxMdbahjFKtjrGMCZBvqRAPZQNIYSAL5xkA@UDQWrAIsbwRWGQsA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>Firstly, get the depths of the items.</p> | |
<p>While there are any non-zero integers at any depth group together as many zeros, and lists that are only zeros at all depths, as possible and decrease all the other integers by one.</p> | |
<p>Lastly, mould a flattened version of the input like that ragged list.</p> | |
<pre><code>ŒJẈÇŒṪ¿ṁ@F - Main Link: ragged list, A | |
ŒJ - multidimensional indices of A | |
Ẉ - length of each -> flat list of depths | |
¿ - while... | |
ŒṪ - ...condition: truthy multidimensional indices | |
Ç - ...do: call the helper link | |
F - flatten A | |
@ - with swapped arguments: | |
ṁ - mould like | |
ŒṖṚ¬ȦƇẈƊÞṪḢ’$Ȧ¡€ - Helper link: ragged list, Current State | |
ŒṖ - all partitions of the Current State | |
Ṛ - reverse (to have longest last rather than first) | |
Þ - sort by: | |
Ɗ - last three links as a monad: | |
¬ - logical NOT (vectorises) | |
Ƈ - filter keep those for which: | |
Ȧ - any and all? | |
Ẉ - length of each | |
Ṫ - tail | |
€ - for each: | |
¡ - repeat... | |
Ȧ - ...times: any and all? | |
$ - ...action: last two links as a monad: | |
Ḣ - head | |
’ - decrement | |
</code></pre> | |
<hr /> | |
<p>Alternative helper, same byte count:</p> | |
<pre><code>ŒṖṚŒṪƇẈ$ÞḢḢ’$Ȧ¡€ | |
</code></pre> | |
" | |
"52210","<h1><a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Tutorial"" rel=""nofollow noreferrer"">Jelly</a>, <s>31</s> <s>30</s> 27 <a href=""https://github.com/DennisMitchell/jellylanguage/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒJẈạṀ$‘Ø0jIr0Ṣ€Ṡị“[],”żFFḊṖ | |
</code></pre> | |
<p>I'm pretty rusty in Jelly, <s>so can probably be golfed a bit further</s>. It indeed can:<br /> | |
-3 bytes thanks to <em>@JonathanAllan</em>.</p> | |
<p>Input as a list; output as a string.</p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/242190/52210"">my 05AB1E answer</a>. The <code>Ø0jIr0Ṣ€Ṡị“[],”żFFḊṖ</code> is a slight modification from <a href=""https://codegolf.stackexchange.com/a/241653/52210""><em>@xigoi</em>'s Jelly answer for the <em>Build a list from a depth map</em> challenge</a>.</p> | |
<p><a href=""https://tio.run/##AVEArv9qZWxsef//xZJK4bqI4bqh4bmAJOKAmMOYMGpJcjDhuaLigqzhuaDhu4vigJxbXSzigJ3FvEZG4biK4bmW////WzMsWzIsWzFdLDJdLDMsNF0"" rel=""nofollow noreferrer"">Try it online</a> or <a href=""https://tio.run/##y0rNyan8///oJK@Huzoe7lr4cGeDyqOGGYdnGGR5Fhk83LnoUdOahzsXPNzd/ahhTnSszqOGuUf3uLk93NH1cOc0oLaHO2foHG7PAkoq6NopAGU1I///jwYqVIiONtQxitUx1jEBcQx1ooEcIGkMJEECxkABnWggE6QGosIIphisGqQ0NlbHRMc0NhYA"" rel=""nofollow noreferrer"">verify all test cases</a>.</p> | |
<p><strong>Explanation:</strong></p> | |
<pre class=""lang-python prettyprint-override""><code> # Main link, taking the input-list as argument: | |
ŒJẈ # Determine the depth of each integer: | |
ŒJ # Get the multidimensional arguments | |
Ẉ # Get the length of each inner list | |
ạṀ$‘ # Invert this depth-list: | |
$ # Apply the previous two links as monad: | |
Ṁ # Get the maximum of this list of depths | |
ạ # Calculate the absolute difference | |
‘ # Increase each 0-based depth by 1 | |
Ø0jIr0Ṣ€Ṡị“[],” # Create a string to zip with: | |
Ø0j # Surround the list with leading/trailing 0 | |
I # Forward-differences | |
r0 # Map each integer `n` to a list in the range [n,0] | |
Ṣ€ # Sort each range | |
Ṡ # Signum (-1 if <0; 0 if 0; 1 if >0) | |
ị“[],” # Index into "[]," ("[" if 1; "," if 0; "]" if -1) | |
ż # Zip/transpose, using the list above | |
F # and the flattened input as arguments | |
F # Then flatten the result | |
ḊṖ # And remove the leading/trailing "," | |
# (after which the result is output implicitly) | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/cairdcoinheringaahing/jellylanguage"" rel=""nofollow noreferrer"">Jelly (fork)</a>, 10 bytes</h1> | |
<pre><code>ÆRUŒƈ×+ƭ/Ƙ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wW1Do0cnJxoenax9bq297aOmx9v@H249Oerhzhmbk//@G5joKRgY6CsZA2sQCxLYAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> (the Jelly equivalent)</p> | |
<p>Outputs all possible solutions, or <code>[]</code> if there are none. And, the equivalent vanilla Jelly answer:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>ÆRUœc3×+ƭ/=¥Ƈ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wW1Do0cnJxoenax9bq297aOmx9v@H249Oerhzhmbk//@G5joKRgY6CsZA2sQCxLYAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How they work</h2> | |
<pre><code>ÆRUŒƈ×+ƭ/Ƙ - Main link. Takes an integer N on the left | |
ÆR - Primes from 2 to N | |
U - Reverse | |
Œƈ - Combinations of 3, no replacement | |
Ƙ - Keep those that equal N under: | |
/ - Reduce [a, b, c] by: | |
ƭ - Tie two dyads f, g: | |
× - Product | |
+ - Addition | |
This maps [a, b, c] -> [a×b, c] -> a×b+c | |
</code></pre> | |
<p>The normal Jelly one is identical, except that <code>œc3</code> is special-cased as <code>Œƈ</code> and <code>=¥Ƈ</code> is equivalent to <code>Ƙ</code></p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>ȷ2ð_«Ż+ḷṖ«S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///EdqPDG@IPrT66W/vhju0Pd047tDr4/@F2zcj//6MNDQx0oDhWJ9rY3EjH0NIIxDUCco1MdcAIwgQrMwIpM9AxMoDQhuamOuYgeSBtaGoAwhBxA0OgQZYgjUBdBrEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Another handful of ports of <a href=""https://codegolf.stackexchange.com/a/241377/85334"">Razetime's BQN</a>.</p> | |
<p><code>ȷ2</code> could hypothetically be golfed to <code>³</code> if this is used as a function in a program with no command-line arguments, but the existing Jelly corpus seems to discourage this. Modifying the programs to use STDIN has yielded no savings (but thanks to emanresu A for reminding me).</p> | |
<pre><code>ȷ2ð With 100 as the left argument to a dyadic chain: | |
« Take the minimum of each element of the input and 100, | |
_ and subtract each minimum from 100. | |
Ż Prepend a 0, | |
+ḷ add 100 to each, | |
Ṗ remove the last element, | |
« take the pairwise minima with the input, | |
S and sum. | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>ȷ2ɓ«ṖạŻ+ɓ«S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///EdqOTkw@tfrhz2sNdC4/u1gZxgv8fbteM/P8/2tDAQAeKY3Wijc2NdAwtjUBcIyDXyFQHjCBMsDIjkDIDHSMDCG1obqpjDpIH0oamBiAMETcwBBpkCdII1GUQCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>ȷ2ðḤ_«Ṗ⁸;«S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///EdqPDGx7uWBJ/aPXDndMeNe6wPrQ6@P/hds3I//@jDQ0MdKA4Vifa2NxIx9DSCMQ1AnKNTHXACMIEKzMCKTPQMTKA0IbmpjrmIHkgbWhqAMIQcQNDoEGWII1AXQaxAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<p><sup>5 if we may output 1-indexed and modular (i.e. yield 0 for the rightmost) - remove <code>;1</code></sup></p> | |
<pre><code>IA>;1TḢ | |
</code></pre> | |
<p>A dyadic Link accepting a list and an integer that yields the 1-indexed stopping point.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/T0c7aMOThjkX///@PNtRRMNZRMAEjAx0Fw9j/RgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How???</h3> | |
<pre><code>IA>;1TḢ - Link: list, B; integer, D | |
I - incremental differences of B | |
A - absolute values | |
> - greater than D? | |
;1 - concatenate a one | |
T - truthy 1-indexed indices | |
Ḣ - head | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>’×ṚḌ⁼× | |
</code></pre> | |
<p>A dyadic Link accepting <span class=""math-container"">\$a\$</span> and <span class=""math-container"">\$b\$</span> that yields <code>1</code> if <span class=""math-container"">\$a\times b = \text{reversed}( (a - 1)\times b )\$</span>, <code>0</code> if not.</p> | |
<p><strong><a href=""https://tio.run/##ASAA3/9qZWxsef//4oCZw5fhuZrhuIzigbzDl////zb/OTAwOQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8//9Rw8zD0x/unPVwR8@jxj2Hp/8/vFz/UdOa//@jo810FCxjdRSiTXQUTEG0sY6CkaG5BZgJFDMyMAdLm@sogMXMDAx0FAwNDMBazEBMC7C8hSFQhamBMVgN0EgDA7CwsZEhUKNhbCwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>’×ṚḌ⁼× - Link: a, b | |
’ - a-1 | |
× - (a-1) times b | |
Ṛ - reverse the digits of (a-1)×b | |
Ḍ - convert back to an integer | |
× - a×b | |
⁼ - equal? | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>,’$×DU⁼¥/ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCIs4oCZJMOXRFXigbzCpS8iLCIiLCIiLFsiMzQiLCIyMDc5Il1d"" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>,’$×DU⁼¥/ Main Link; dyad accepting a, b | |
,’$ pair: [a, a - 1] | |
× multiply: [ab, (a - 1)b] | |
D to digit list | |
/ reduce between the two: | |
U is the reverse of the former | |
⁼ equal to the latter? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>Ẇœ-QḊƊÐḟṪȯ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hrrajk3UDH@7oOtZ1eMLDHfMf7lx1Yv3/w@1HJz3cOeP//2hDHQUjHQUgaQxkxAIA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ẇœ-QḊƊÐḟṪȯ - Link: list, A | |
Ẇ - substrings (well, non-empty ones) sorted by length then left to right | |
Ðḟ - filter discard those for which this is truthy: | |
Ɗ - last three links as a monad: | |
Q - distinct values | |
œ- - multiset difference - remove one of each value from A | |
Ḋ - dequeue - remove one from this list if there are any | |
- [] is falsey | |
Ṫ - tail - one of, or the, longest one | |
- unless A was [] in which case zero | |
ȯ - logical OR with A - replace that zero with [] | |
</code></pre> | |
<hr /> | |
<p>Alternatively, <code>Ẇœ-QLỊƲƇṪȯ</code>.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 20 bytes</h1> | |
<pre><code>,ZḲÇ€€$€€Ẏ)œ-"/ẎḊƇFS | |
</code></pre> | |
<p>A monadic Link that accepts a pair of boards (lists of lists of characters), the first being the board's state <em>after</em> the turn has been played, that yields the score. The boards must fully align, using spaces to pad as necessary.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/6hhjqujp79fUIhPcCiQ4@IOJJycfQOAlJtHWHgkkPYGYgjyioDQgVGPGuYe6X7UtCbk4Y5F/3WiHu7YdLgdyAUiFQj1cFef5tHJukr6QMbDHV3H2t2C////Hx2tFOAYHBIa5KrEpaCj5BjhqqAQqQBm@7mGKwAxkB3LpYNbmQKQCVMWCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (The header is a Link that performs the lookup of the value of a tile by its character*)<br /> | |
Or see the <a href=""https://tio.run/##bY6xTsMwEIb3e4pTxYJExTO4xE1D0jjYhpbsLKgvUJShZYkEEks3BAusTAhFKUgdWsp7OC9izg6qOmCd7/v/O/t011eTydQ2syfOIpFKnahzMkFIqXcyzAj9wcXokhjTbeN03PIsb2bP3/fN7Zs29Ys9yk39vinJUhy0MJ8Ph9tFt3NMwtR3P2VfWfP1sV2Y5at7MV8VeONFlRNys3zclNC256t1ta78QGszpjQW6ABszJG0ByAlMikfIYASSRSQ8wT0p0AthOYBwJ/FAUiRJKQcdtVspzhAj7kxlIH5GkMBqXAbUP6vjXvt2Ndi@gIqSkO3D4FLv0Eo2dC1MymcVL8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<p>* Blank tiles can be incorporated by using a new character, e.g. <code>b</code>, too.</p> | |
<h3>How?</h3> | |
<pre><code>,ZḲÇ€€$€€Ẏ)œ-"/ẎḊƇFS - Link: pair of lists of equal-length lists of characters | |
) - for each grid in the pair: | |
Z - tranpose | |
, - pair the grid and its transpose | |
$€€ - for each line in each of those: | |
Ḳ - split at spaces | |
€€ - for each tile character in each of those: | |
Ç - call our tile value finding function | |
Ẏ - tighten | |
/ - reduce by: | |
" - zip with: | |
œ- - multiset difference | |
Ẏ - tighten | |
Ƈ - keep only those for which: | |
Ḋ - dequeue -> falsey for length one words | |
F - flatten | |
S - sum | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>ẆµĠẈ’SỊµƇṪȯ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLhuobCtcSg4bqI4oCZU+G7isK1xofhuarIryIsIsOH4oKsIiwiIixbIltbXSwgWzEsMiwzXSwgWzEsMiwyLDNdLCBbMiwyLDMsMiw0XSwgWzEsMiwxLDMsMl0sIFsxLDIsMywxLDQsMSwyLDMsNCw1LDFdXSJdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>-1 byte thanks to Jonathan Allan</p> | |
<pre><code>ẆµĠẈ’SỊµƇṪȯ Main Link | |
Ẇ all sublists | |
µ µƇ filter | |
Ġ - group indices of equal elements | |
Ẉ - length of each group | |
’ - subtract one from each length | |
S - sum of these (total number of duplicate elements) | |
Ị - is this insigificant? (between -1 and 1) | |
Ṫ take the last (longest) element | |
ȯ logical OR; if the output is 0 (only happens if input | |
is []), return the input instead, which fixes [] being | |
output as 0 | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>⁸JW;ṚZ+LƲƲ2¡¡ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASMA3P9qZWxsef//4oG4Slc74bmaWitMxrLGsjLCocKh/8KiR/8xMA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A nilad function or full program that takes a number from stdin and returns the 1-based involute of size n × n.</p> | |
<h3>How it works</h3> | |
<pre><code>⁸JW;ṚZ+LƲƲ2¡¡ | |
⁸ Empty list ([]) | |
2¡¡ Take n from stdin and repeat 2n times starting from the above: | |
Given previous matrix m, | |
ṚZ+LƲ Rotate m and add the number of rows of m | |
JW; Ʋ Prepend a row of 1..(number of rows of m) | |
</code></pre> | |
<p>The involute can be constructed iteratively as follows:</p> | |
<pre><code>Start with m = [] (think of it as 0-row, 0-col matrix) | |
Repeat 2n times: | |
If m has r rows, add r to every cell of m | |
Rotate m 90deg clockwise | |
Attach 0..r-1 (or 1..r) as a new row at the top of m | |
</code></pre> | |
<p>After every step, the matrix <code>m</code> is always an involute for some rectangular size (square at even steps). For example, using 1-based indexing, doing a single step on</p> | |
<pre><code>1 2 3 | |
8 9 4 | |
7 6 5 | |
</code></pre> | |
<p>gives</p> | |
<pre><code> 1 2 3 | |
10 11 4 | |
9 12 5 | |
8 7 6 | |
</code></pre> | |
<p>and then</p> | |
<pre><code> 1 2 3 4 | |
12 13 14 5 | |
11 16 15 6 | |
10 9 8 7 | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 34 33 </s> 32 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>I would have thought Jelly would be better at this, maybe a more mathematical approach will triumph?</sup></p> | |
<pre><code>ŒMḢḢ | |
+þ`¬ZṚ$ṛ¬Ç$¦€Ç¦‘ɼ$ḣÇȦƊ?ƬȦƇṂ | |
</code></pre> | |
<p>A monadic Link accepting a positive integer that yields a list of lists of positive integers (top-left <code>1</code> option).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///oJN@HOxYBEZf24X0Jh9ZEPdw5S@XhztmH1hxuVzm07FETkAZSDTNO7lF5uGPx4fYTy4512R9bA6TaH@5s@n@43f3/f0MDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Start with an <span class=""math-container"">\$N\times N\$</span> table of zeros, then repeatedly either fill in the next number in the first zero of the first row that contains a maximal value, unless that row is filled in which case rotate. This process terminates with a full table but rotated further than we want, so we collect all the states along the way then pick the one we need out (using <code>ȦƇṂ</code>).</p> | |
<pre><code>ŒMḢḢ - Helper Link: list of list of integers (current state) | |
ŒM - multidimensional indices of maximal elements | |
Ḣ - head | |
Ḣ - head -> row index containing the maximum value | |
+þ`¬ZṚ$ṛ¬Ç$¦€Ç¦‘ɼ$ḣÇȦƊ?ƬȦƇṂ - Link: positive integer, N | |
+þ` - [1..N] addition table with [1..N] | |
¬ - logical NOT -> N×N table of zeros | |
Ƭ - collect inputs while distinct applying: | |
? - if... | |
Ɗ - ...condition: last three links as a monad: | |
Ç - call our helper link | |
ḣ - head (the current state) to that index | |
Ȧ - all truthy when flattened? | |
$ - ...then: last two links as a monad: | |
Z - transpose | |
Ṛ - reverse | |
- this rotates when we've finished a row | |
$ - ...else: last two links as a monad: | |
ɼ - apply to the register (initially 0) & yield: | |
‘ - increment | |
¦ - sparse application... | |
Ç - ...to indices: call our helper link | |
€ - ...apply: for each: | |
¦ - sparse application... | |
$ - ...to indices: last two links as a monad: | |
¬ - logical NOT (vectorises) | |
Ç - call our helper link | |
ṛ - ...apply: the incremented register value | |
Ƈ - filter keep those for which: | |
Ȧ - all truthy when flattened? | |
Ṃ - minimum (of the rotate tables we have left) | |
</code></pre> | |
<hr /> | |
<p>Another approach, but even more lengthy at 39:</p> | |
<pre><code>RµṚĖm€0F;Ɱ"ḊṚ’$ṖṚ4ƭ³’Ḥ¤Ð¡UÐeẎIƇŒṬ€×"J$S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/o0NaHO2cdmZb7qGmNgZv1o43rlB7u6AIKPWqYqfJw5zQgy@TY2kObgdyHO5YcWnJ4wqGFoYcnpD7c1ed5rP3opIc71wB1Hp6u5KUS/P9wu/v//4YGAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try this one</a></p> | |
<p>This one works by building a list of the two-dimensional indices ordered by their final value then composing the table by adding up tables that are all zeros except the bottom-rightmost entry which is the number we want there in the end.</p> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>UZƭ7СQL | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z806tha88MTDi0M9Pl/uP1R05r//6O5FBSio01jY3XADAMdg1gdMAkXMAQKGKILGGAKGMIEjKBajGECxjomQAFLhApDHSMMQ8EWGwJpqGnIkkYwVyHRaJJG@CTN0CVjAQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><code>UZƭ</code> alternatively performs <code>U</code> (reverse each row) and <code>Z</code> (transpose).</p> | |
<p>Doing this 7 times and collecting all intermediate results with <code>7С</code> gets all 8 transforms: {identity, <code>U</code>, <code>UZ</code>, <code>UZU</code>, … <code>UZUZUZU</code>}, and <code>QL</code> (unique+length) counts distinct ones.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Yowch, it took quite some effort circumventing Jelly's, usually useful, modular indexing nature!</sup></p> | |
<pre><code>J;-ṗLị@’¥’r‘RƇƲ}¦ƒ€⁸§Ṁ | |
</code></pre> | |
<p>A monadic Link accepting a list of positive integers that yields the maximal sum reachable (only revisiting previously squashed indices if better for the golf).</p> | |
<p><strong><a href=""https://tio.run/##AUEAvv9qZWxsef//Sjst4bmXTOG7i0DigJnCpeKAmXLigJhSxofGsn3CpsaS4oKs4oG4wqfhuYD///9bMSw4LDEsOSwxXQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9/LWvfhzuk@D3d3OzxqmHloKZAoetQwI@hY@7FNtYeWHZv0qGnNo8Ydh5Y/3Nnw/3A7kPf/f3S0kQ4QxipAgbKCrp2CGZdOtImOKVwQKmwJFjZDFzY0AIsjy0DETSDqkQyCiJsCxQ11DHUsUcWNDKHiCBmIOES9BUhcxzAWLm5sAVFvEIvmHoi4KcQksA6IenOguCVY1BDDfGOgO81BdiCZb8gVCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>J;-ṗLị@’¥’r‘RƇƲ}¦ƒ€⁸§Ṁ - Link: list of integers, A | |
J - range of length of A -> [1,2,...,length(A)] | |
- - literal -1 | |
; - concatenate -> [1,2,...,length(A),-1] -> our alphabet | |
L - length of A | |
ṗ - Cartesian power (all words of length length(A) with our alphabet) | |
€ - for each word | |
⁸ - ...using A as the right argument: | |
ƒ - reduce [A]+word by: | |
¦ - sparse application | |
} - ...to indices: using the right argument (next integer of word): | |
Ʋ - last four links as a monad - f(I=integer): | |
’ - decrement I | |
‘ - increment I | |
r - inclusive range -> [I-1, I, I+1] | |
Ƈ - filer keep those (of [I-1, I, I+1]) for which: | |
R - range (truthy for positive integers) | |
¥ - ...apply: last two links as a dyad - f(current state, I): | |
@ - with swapped arguments: | |
ị - index into -> our squish value | |
’ - decrement | |
§ - sums | |
Ṁ - maximum | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>;0µ+J«LịƬ`L | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/a4NBWba9Dq30e7u4@tibB5//hds3I//@jow1juXSiDXWAEMSw1EFiGgOZRkCIJGimYwahDHVA8uY6JjpmQNoIyIJKGYKloMpNgfIgWYQlIGYsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Feels like there ought to be one more byte to shave off, perhaps dealing with the final step with something shorter than <code>;0µ</code>, but it at least ties.</p> | |
<pre><code>;0µ Append a 0 to the list. | |
+J Find the sum of each element and its 1-index | |
«L capped at the list's length. | |
ịƬ` Index this into itself (constant) until it doesn't change, | |
L and return the number of iterations that took. | |
</code></pre> | |
<p><code>Ṗ’o¥\ċ1‘µÐƤṀ</code> and <code>’o¥\ÐƤI>-§Ṁ‘</code>, a byte longer and completely different, also work.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>ṗµẆ;"ḟƑ$)S | |
</code></pre> | |
<p><a href=""https://tio.run/##ASkA1v9qZWxsef//4bmXwrXhuoY7IuG4n8aRJClT/8mTxbvDp0DDvkf//zX/Nw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Went through no fewer than six 11-byters before finally reaching par, and turns out it's pretty much just what Dennis did on the linked challenge...</p> | |
<pre><code> µ ) Map over | |
ṗ the Cartesian power of the arguments: | |
Ẇ The list of the word's contiguous substrings | |
;" $ with each one concatenated to itself, | |
Ƒ is it unchanged by | |
ḟ removing every substring of the word? | |
S Sum the results. | |
</code></pre> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 20 bytes</h1> | |
<pre><code>Ø0jIr0Ṣ€Ṡị“[],”ż⁸FḊṖ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wDIMszyKDhzsXPWpa83Dngoe7ux81zImO1XnUMPfonkeNO9we7uh6uHPa////ow11jHQg2BgIDXVMYgE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A string-based approach.</p> | |
<h2>Explanation</h2> | |
<pre><code>Ø0jIr0Ṣ€Ṡị“[],”ż⁸FḊṖ | |
Ø0j Surround with zeroes | |
I Increments | |
r0 Raplace each element x with the range x..0 | |
Ṣ€ Sort each range | |
Ṡ Replace each number with its sign | |
ị“[],” Perform the mapping: 1 -> "[", -1 -> "]", 0 -> "," | |
ż⁸ Zip with the original input | |
F Flatten | |
ḊṖ Remove the leading and trailing commas | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ߌḊ¡€Ṣ | |
</code></pre> | |
<p><a href=""https://tio.run/##XZAxDsIwDEX3nsISa5CapgnJwj2QlZEF9QKsLEiMTGwIZg5AVyoOUi4S7DhUgBTJv87z9282667bpjScn8fxfnhcXrvb2F/TsCdBrf5EdZUSVtgo0FHBDOZLQK2giRUi6lqBVRDoBp2Clk5kzTh9G9aGKvO5T8rTFWudR12Mky1OPRkjBz/ZmWIn0km/zTszzzEoY01@nMyVVJqDL4QOBQ3Z92vtB/ZcM/o/nj2DvAFHsIJ5VhLW/v9I@EVNQa0sr@Ib"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>ߌḊ¡€Ṣ - Main link f(M). Takes a multidimensional array M on the left | |
€ - Over each inner element E of M: | |
ŒḊ - Get its depth, D | |
ß ¡ - Call f(E) D times | |
Ṣ - Sort the result | |
</code></pre> | |
<p>Essentially, as sorting is <a href=""https://en.wikipedia.org/wiki/Idempotence"" rel=""noreferrer"">idempotent</a>, <code>f</code> is also idempotent, and so we can apply it as many times as we want with no extra side effects. Therefore, we iterate over each element of <code>M</code>, depth-wise, apply <code>f</code> to it, then sort the result.</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ŒpQ€ẈṀ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLFknBR4oKs4bqI4bmAIiwiIiwiIixbIltbMSwgMiwgM10sIFsyLCA0LCA1LCA2XSwgWzMsIDUsIDYsIDddLCBbMSwgMl0sIFsyLCAzXSwgWzEsIDNdXSJdXQ=="" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>ŒpQ€ẈṀ Main Link | |
Œp Cartesian Product; get all possible selections | |
Q€ Uniquify each | |
Ẉ Length of each | |
Ṁ Maximum result | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ṫ‘ḢƊƬÐƤẈṀ_2 | |
</code></pre> | |
<p>A monadic Link accepting a list of integers that yields an integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hztWPGmY83LHoWNexNYcnHFvycFfHw50N8Ub///@PNtMx1LHUMdYx1zHRMQPSRkCWmY5ZLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hztWPGmY83LHoWNexNYcnHFvycFfHw50N8Ub/D7c/alrz/390tGEsl060oQ4QghiWOkhMYyDTCAiRBM10zCCUoQ5I3lzHRMcMSBsBWVApQ7AUWHksAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>Unfortunately, while <code>Ḣ</code> pops off and yields the head of a list it affects the original list given to <code>ÐƤ</code> (for suffixes of the list) as well as the suffix being dealt with at the time and so affects the remaining suffixes. Without the popping we need to increment for <code>ṫ</code> (tail from) to do the correct thing so I've incremented all elements, tailed from each of those and then kept the head of those lists. Maybe there is a better way to do this challenge that will take less bytes...?</p> | |
<pre><code>ṫ‘ḢƊƬÐƤẈṀ_2 - Link: list of integers, River | |
ÐƤ - for each suffix of River: | |
Ƭ - collect input values while distinct, applying: | |
Ɗ - last three links as a monad: | |
‘ - increment all values | |
ṫ - tail (vectorises, so tail at from incremented value) | |
Ḣ - head (the list that used the first incremented value) | |
Ẉ - length of each | |
Ṁ - maximum | |
_2 - subtract two (the final [] and the 0 that heading [] (or 0) yields) | |
</code></pre> | |
<hr /> | |
<p>This one is 13 bytes, but maybe the idea can lead to a shorter solution?</p> | |
<pre><code>JŒPịṖ⁼I{ʋƇ⁸ṪL | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 82 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>⁼“¤fÞ#³ıḄ×»“¡mƁµɼʋ"§ĿỵSėṭƊḲṂ§ÇḋỵL}Ṅnʠṫ2#ap{}fƓ*ƑṇḢ§ƓṾ®[~]sṘÐ/wỊḊ.÷⁹ß’ḣṃ“ \_¶-=|.)/ | |
</code></pre> | |
<p>A full program accepting a string that prints the art when that string is "dotnet ef".</p> | |
<p><strong><a href=""https://tio.run/##Aa0AUv9qZWxsef//4oG84oCcwqRmw54jwrPEseG4hMOXwrvigJzCoW3GgcK1ybzKiyLCp8S/4bu1U8SX4bmtxorhuLLhuYLCp8OH4biL4bu1TH3huYRuyqDhuasyI2Fwe31mxpMqxpHhuYfhuKLCp8aT4bm@wq5bfl1z4bmYw5Avd@G7iuG4ii7Dt@KBucOf4oCZ4bij4bmD4oCcIFxfwrYtPXwuKS////9kb3RuZXQgZQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>⁼“...»“...’ḣṃ“... - Main Link: string, S | |
“...» - dictionary compression of "dotnet ef" | |
⁼ - S equals that? (1 if so; 0 otherwise) | |
“...’ - base 250 integer (say, n) = 1111111111111023341111111555660111122413331133311178111127247133771337117119111222471371713711123017110072247333773711111110111222022 | |
ḣ - head that (implicitly wrapped in a list) by (1 or 0) | |
-> [n] or [] | |
“... - the art's characters (¶ is a newline & no closing quote needed) | |
ṃ - decompress the integers (in either [n] or []) using the | |
characters as the digits [1,...,9,0] (as there are ten of them) | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 19 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<p><sup>Hmm, I don't think we want any <code>ṀȯLƊ</code> on our pumpkins :( I also feel like this is beatable*!</sup></p> | |
<pre><code>ŒṖṀȯLƊ⁼LƊȧTE$Ɗ€Ȧ$ƇẸ | |
</code></pre> | |
<p>A monadic Link accepting a list that yields <code>1</code> if a valid plan or <code>0</code> otherwise.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opIc7pz3c2XBivc@xrkeNe4DkieUhripATtOaE8tUjrU/3LXj////0QY6BjqGQGwMJg1iAQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///opIc7pz3c2XBivc@xrkeNe4DkieUhripATtOaE8tUjrU/3LUDrGqGzuH2rEcNcxR07RQeNczVjPz/PzraMFYn2kDHAEgagzCEpQMU0TECsw10QDwTsAiEb6BjqAMSNUQSgYjBoCmUNoOqMIPLGCNUQXVC1IJcYQSyEypqBGYZgdwAVBkLAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ŒṖṀȯLƊ⁼LƊȧTE$Ɗ€Ạ$ƇẸ - Link: list of integers, Plan | |
ŒṖ - all ways to partition Plan | |
Ƈ - filter keep those partitions for which: | |
$ - last two links as a monad: | |
Ɗ€ - for each part, last three links as a monad: | |
Ɗ - last three links as a monad: | |
Ɗ - last three links as a monad: | |
Ṁ - maximum of the part | |
L - length of the part | |
ȯ - logical OR | |
L - length of the part | |
⁼ - equal? (1 if enough space for the largest pumpkin | |
ignoring others in the part; 0 otherwise) | |
$ - last two links as a monad: | |
T - truthy indices | |
E - all equal? (1 for those parts with up to one | |
non-zero; 0 otherwise) | |
ȧ - logical AND (1 for good parts; 0 otherwise) | |
Ạ - all? (1 for good partitions; 0 otherwise) | |
Ẹ - any? (1 if the plan will work; 0 otherwise) | |
</code></pre> | |
<hr /> | |
<p>* Maybe it's not that bad... | |
This <a href=""https://tio.run/##y0rNyan8///hjq5HjTsO7TzW/nDHokO7Qx7umA/EXSppXiD@kkMLH@6cdWjr4Qk@D3ft@H@4/VHTmqOTHu6c8f9/dLRhrE60gY4BkDQGYQhLByiiYwRmG@iAeCZgEQjfQMdQByRqiCQCEYNBUyhtBlVhBpcxRqiC6oSoBbnCCGQnVNQIzDICuQGoMhYA"" rel=""noreferrer"" title=""Jelly – Try It Online"">different approach</a> is much more efficient but a couple of bytes longer (greedily grow the outermost pumpkin using outer zeros if possible) - outputs <code>0</code> if the plan is valid or <code>1</code> otherwise:</p> | |
<pre><code>Ḋ⁸¹ƇḢ»TḟTḊ$fJḢ¤¡ṚµÐLẸ | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>ŻŻ+ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o7qO7tf8/3L3l0Najkx/uXPyoYY6CrZ3Co4a5D3csCjvcfnTSw50zNCP//4821DHSMY4FSYKZJmAuVzSQhgiaQASBQoYwVQY6hkCuOVDYVMcMIgjiGBrpGBqAhbjgRhkiTDYFqzcC64WYATfOCGokgg2XMoZikLSFjrmOGcgciDSIa4iw1gRsgImOpY6hGUy/CUjKyAAiBnYVwj0gDgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Using <a href=""https://chat.stackexchange.com/transcript/message/60209526#60209526"">hyper's oberservation</a></p> | |
<h2>How it works</h2> | |
<pre><code>ŻŻ+ - Main link. Takes a list L | |
ŻŻ - Prepend two zeros | |
+ - Add elementwise | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>QJƑ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJRSsaRIiwi4bu0T185NsOH4oKsIiwiIixbImFcbmFhYVxuYWJhYlxuYWFiY2NcbmFiYWNhYmFkYWJhY2FiYVxuYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpoXG5iXG5hY1xuYmFjXG5hYmJkY1xuYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5emFcbmFicmFjYWRhYnJhIl1d"" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>Takes input as one-indexed alphabet indices.</p> | |
<pre><code>QJƑ Main Link | |
Q Uniquify | |
JƑ Is it equal to [1, 2, 3, ..., len]? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>»/⁹ÐƤ⁺€ | |
</code></pre> | |
<p>A monadic Link accepting a list of lines that yields a list of lines.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///Qbv1HjTsPTzi25FHjrkdNa/4/3L3l8PLI//8VoEA/BsbigokoKMSgCumDiBhkIX0IJwYhpA8zJgYmBBeBiHGhiIDFuFBFQGJcQJF4JAAUg7mrBoxQnEpTIYJ@BDoP7lqgGJD8bwwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>»/⁹ÐƤ⁺€ - Link: list of lists of characters, Lines; pixel size, N | |
ÐƤ - for non-overlapping infixes | |
⁹ - ...of length: chain's right argument, N | |
/ - ...yield: reduce by: | |
- maximum (vectorises) | |
(Note: space is less than any other character used) | |
€ - for each: | |
⁺ - repeat the last link - i.e. do Ṁ⁹ÐƤ | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒHḢ$ŒḂпL’ | |
</code></pre> | |
<p>A monadic Link accepting a list of characters that yields an integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///oJI@HOxapHJ30cEfT4QmH9vs8apj5////xKQkBAIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>So many 2 byte instructions:(</p> | |
<h3>How?</h3> | |
<pre><code>ŒHḢ$ŒḂпL’ - Link: list of characters, S | |
п - collect up input values while... | |
ŒḂ - ...condition: is a palindrome? | |
$ - ...next input: last two links as a monad: | |
ŒH - split into halves (first 1 longer if odd length) | |
Ḣ - head | |
L - length | |
’ - decrement | |
</code></pre> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>10</s> 9 bytes</h1> | |
<pre><code>⁸P‘ṭƊ¡’0¦ | |
</code></pre> | |
<p><a href=""https://tio.run/##AR4A4f9qZWxsef//4oG4UOKAmOG5rcaKwqHigJkwwqb//zQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Based on the Sylvester sequence.</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>Ḋm2Ḥ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLhuIptMuG4pCIsIiIsIiIsWyJ1bWJyZWxsYSJdXQ=="" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>Ḋm2Ḥ Main Link | |
Ḋ Remove the first character | |
m2 Return every other character | |
Ḥ Double. This turns ["a", "b"] into ["aa", "bb"], which | |
is not the correct format for a Jelly string, but displays | |
correctly when printed. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Œp߀ | |
</code></pre> | |
<p>A monadic link accepting a list of the two ragged lists that yields their product-all-the-way-down.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opILD8x81rfl/uP3opIc7Z/z/Hx0dHasDxEAiNpZLB8aL5YoFAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong><br /> | |
Or see the <a href=""https://tio.run/##y0rNyan8///opILD8x81rfn/cPeWQ1sf7th0dFIYkHu4/eikhztnPNwx/1HjNh2HrEcNcxR07RQeNczVjPz/PzpWITqWKzo6FkgDCRBLB8QAcUEUUABMw5SBJXWgyiEqAQ"" rel=""nofollow noreferrer"">test-suite</a> (The footer parses and reformats like the question for ease of comparison)</p> | |
<h3>How?</h3> | |
<pre><code>Œp߀ - Link, "f": list of lists (initially the two inputs), A: | |
Œp - Cartesian product of A's items | |
€ - for each resulting list, a: | |
ß - call this Link - i.e. f(a) | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 9 bytes</h1> | |
<p>Takes the <code>length,breadth</code> as the first argument and the symbols as a second argument.</p> | |
<pre><code>«þ/U«ṚƊịY | |
</code></pre> | |
<p><a href=""https://tio.run/##ASMA3P9qZWxsef//wqvDvi9VwqvhuZrGiuG7i1n///85LDf/IkAtIg"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>«þ/ -- Minimum table of the left argument | |
Ɗ -- On that table: | |
U«Ṛ -- Minimum of each row reversed and the columns reversed | |
ị -- Index into the symbols (modular indexing) | |
Y -- Join by newlines | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 85 bytes</h1> | |
<pre><code>“¦÷fİȷ⁻ƒỌU,ɠṘµINọþọ^°56ß~+Œ:ḟyṘdạʠȷẇḌẆ[ŻṁỤ°8zẉݬ{ḋzỵḣuṄ}Ṗj|ĠỌ½Ɲœiḥd⁷ɦȮʋḢ/iÇØ#¤œ’Bs28Y | |
</code></pre> | |
<p><a href=""https://tio.run/##AawAU/9qZWxsef//4oCcwqbDt2bEsMi34oG7xpLhu4xVLMmg4bmYwrVJTuG7jcO@4buNXsKwNTbDn34rxZI64bifeeG5mGThuqHKoMi34bqH4biM4bqGW8W74bmB4bukwrA4euG6icSwwqx74biLeuG7teG4o3XhuYR94bmWanzEoOG7jMK9xp3Fk2nhuKVk4oG3yabIrsqL4biiL2nDh8OYI8KkxZPigJlCczI4Wf//"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Boring compression approach, but hey, it beats Vyxal. Outputs <code>1</code> for dead and <code>0</code> for live.</p> | |
<h2>How it works</h2> | |
<pre><code>“¦÷...#¤œ’Bs28Y - Main link. | |
“¦÷...#¤œ’ - Compressed base-250 number; 267895893890769127503254177532545466822034310678965401690230443467397769491824224432265750760013635073235874891500166493638274198855494319824095093907255178782140555126842877012017876031 | |
B - Binary | |
s28 - Split into chunks of size 28 | |
Y - Join by newlines | |
</code></pre> | |
<p>Fun fact, using base 2 is the <a href=""https://tio.run/##y0rNyan8///h7i1hj5rWAJHbwx2tjzauO7H94Y6uQ1sf7mg2MjV4uLv78AyvR43bdQwtjA4tqXy4u@dR475HDXMeNczM0vQ5POHhzqb///8bgoEBEKCRQFEusIyhATYSImkIUYpOGnJhMRBGgnTi0giSNMBtKT5jDbjwaIRI4rIUv7EjxbWG@I0lNyWAJbEYCwIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">shortest</a> of all approaches in the form "large compressed number, to base, split"</p> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 28 bytes</h1> | |
<pre><code>“-\/_”iⱮⱮZTḢ+S+3BḊƲƲ€FḊs2E€Ạ | |
</code></pre> | |
<p><a href=""https://tio.run/##VUwxCsJAEOz3FdtKOBb0B4J@QKuwcJWFks5Kq9NGsLVVEG1FMKhEhRSK@cfdR869XBpnB3bYmdnJKMtm3juzVUzamd3YXc7CdGiLQzJIOl1brKu8yt3y1Bc5bfdE2efefzf2cXSL8n2XudnXdS5tTD@rlvcMyACsAZGRmGqFCgPEIA4GNQklF7mTbK0p5GI8gnUw8A9SAIK45As6UwqBakcB6vBZQE2PYkDIPw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Seems long!</sup></p> | |
<pre><code>¬RẎƬṖẈ€E€i0oLƲ | |
</code></pre> | |
<p>A monadic Link accepting a list that yields the "array-depth".</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///QmqCHu/qOrXm4c9rDXR2Pmta4AnGmQb7PsU3/D7cD2f//R0cbxnLpRBvqKBjpKBiDmHA2iGOsowDBsSARmAqQJqCiWKikSWxsLIpOkJiOgqmOghmyONAQqEy0KYhhBsTmyFqh5oG0QuXNdRQsdBQsIUqiLUBqQDJgVSAGxAqYAdFQWahF0RCHQfSCHByNWzcYGMdCAFcsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Uses the same intuition as <a href=""https://codegolf.stackexchange.com/a/241157/53748"">emanresu A's JavaScript answer</a></p> | |
<pre><code>¬RẎƬṖẈ€E€i0oLƲ - Link: list, A | |
¬ - logical NOT - converts all integers to zeros | |
R - range (vectorises) - converts all zeros to empty lists | |
Ƭ - collect up inputs while distinct, applying: | |
Ẏ - tighten | |
Ṗ - pop - remove the final one | |
Ẉ€ - lenth of each for each | |
E€ - all-equal for each | |
Ʋ - last four links as a monad, f(that): | |
i0 - first 1-indexed index of a zero (or zero) | |
oL - logical OR with the length | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>OSḍ@L | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJPU+G4jUBMIiwiw4figqwiLCIiLFsiW1wiYWJjYlwiLCBcImNjY1wiLCBcImFhYVwiLCBcImJlZFwiLCBcImNvZGVcIiwgXCJib2RlXCJdIl1d"" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>OSḍ@L Main Link | |
O ord (vectorizes) | |
S sum | |
ḍ@ is this divisible by | |
L the length of the input? | |
</code></pre> | |
<p>If outputting inconsistent truthy/falsy values is allowed:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>OSọL | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJPU+G7jUwiLCLDh+KCrCIsIiIsWyJbXCJhYmNiXCIsIFwiY2NjXCIsIFwiYWFhXCIsIFwiYmVkXCIsIFwiY29kZVwiLCBcImJvZGVcIl0iXV0="" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>OSọL Main Link | |
O ord (vectorizes) | |
S sum | |
ọ how many times is this divisible by | |
L the length? | |
</code></pre> | |
<p>This works using an observation made by <a href=""https://chat.stackexchange.com/transcript/message/60084609"">caird coinheringaahing</a> in chat that you do not need to account for the offset between A = 1 and A = 65 when you take the codepoint, since the codepoint offset will be added <code>len(X)</code> times and not affect the modulo.</p> | |
<p>Yes, caird also just straight up gave the algorithm, but to be fair, the observation was the only non-trivial part about this solution anyway.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 56 </s> 51 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>+1 to cater for strict IO (two distinct outputs rather than truthy vs falsey being allowed)</p> | |
<pre><code>“jtklmnpsw”,ØẹŒpṖṖ¬3,8¦p”n;ƊṗⱮLẎF€⁾mnyw⁾nnƲÐḟḊ€;$e@ | |
</code></pre> | |
<p>A (very inefficiant) monadic Link that yields <code>0</code> when the input string is not a Toki Pona word and <code>1</code> when it is.</p> | |
<p>(Don't) <a href=""https://tio.run/##y0rNyan8//9Rw5yskuyc3LyC4vJHDXN1Ds94uGvn0UkFD3dOA6JDa4x1LA4tKwDK5Fkf63q4c/qjjet8Hu7qc3vUtOZR477cvMpyIJWXd2zT4QkPd8x/uKMLKGGtkurw////rMQ8AA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> (it's so inefficient it'll only complete for words of length three or less!)</p> | |
<p>...but here is a <a href=""https://tio.run/##JY6xasMwEIZfJuDFm5eAl0x9idLhChpkSSeBbEQ2t2OGEDq0HVoKHTKFQDPFGTrYxO8hvYiiU0Cn06/v139qmJTrGEP/1bRCKjTWhf67nD79Zbi@GT@8pzUeqnI57k0iWM8bP3yEv2PlL9uH8HoIL/8K1y41xPk07fz5x583CdSLOP6yVbLG@FiAY1iURQO0s1RKo@1aSCfBDBOc7rkgYjmaLA0IkORoQYHQ@bnSGdzTnrniJDWCpS4BSTudXU6Tp81RrqORvCFsO8wcECncgqJPQPI93QA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a> that has all tests except the four syllable <code>pankulato</code> that (a) limits to three base-syllables, rather than that of the number of characters in the input string and (b) only calls the word-generating code once for all (hence the <code>e@</code> has been moved out to the footer).</p> | |
<h3>How?</h3> | |
<p>We construct a list containing ALL valid Toki Pona words constructed from at most <code>length(input)</code> syllables and check if the input is in there.</p> | |
<p>Yep that's soooo nasty, but without easy regex access I imagine it's the golfiest way.</p> | |
<pre><code>“jtklmnpsw”,ØẹŒpṖṖ¬3,8¦p”n;Ɗṗ - (partial) Link: integer (from below!) | |
“jtklmnpsw” - "jtklmnpsw" | |
Øẹ - "aeiou" | |
, - pair | |
Œp - Catesian product | |
ṖṖ - pop off "wu" and "wo" | |
3,8¦ - apply to indices 3 & 8 ("ji" & "ti"): | |
¬ - logical NOT (replace these with [0,0] (integers) | |
Ɗ - last three links as a monad: | |
”n - 'n' | |
p - Cartesian product (appends 'n' to each) | |
; - concatenate | |
ṗ - Catiasian power (the integer) | |
...ⱮLẎF€⁾mnyw⁾nnƲÐḟḊ€;$e@ - (continued) Link: string, S | |
... L - length of S | |
...Ɱ - map across [1..length(S)] with: | |
... - code above -> base-syllable combos of each length | |
Ẏ - tighten | |
F€ - flatten each | |
Ðḟ - filter discard those for which: | |
Ʋ - last four links as a monad: | |
⁾mn - "mn" | |
y - translate (convert ms to ns) | |
⁾nn - "nn" | |
w - index of first occurrence (or zero) | |
$ - last two links as a monad: | |
Ḋ€ - dequeue each | |
; - concatenate | |
@ - with swapped arguments: | |
e - S exists in there? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 89 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“µð1|ż‘Ḥ‘>@LS‘ị“\-/“(“^oḄṾȥx“-__-@_‘ŒḄ‘6¦U7¦0ịxɗ€6a"ƊZỌ¤ | |
L⁶;“£ṭṛẇṣLe“¦ŒɱṣṀ^Tż»jṭÇ“Pov:¶”; | |
</code></pre> | |
<p>A full program accepting a (Python formatted) string argument that prints the result.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9Rw5xDWw9vMKw5uudRw4yHO5YASTsHn2AQZ3c3UDZGVx9IagBxXP7DHS0Pd@47sbQCyNONj9d1iAcqOzoJKAykzQ4tCzU/tMwAqK3i5PRHTWvMEpWOdUU93N1zaAmXz6PGbdYguxY/3Ln24c7ZD3e1P9y52CcVJLTs6KSTG4G8hzsb4kKO7jm0Owuo5nA7UCogv8zq0LZHDXOt////r66uPkQcC3QpAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8//9Rw5xDWw9vMKw5uudRw4yHO5YASTsHn2AQZ3c3UDZGVx9IagBxXP7DHS0Pd@47sbQCyNONj9d1iAcqOzoJKAykzQ4tCzU/tMwAqK3i5PRHTWvMEpWOdUU93N1zaAmXz6PGbdYguxY/3Ln24c7ZD3e1P9y52CcVJLTs6KSTG4G8hzsb4kKO7jm0Owuo5nA7UCogv8zq0LZHDXOt/wP5TWsi//@PVrdX18pTSMsvUshTyMxT0DDQUTC01FEwAtImQNoUSFsCaUMDIMMIJGJkCpYCyxloxgIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>“...‘Ḥ‘>@LS‘ị“...‘ŒḄ‘6¦U7¦0ịxɗ€6a"ƊZỌ¤ - Helper: list of characters, X | |
“...‘ - list of numbers = [9,24,49,124,249] | |
Ḥ - double = [18,48,98,248,498] | |
‘ - increment = [19,49,99,249,499] | |
>@L - length of X greater than? (vectorises) | |
S - sum | |
‘ - increment -> our "face index" | |
¤ - nilad followed by link(s) as a nilad: | |
“...‘ - list of lists of numbers | |
...the ordinals of the characters: | |
"\-/", "(", "^o¬ºªx", "-__-@_" | |
ŒḄ - bounce | |
...this appends: | |
"^o¬ºªx", "(", "\-/" | |
‘6¦ - increment the sixth - 2nd "(" -> ")" | |
U7¦ - reverse seventh - 2nd "\-/" -> "/-\" | |
Ɗ - last three links as monad: | |
6 - literal six | |
ɗ€ - for each - f(list, 6): | |
0ị - get the last one | |
x - repeat it six times | |
a" - zip with logical AND | |
...effectively extend the lists to | |
length six using the rightmost | |
ordinal. | |
Z - transpose | |
Ọ - convert the integers to characters | |
...a list of the faces | |
ị - "face index" index into "faces" | |
L⁶;“...»jṭÇ“Pov:¶”; - Main Link: list of characters, X | |
L - length of X | |
⁶; - prefix with a space | |
“...» - compressed list of strings = " you score", " on codegolf" | |
j - join with the score | |
Ç - call the helper link, above with X as the argument -> face | |
ṭ - tack the face to the front | |
“Pov:¶” - "Pov\n" | |
; - concatenate | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Dœs3µZI%⁵z-Ḣ⁼Ṫ | |
</code></pre> | |
<p>A monadic Link accepting a positive integer that yields <code>1</code> if it is Fmbalbuena, or <code>0</code> if not.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/l6ORi40NbozxVHzVurdJ9uGPRo8Y9D3eu@n90z@H2R01r3P//jzY0MLM0tdRRMDQAEkaGYJaxkZGRjoIZGBgYGOgomJubA5mWlmBZIN/IGEgYGxnAFAEBUMbI1ARMg000igUA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong><br /> | |
Or test every positive integer up to and including <span class=""math-container"">\$106959\$</span> <a href=""https://tio.run/##AS4A0f9qZWxsef//RMWTczPCtVpJJeKBtXot4bii4oG84bmq/8OH4oKsVP//MTA2OTU5"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">here</a>.</p> | |
<h3>How?</h3> | |
<pre><code>Dœs3µZI%⁵z-Ḣ⁼Ṫ - Link: positive integer, I | |
D - digits of I | |
3 - literal three | |
œs - split the digits into three equal(ish) parts | |
(if not equally splittable leftmost get longer first) | |
µ - start a new monadic chain with X=that as the argument | |
Ṫ - tail X (gets the digits in the last part and modifies X) | |
Z - transpose the remaining parts | |
I - deltas | |
⁵ - literal ten | |
% - modulo (the deltas) | |
- - literal minus one | |
z - transpose with filler -1 (avoiding false positives like 1009) | |
Ḣ - head | |
⁼ - does that equal the tail we removed? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 15 </s> 14 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ḟ;ċ?”'ḣ2)Ṛ)⁸;Ẏ | |
</code></pre> | |
<p>A monadic Link accepting a list of lists (parts) of lists of characters (moves) which yields a list of lists of characters (moves).</p> | |
<p><strong><a href=""https://tio.run/##AT0Awv9qZWxsef//4bifO8SLP@KAnSfhuKMyKeG5minigbg74bqO/@G7tOG4suKCrMOHS///RicgVTIgUgpEIEIy"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ḟ;ċ?”'ḣ2)Ṛ)⁸;Ẏ - Link: list of lists of moves, A | |
) - for each Part of A: | |
) - for each Move in that part: | |
”' - yield a quote character | |
? - if... | |
ċ - ...condition: count (X' -> 1, X -> 0, X2 -> 0) | |
ḟ - ...then: filter discard (X' -> X) | |
; - ...else: concatenate (X -> X', X2 -> X2') | |
ḣ2 - head to index 2 (X -> X, X'-> X', X2' -> X2) | |
Ṛ - reverse (this Part) | |
⁸ - A | |
; - concatenate (the reversed, altered Part) | |
Ẏ - tighten from a list of four parts to a list of all of the resulting moves | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>ŒJẈṂ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLFkkrhuojhuYIiLCIiLCIiLFsiW1tbMV0sMixbWzMsNF1dXV0iXV0="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>-1 byte thanks to Razetime</p> | |
<pre><code>ŒJẈṂ Main Link | |
ŒJ Get the multidimensional index of each scalar value | |
Ẉ Length of each coordinate = depth of each value | |
Ṃ Minimum | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>1bQ€FQƑʋ1# | |
</code></pre> | |
<p><a href=""https://tio.run/##ZdAxDsIwDADA3a@wxAdqJ06aD7B3QWJFYkH9ACsDHZjgC6xMiKGIjUod@EX7kZC2CNJi2VKUU2wrm3Web72nVdbuLvOsPr4ONPNNeSbXlNfnvS4WAaoCmsetKsJx6T1jipQgGfxGuz@hpPCRODphO4j5E60g3JJFSidCJvkRuVE71iNiikhAaVSCykwaGm1Ao@6yLx1tTgwKVZd9qcGHNWzCICJorUXn3HhHI0BEYSz3b@PfEHkD"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>1bQ€FQƑʋ1# - Main link. Takes a list of integers L on the left | |
ʋ - Group the previous 4 links into a dyad f(k, L): | |
b - Convert k into each base in L | |
Q€ - For each list of digits, remove duplicates | |
F - Flatten | |
QƑ - Are all elements in this list unique? | |
1 1# - Count up from n = 1, 2, ... until the first n is found such that f(n, L) is truthy | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>ṡṀ€Ṃ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzoUPdzY8alrzcGfT/8PLlSL//4821FEw1VEw1lEwidVRAPGMIDygMFQAjsACQMUmECVGxrH/4YqNAQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Since <a href=""https://codegolf.stackexchange.com/a/73187/66833"">Dennis' answer</a>, the <code>Ṁ</code>aximum and <code>Ṃ</code>inimum monadic atoms have been added</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>Ḷ_þ%Ɗ< | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLhuLZfw74lxoo8IiwiIiwiIixbIjUiLCIzIl1d"" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>Ḷṙ`U< | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLhuLbhuZlgVTwiLCIiLCIiLFsiNSIsIjMiXV0="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>-1 byte thanks to Jonathan Allan</p> | |
<pre><code>Ḷṙ`U< Main Link; take n, k | |
Ḷ [0, 1, 2, ..., n - 1] | |
` Apply with ^ on the left and right: | |
ṙ Rotate left; [[0, 1, 2, ..., n - 1], [1, 2, 3, ..., n - 1, 0], [2, 3, 4, ..., n - 1, 0, 1], ...] | |
U Reverse each; [[n - 1, n - 2, ..., 1, 0], [0, n - 1, n - 2, ..., 2, 1], [1, 0, n - 1, ..., 3, 2], ...] | |
< Is this less than k? [[0, ..., 1, 1, 1], [1, 0, ..., 1, 1], ...] | |
^-- k --^ | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>߀Ṣ | |
Ç€E | |
</code></pre> | |
<p>A monadic Link accepting a list of the two ragged lists that yields <code>1</code> if they are "shapeless equal".</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///w/EdNax7uXMR1uB3IcP0Ppv7/j46OjtVRiI6N5dIBM4E4FiQAonVAbIQ4RA4sGauDUABVgWoK3Ax0IZgAWAQsiGQjjA81NxYA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Recursively sort the containers of any nested lists and compare the results for equality.</p> | |
<pre><code>߀Ṣ - Helper Link, recursively sort container lists and their content: List, X | |
€ - for each element in X: | |
ß - call this Link | |
Ṣ - sort | |
Ç€E - Link, the main function: List, A | |
€ - for each of the two lists in A: | |
Ç - call the Helper Link | |
E - all equal? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ċƇf/>Ƈ⁹ȧ | |
çⱮFḟ@Ɱ | |
</code></pre> | |
<p>A monadic Link accepting a list of lists of strictly positive integers that yields a list of lists of strictly positive integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8//9I97H2NH27Y@2PGneeWM51ePmjjevcHu6Y7wCk/x9uf9S05uikhztnAOnI//@jo6MNdYx0TGJ1wLQxkAaRsVw60dHGYGFTHTMIFyYPpsFSEBoiCaGMdAyNwBKGEJMMQdKxAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (The footer calls the Link for each and formats the output)</p> | |
<h3>How?</h3> | |
<pre><code>ċƇf/>Ƈ⁹ȧ - Helper Link: list of lists, A; integer, I | |
Ƈ - filter keep those lists in A for which: | |
ċ - count occurrences of I - truthy if the list contains I | |
/ - reduce this list of lists that contain I by: | |
f - filter keep | |
- gets us a list of those values appearing in all of them | |
⁹ - use I as the right argument of: | |
Ƈ - filter keep those for which: | |
> - greater than I? | |
ȧ - logical AND I (non-vectorising) | |
- i.e. I if it is a consistently dependent smaller integer, else 0 | |
çⱮFḟ@Ɱ - Link: list of lists, A | |
F - flatten A | |
Ɱ - map across each integer I in that with: | |
ç - call the Helper Link as a dyad - f(A, I) | |
Ɱ - map across each list in A with: | |
@ - with swapped arguments: | |
ḟ - filter discard | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>‘DṢƑ$1# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9RwwyXhzsXHZuoYqj8//9/QxNTUwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>‘DṢƑ$1# - Main link. Takes n on the left | |
‘ - Yield n+1 | |
$1# - Starting from n+1, find the first integer after such that: | |
D - The digits are | |
Ƒ - Invariant under | |
Ṣ - Sorting | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 7 </s> 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>¬ß€»LṀ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///QmsPzHzWtObTb5@HOhv@H24Hs//@jo2O5dIAEiDTUMdIxBnMhLJhYdKyOIYQNQhYgEaBwrI6pjomOZWwsRAVQYywA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>A monadic Link accepting a list containing any strictly positive integers or nested, similar, lists that yields the maximal length list.</p> | |
<h3>How?</h3> | |
<pre><code>¬ß€»LṀ - Link, call this "f": list, A | |
¬ - logical NOT (vectorises) - convert all positive integers to zeros so that | |
we wont implicitly treat them as ranges | |
€ - for each element, E, in A (...if the current A isn't now a zero): | |
ß - call this Link (i.e. f(A=E)) | |
L - length of A - Note that zero has length one. | |
» - maximum (vectorises) | |
Ṁ - maximum (of the resulting list) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 27 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>;©U;þ®ẎḢ⁼ṪƊƇƊLСŒṬ€ĖP€o/SİM | |
</code></pre> | |
<p>A monadic Link accepting the adjacency list specified that yields a list of all of the Kevin Bacons of that graph.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/60MpQ68P7Dq17uKvv4Y5Fjxr3PNy56ljXsfZjXT6HJxxaeHTSw51rHjWtOTItAEjm6wcf2eD7////aA1DHQUjTR0FDSMdBWMQbayjYAKiTXQUDKHippqxAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<p>How?</p> | |
<p>We first produce lists of all pairs of nodes linked by <code>1, 2, 3, ...</code> steps (up to <code>2p+1</code> where <code>p</code> is the number of pairs in the input, just for golfing purposes) - including redundancies and self-linked pairs.</p> | |
<p>Then we turn each of these into tables showing the number of steps taken, if possible, or zero if not - i.e. the first is <code>0</code> or <code>1</code> at each point, the second is <code>0</code> or <code>2</code> at each point, and so on.</p> | |
<p>We then reduce these by logical OR, giving us the shortest length table shown in the question with a leading diagonal filled with <code>2</code>s (since we are guaranteed a fully-connected graph, we will always produce a <code>2</code> at this position in the second previous table by following a given pair and its reverse, and the logical OR will keep this value if we could do the same in more steps).</p> | |
<p>Then we sum the columns, inverse and find maximal indices (aligning with the guaranteed <code>[1,n]</code> node numbering).</p> | |
<pre><code>;©U;þ®ẎḢ⁼ṪƊƇƊLСŒṬ€ĖP€o/SİM - Link: adjacency list, A | |
U - reverse each pair in A | |
; - concatenate that to A | |
© - copy this to the register for later | |
С - collect up and repeat: | |
L - ...times: length (of the new list) | |
Ɗ - ...what: the last three links as a monad, f(current): | |
® - use the register as the right argument of: | |
þ - (current) table (register) using: | |
; - concatenation (e.g. [2,5];[1,2] -> [2,5,1,2]) | |
Ẏ - tighten (from a table to a row-major order list) | |
Ƈ - filter keep those for which: | |
Ɗ - last three links as a monad: | |
Ḣ - pop and yield head | |
Ṫ - pop and yield tail | |
⁼ - equal? (leaving the inner two | |
e.g. [2,5,1,2] -> [5,1] | |
which is kept since 2=2) | |
€ - for each: | |
ŒṬ - make a table with 1s at the given coordinates) | |
Ė - enumerate -> [[1,first],[2,second],...] | |
P€ - product of each | |
o/ - reduce by logical OR | |
S - sum columns | |
İ - inverse | |
M - maximal indices (1-indexed) | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>1IS;ƊÄ$¡IIS+¬ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/QM9j6WNfhFpVDCz09g7UPrfn//7@RJQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>1IS;ƊÄ$¡IIS+¬ | |
1 $¡ Starting from [1], iterate an operation n times: | |
IS Sum the increments (i.e. last minus first), | |
;Ɗ prepend this to the array, | |
Ä and take the cumulative sum. | |
e.g. [a,b,c,d] → [d-a, d, d+b, d+b+c, d+b+c+d] | |
IIS Increments, increments, sum. | |
+¬ This erroneously gives a(0)=0, so add 1 if n=0. | |
</code></pre> | |
<p>This is a port of the Maple code contributed to the OEIS page by Peter Luschny. As far as I understand, it's similar to Neil's answer, but modifies Aitken's array to get the result directly.</p> | |
" | |
"9288","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 2 bytes</h1> | |
<pre><code>ÆẸ | |
</code></pre> | |
<p>Decoder:</p> | |
<pre><code>ÆE | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9w28NdO/4fblc43Oaq8Khxj@b//9GGsTrRhgYgQscISBrpgAUgJJQJYUMljHSMdUx0THXMdMx1LHQsdcB6LY11jCx1TMx1wLSFiY6hpY65QSwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A built-in.</p> | |
<blockquote> | |
<p><code>ÆE</code>: Compute the array of exponents of z's prime factorization. Includes zero exponents.</p> | |
<p><code>ÆẸ</code>: Inverse of <code>ÆE</code>.</p> | |
</blockquote> | |
<p>In other words, <code>ÆẸ</code> maps <span class=""math-container"">\$[a,b,c,d,\dots]\$</span> to <span class=""math-container"">\$2^a 3^b 5^c 7^d \cdots\$</span>.</p> | |
<p>This trick is also used in the <a href=""https://en.wikipedia.org/wiki/G%C3%B6del_numbering#G%C3%B6del%27s_encoding"" rel=""nofollow noreferrer"">Gödel numbering</a>.</p> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>4</s> 2 bytes</h1> | |
<p>-2 bytes from <a href=""https://codegolf.stackexchange.com/a/240598/64121"">xnor's answer</a></p> | |
<pre><code>+Ṁ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/1/74c6G/4fbFYCUx8NdC491KTxq3KP5/3@0YaxOtKEBiNAxApJGOmABCAllQthQCSMdYx0THVMdMx1zHQsdSx2wXktjHSNLHRNzHTBtYaJjaKljbhALAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>+Ṁ -- Encoder | |
+Ṁ -- Add the Ṁaximum to each value | |
ṀHạ -- Decoder | |
ṀH -- Halve of the Ṁaximum | |
ạ -- ạbsolute difference between this and each value | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ŒJ§ḂṬƙFṀḊ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///oJK9Dyx/uaHq4c82xmW4PdzY83NH1/3D70UkPd87QjPz/P5orOtpIR8EAhhDsWB0uhWgDJCmIrCGQBEsZYYoj6TJCEoeqQTIQoR5JF0QlOgnTZYhkHVQWSZcBmmwsUA7oM0znYzoERRbD@Qg1qJ42xPA0ssMRamC6sHgOI4AxPY2JDKE@MwLbjI5gtuGSwmqkAW2kDMFeQUf4pGgaZ4bYEip944xynxnhTo0GA5wa0WyjXbqilxRyPjNE89yQ91ksAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input as an <span class=""math-container"">\$8 \times 8\$</span> matrix, with <code>0</code> being empty space, <code>1</code> being white and <code>2</code> being black. Outputs an empty list <code>[]</code> for truthy, and a non-empty list <code>[1]</code> for falsey.</p> | |
<p>Additionally, if we <em>really</em> want to stretch the output format, we can have this 8 byter</p> | |
<pre><code>ŒJ§ḂṬƙFṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///oJK9Dyx/uaHq4c82xmW4Pdzb8P9x@dNLDnTM0I///j@aKjjbSUTCAIQQ7VodLIdoASQoiawgkwVJGmOJIuoyQxKFqkAxEqEfSBVGJTsJ0GSJZB5VF0mWAJhsLlAP6DNP5mA5BkcVwPkINqqcNMTyN7HCEGpguLJ7DCGBMT2MiQ6jPjMA2oyOYbbiksBppQBspQ7BX0BE@KZrGmSG2hErfOKPcZ0a4U6PBAKdGNNtol67oJYWczwzRPDfkfRYLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>which outputs <code>[1]</code> for truthy, and <code>[1, 1]</code> for falsey.</p> | |
<h2>How it works</h2> | |
<pre><code>ŒJ§ḂṬƙFṀḊ - Main link. Takes a matrix M on the left | |
ŒJ - 8x8 grid of coordinates [x, y] between 1 and 8 | |
§ - Sum of each coordinate | |
Ḃ - Bit | |
F - Flatten M | |
ƙ - Over the lists formed by grouping the flattened M by the bit of the coordinate: | |
Ṭ - Yield a boolean list, with 1s at the indices in the list | |
Ṁ - Maximum | |
Ḋ - Dequeue, remove the first element | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>12</s> 11 bytes</h1> | |
<pre><code>ŒḊ€aJŒg⁸ṁF€ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIc7uh41rUn0Ojop/eHORodDW92A3P@H24EyO2f8/x9trqMQbaqjYByro2AEZBqCKRDPUkfBQkfBHEwC2dHGOgomsSAVIMIoNhYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ŒḊ€ Depth of each (1 for lists, 0 for numbers) | |
aJ Replace each 1 with its index [0 0 1 0 1 1] -> [0 0 3 0 5 6] | |
Œg Group runs of equal elements [[0 0] [3] [0] [5] [6]] | |
⁸ṁ Reshape the original input to this list | |
F€ Flatten each element (turns entries like [[1 2]] back into [1 2]) | |
</code></pre> | |
<p>This approach feels elegant in theory, but a lot of bytes are wasted on <code>€@µ€</code>, so there might be saves.</p> | |
<p>Jonathan Allan saved a byte! Thanks.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Really not sure if this is optimal, it's just the first way I though of...</p> | |
<pre><code>,⁻;ɗƝŻœṗ⁸F€ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##XVC7DcIwEO0zxQ1wjZ3EcUTPDujkkgZlAcrQ0EMRGjZgAKKUyEiMkSxizmcLoTS238/v7MO@644h4NJPm8/wvvvJX@dxWPrndjk9wuvMq7/M4433XQhUELUIFYJ2DgsyCKQQIiW4YVwjlC4aGLOmGUqizgRpESNLVQxmiZT7d7NqmGhWEok/79LB5ZZ9CCaVV7kfQUnWprpWYrHfpFKSmdZTpwfphH5XWzlTmZNxHJIfcF8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>,⁻;ɗƝŻœṗ⁸F€ - Link: list, A | |
Ɲ - for each of the neighbours: | |
ɗ - last three links as a dyad, f(left, right): | |
, - pair them (e.g. [1,2] and 3 -> [[1,2],3]]) | |
; - concatenate them (e.g. [1,2] and 3 -> [1,2,3]) | |
⁻ - are these not equal? (i.e. was either left or right a list?) | |
Ż - prefix a zero | |
⁸ - use A as the right argument of... | |
œṗ - partition right at truthy indices of left | |
F€ - flatten each | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>e€Øcn\<$a32^OỌ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/1UdOawzOS82JsVBKNjeL8H@7u@f//f0lGqkJhaWZytkJSUX55nkJafoVCVmluQbFCfllqkQJIOiexqlIhJT8dAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>e€Øc For each input character: is it in Øc (vowels)? | |
This gets a mask with 1s where vowels are, e.g. | |
“b x d e f h i z k o m u p” | |
0 0 0 1 0 0 1 0 0 1 0 1 0 | |
n\<$ scanl(≠, mask) < mask: This selects every other 1. | |
scanl(≠): 0 0 0 1 1 1 0 0 0 1 1 0 0 | |
original: 0 0 0 1 0 0 1 0 0 1 0 1 0 | |
<: 0 0 0 0 0 0 1 0 0 0 0 1 0 | |
a32 Replace all 1s by 32. | |
^O XOR by ord(input string). | |
Ọ chr() | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>e€ØẹTḊm2 | |
Œuç¦ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJl4oKsw5jhurlU4biKbTJcbsWSdcOnwqYiLCIiLCIiLFsidGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZ3MiXV0="" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>e€ØẹTḊm2 Helper Link; get every other vowel | |
e€ For each element, is it in | |
Øẹ the list of vowels ("aeiou")? | |
T Get said indices | |
Ḋm2 Pop off the first one and take every other one | |
Œuç¦ Main Link | |
¦ Apply | |
Œu to-uppercase | |
ç to every other vowel | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>+ċṪ$Ƥ | |
</code></pre> | |
<p>A monadic Link accepting a sorted list of integers that yields a list of integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/1/7SPfDnatUji35//9/tK6pjgIKNtFRQEaWQBQLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>+ċṪ$Ƥ - Link: list of integers, A | |
Ƥ - for prefixes of A: | |
$ - last two links as a monad, f(prefix): | |
Ṫ - pop off the tail from the prefix | |
ċ - count occurrences of that in the remaining prefix | |
+ - A add that (vectorises) | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>ŒɠḶF+ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opJMLHu7Y5qb9/3D70UkPd87QjPz/P5or2lBHwUhHwThWB8yE8EACUDEDHQUEQigyNIBhdAKkRtdURwEFm@goICNLIEIyC25tLFcsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>ŒɠḶF+ - Main link. Takes a list L on the left | |
Œɠ - Group run lengths | |
Ḷ - Zero based range | |
F - Flatten | |
+ - Add elementwise to L | |
</code></pre> | |
<p>For example, take <code>L = [1, 1, 2, 2, 3, 3]</code>:</p> | |
<ul> | |
<li><code>Œɠ</code>: <code>[2, 2, 2]</code></li> | |
<li><code>Ḷ</code>: <code>[[0, 1], [0, 1], [0, 1]]</code></li> | |
<li><code>F</code>: <code>[0, 1, 0, 1, 0, 1]</code></li> | |
<li><code>+</code>: <code>[0, 1, 0, 1, 0, 1] + [1, 1, 2, 2, 3, 3] = [1, 2, 2, 3, 3, 4]</code></li> | |
</ul> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ĠEÞZFị | |
</code></pre> | |
<p>A monadic Link accepting and returning a list of positive integers as specified.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///IAtfD86LcHu7u/n90z@H2R01rjk56uHMGkAaiLBDVMEdB107hUcPcyP//o6MNY3UUoi10FMxBtKGOAhAZITF1FIyBCCRgDBOwAIsZGgBZsbEA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Produces a list of the form <code>a+b+a</code> where <code>a</code> is a list of the elements that are present twice and <code>b</code> is a list of the elements that only appear once. (<code>a</code> and <code>b</code> are also each sorted by value as a side effect of the method employed.)</p> | |
<pre><code>ĠEÞZFị - Link: list of integers with at most two of each, A | |
e.g. [3, 3, 1, 1, 2] | |
Ġ - group indices of A by their values [[3, 4], [5], [1, 2]] | |
Þ - sort the result using: v v v | |
E - all equal? 0 1 0 | |
-> [[3, 4], [1, 2], [5]] | |
Z - transpose [[3, 1, 5], [4, 2]] | |
F - flatten [3, 1, 5, 4, 2] | |
ị - index back into A [1, 3, 2, 1, 3] | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<p>A port of <a href=""https://codegolf.stackexchange.com/a/240372/64121"">tsh's Python answer</a>.</p> | |
<pre><code>Qċ@Þ¹Uṁ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/wSLfD4XmHdoY@3Nn4/3D7o6Y17v//RxvG6ihEW@gomINoQx0FIDJCYuooGAMRSMAYJmABFjM0ALJQFELV6iiYAFEsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Q -- the unique elements of the list | |
Þ -- sort by ... | |
ċ@ ¹ -- the number of occurences in the full list | |
U -- reverse | |
ṁ -- mold; reshape the list to the length of input by reusing from the front | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ẹⱮ_"JỤị | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hrp2PNq6LV/J6uHvJw93d/w@3P2pa4/7/f7RhrI5CtIWOgjmINtRRACIjJKaOgjEQgQSMYQIWYDFDAyALRSFUrY6CCRDFAgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h3>How it works</h3> | |
<pre><code>ẹⱮ_"JỤị Monadic link. Input: X, a numeric vector | |
ẹⱮ For each element n of X, get all indices of n in X | |
_"J For each list of indices, subtract the original index | |
If n appears twice, the first becomes [0, positive], | |
and the second becomes [negative, 0]. | |
If n appears only once, it becomes [0]. | |
Ụị Sort X by the above | |
All [negative, 0]s come first, then [0]s, then [0, positive]s | |
</code></pre> | |
<p>I really hope Jelly were a proper derivative of J/K, in which case we wouldn't need the <code>"</code>.</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>Œ!ĠISƊÐṀ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLFkiHEoElTxorDkOG5gCIsIiIsIiIsWyIxLCAxLCAyLCAyLCAzLCAzIl1d"" rel=""noreferrer"">Try It Online!</a></p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>JŒPḊX,Ẋ$yJị | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJKxZJQ4biKWCzhuookeUrhu4siLCIiLCIiLFsiNSwxLDIsNyw0Il1d"" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>JŒPḊX,Ẋ$yJị Main Link | |
J Get the list of indices [1, 2, ..., n] | |
ŒP Powerset - all possible subsets | |
Ḋ Remove the empty one | |
X Select a random one | |
,Ẋ$ Pair that with a random permutation of itself | |
yJ Translate the original indices according to that mapping | |
ị Index back into the original list | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>JÄ‘œṖ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/rcMujhhlHJz/cOe3/4fajkx7unPH/f7ShgYGOghGIMAYRJiDC1MAgFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>JÄ‘œṖ - Link: list, L e.g. [5,4,3,2,1,0,1,2] | |
J - range of length of L [1,2,3,4,5,6,7,8] | |
Ä - cumulative sums [1,3,6,10,15,21,28,36] | |
‘ - increment [2,4,7,11,16,22,29,37] | |
œṖ - partition L before those indices [[5],[4,3],[2,1,0],[1,2]] | |
</code></pre> | |
<hr /> | |
<p>Also 5 bytes <a href=""https://tio.run/##y0rNyan8/9@rIuHQzmMz/x9uPzrp4c4Z//9HGxoY6CgYgQhjEGECIkwNDGIB"" rel=""nofollow noreferrer"">TIO</a>:</p> | |
<pre><code>Jx`¹ƙ | |
</code></pre> | |
<p>...(<code>J</code>) range of length, (<code>`</code>) use right as both arguments with (<code>x</code>) repeat elements then (<code>ƙ</code>) apply to groups of identical values (<code>¹</code>) a no-op function.<br /> | |
i.e. build a list like <code>[1,2,2,3,3,3,4,4,4,4,...]</code> and group the original values like its equal values, <code>[[1],[2,2],[3,3,3],[4,4,4,4],...]</code>.</p> | |
<p>or, equivalently (just reapplying <code>J</code> rather than using the quick <code>`</code>):</p> | |
<pre><code>JxJ¹ƙ | |
</code></pre> | |
" | |
"95126","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ỤỤịUỤ$ị | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///h7iVg1B0KpFSA9P///6MtdBSMdRQMdRQsYCSIawCmLCAsi1gA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/240053/95126"">my R answer</a>.</p> | |
<p>Pseudocode: | |
<code>x [ order of reverse of x ] [ order of order of x ]</code></p> | |
<p><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a> explanation:</p> | |
<pre><code>ỤỤ # get the order of the order of the input; | |
ị # use this to index into... | |
$ # (previous two links together) | |
U # ...reverse of | |
Ụ # ...order of the input; | |
ị # finally use this to index into the input | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>P+€TọµẠƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASYA2f9qZWxsef//UCvigqxU4buNwrXhuqDGh/9bMSwyLDMsNCw1XcOH/w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Outputs an empty list for falsy.</p> | |
<pre><code>P Product | |
+€ Foreach, added to | |
T 0...input length | |
ọ Number of times each divides each - 0 for falsy | |
µẠƇ Filter by all truthy | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 25 bytes</h1> | |
<pre><code>ḶJX,XƊṬ×ịÆm¥oʋƊ⁹¡µṂ;Ṁ;Æm, | |
</code></pre> | |
<p><a href=""https://tio.run/##ATwAw/9qZWxsef//4bi2SlgsWMaK4bmsw5fhu4vDhm3CpW/Ki8aK4oG5wqHCteG5gjvhuYA7w4ZtLP///zEw/zU"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Outputs <code>[[min, max, mean], list]</code>. Takes <code>length</code> as the first argument, and <code>generation</code> as the second</p> | |
<h2>How it works</h2> | |
<pre><code>ḶJX,XƊṬ×ịÆm¥oʋƊ⁹¡µṂ;Ṁ;Æm, - Main link. Takes L on the left, G on the right | |
Ḷ - [0, 1, ..., L-1] | |
Ɗ - Previous 3 links as a monad f(R): | |
J - Indices of R | |
Ɗ - To the indices of R: | |
X - Randomly choose one | |
X - Randomly choose one again | |
, - Pair; [i, j] | |
ʋ - Last 4 links as a dyad g([i, j], R): | |
Ṭ - Boolean array with 1s at i and j | |
¥ - Last 2 links as a dyad h([i, j], R): | |
ị - Get R[i] and R[j] | |
Æm - Take the mean | |
× - Replace the 1s with the mean | |
o - Or; replace the elements at i and j in R with the mean | |
⁹¡ - Apply f(R) G times | |
µ - Use this list L' as the new argument | |
Ṃ - Minimum | |
Ṁ - Maximum | |
Æm - Mean | |
; ; - [Min, Max, Mean] | |
, - Pair with L' | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ĠUFỤịỤịU | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///IglC3h7uXPNzdDSFD////H22ho2Cso2Coo2ABI0FcAzBlAWFZxAIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of Jonah's J answer:</p> | |
<pre><code>Ġ Group indices | |
U Reverse each group | |
F Flatten | |
Ụ Grade up | |
ịỤ Index into graded-up original list | |
ịU Index into reversed list | |
e.g. input: “XYXZYY” (needn't be integers!) | |
Ġ: [[1,3],[2,5,6],[4]] | |
U: [[3,1],[6,5,2],[4]] | |
F: [ 3,1, 6,5,2, 4 ] | |
Ụ: [2,5,1,6,4,3] | |
This is a "rank" of the input, breaking ties backwards: | |
X Y X Z Y Y | |
2 1 rank Xs backwards | |
5 4 3 rank Ys backwards | |
6 rank Zs backwards | |
→ [2,5,1,6,4,3]. | |
Meanwhile, Ụ is [1,3,2,5,6,4] (equiv. to ĠF), | |
indices that sort the input: | |
[X,Y,X,Z,Y,Y] | |
[1, 3, indices of Xs | |
2, 5,6, indices of Ys | |
4] indices of Zs | |
Now ịỤ permutes one list by the other, | |
mapping each element to its twin's index: | |
ịỤ: [3,6,1,4,5,2] | |
X Y X Z Y Y | |
3 1 Twin indices of Xs | |
6 5 2 Twin indices of Ys | |
4 Twin indices of Zs | |
And we only have to index into the backwards input: | |
ịU: “ZXYXYY” | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>ĠżṚ$€ẎḢÞịṚ | |
</code></pre> | |
<p>A full program that accepts the list and prints the result.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///IgqN7Hu6cpfKoac3DXX0Pdyw6PO/h7m6gyP///6MNdRSMdBSMdRRMwAxDMNsoFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ĠżṚ$€ẎḢÞịṚ - Main Link: list, A | |
Ġ - group indices by their element's values | |
$€ - for each: | |
Ṛ - reverse that list of indices having equal values | |
ż - zip the two together | |
Ẏ - tighten (to a list of [index, twin index] pairs) | |
Þ - sort by: | |
Ḣ - pop head from the pair being inspected | |
Ṛ - reverse A | |
ị - use the (remaining) twin indices to index into the reversed copy of A | |
- implicit, smashing print | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ĠUF,ỤyJịU | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLEoFVGLOG7pHlK4buLVSIsIiIsIiIsWyJbOCwgMywgMSwgOCwgMSwgOCwgMywgMTAsIDMsIDgsIDEwLCA4XSJdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<pre><code>ĠUF,ỤyJịU Main Link | |
Ġ Group indices by equal elements | |
U Reverse each block | |
F Flatten | |
,Ụ Pair with the grade of the original list | |
yJ Apply this as a translation to the indices of the list | |
ịU Index that into the reverse of the original list | |
</code></pre> | |
<p>-1 byte thanks to Lynn with the grading up trick. Grading up a list sorts the indices by their corresponding values.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>ạJĠị | |
</code></pre> | |
<p>A monadic Link that accepts the list of integers and yields a list of lists of integers.</p> | |
<p>Does not perform the optional empty list insertions.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hroVeRxY83N39////aFMdBTMdBQsdBWMdBUsdBRMdBSMdBUMdBfNYAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Pretty simple for Jelly this one...</p> | |
<pre><code>ạJĠị - Link: list of integers, A | |
J - range of length of A -> [1,2,...,length(A)] | |
ạ - A absolute difference that (vectorises) | |
Ġ - group indices of that by their values | |
ị - use those to index back into A | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>ŒṗB§Ṣ⁼JƲ€S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIc7pzsdWv5w56JHjXu8jm161LQm@P/D3VsObX24Y9PDHYvCdA63q2i6//9vqKBgyGUEIowVFAy4TBQUjLhMQVxDAyDL0ETBjMvQUsGcy8hAwdCAy8hUwdCEy9hYwdiIy8RQwcScy8REwdSUy9RAwcIEAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Brute force approach, we generate all partitions then count those that satisfy <span class=""math-container"">\$\operatorname{bitsum}(a_j) = j\$</span>. Times out for the <span class=""math-container"">\$n = 59\$</span> test case on TIO, and can handle a test suite going up to the <span class=""math-container"">\$n = 50\$</span> test cases</p> | |
<h2>How it works</h2> | |
<pre><code>ŒṗB§Ṣ⁼JƲ€S - Main link. Takes n on the left | |
Œṗ - Integer partitions of n | |
B - Convert everything to binary | |
Ʋ€S - Count for how many the following is true: | |
§ - Sum of bits for each | |
Ṣ - Sorted | |
⁼J - Is equal to [1, 2, ..., n] for some n? | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ØaiⱮb‘ịØB | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLDmGFp4rGuYuKAmOG7i8OYQiIsIiIsIiIsWyJ1bmNvcHlyaWdodGFibGUiLCIzNiJdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>-1 byte thanks to caird coinheringaahing</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ODFBḌS | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJPREZC4biMUyIsIsOH4oKsIiwiIixbIlwiSGVsbG8gV29ybGQhXCIsIFwiRm9vIEJhciFcIiwgXCJDb2RlIEdvbGZcIiwgXCJTdGFjayBFeGNoYW5nZVwiLCBcIldpbnRlciBCYXNoXCIiXV0="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>Literally just ord → to digits → flatten → to binary → from decimal → sum</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>W{Ɱṭ/ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z@8@tHGdQ93rtX/f3i5g/7RSQ93ztCM/P8/2lDHIFYn2ghMGoNJEzBpCibNgCQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Value on left, <span class=""math-container"">\$n\$</span> on right</p> | |
<pre><code>W The value wrapped in a singleton list | |
{Ɱ for each 1..n. | |
ṭ/ Reduce by Funky Reverse Append™. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>17</s> 16 bytes</h1> | |
<pre><code>»×¥@\Ṛ$⁺ | |
Ç€»ÇF1e | |
</code></pre> | |
<p><a href=""https://tio.run/##NY4xDsIwDEV3H6NmrCzKCTox5QisHUAdWdgKSwZGBiRUJsTWkSKVbok4SHKRYLvUiuP/X2Inu6quDym50V/ds9yE4baIxw94G08dQ7suqrSPTevesbl/L2F4qFHr@jC@tiXflNW0BhmG8bzKl3nhresZp5RlGRgAQ0BaOIAIxXMYpkIApzNNdhLECThTmIA0ogDRANxJ0ooq5A3SqsPmDf9KhgH/5wc"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>Fixed by borrowing back from hyper-neutrino lmao</em></p> | |
<p><em>-1 replacing the double transpose with a map by replacing the map with implicit vectorization</em></p> | |
<p>Takes a matrix of 0 for <code>#</code>, 1 for <code>.</code>, and 2 for <code>L</code>.</p> | |
<pre><code>»×¥@\Ṛ$⁺ Monadic helper link: light up all columns or a row | |
\ Scan by | |
» @ (vectorizing) max of right and | |
×¥ (vectorizing) product, | |
Ṛ then reverse. | |
$⁺ Do it again. | |
Ç€»ÇF1e Monadic main link: is there anything unlit? | |
Ç Light up | |
€ each row, | |
Ç light up the columns, | |
» and take the maximum at each position. | |
F Flatten the result. | |
1e Does it contain 1? | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 19 bytes</h1> | |
<pre><code>,Z»×¥@\Ṛ$2¡€Z»¥/F’Ạ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCIsWsK7w5fCpUBcXOG5miQywqHigqxawrvCpS9G4oCZ4bqgIiwidOKAnMK24oCdxZPhuaPigJzCtsK24oCdwrXhu7RpQOKCrOKCrOKAnC5M4oCdw4fCteKCrCIsIiIsWyJcIlwiXCJcbkxcblxuTC5cbi5MXG5cbkwuLi4uXG4uLiNMLlxuLi4uLkxcbi5MLi4uXG5cbiNcblxuTC4uLkwuLi5MXG5cbiMjIyMjLiMjI1xuI0wuLi5MLi4uXG4jIy4jIyMjTC5cbiMuTC4uIyMjI1xuXG4uXG5cbi4jXG5cbkwjLlxuXG4uIy5cbi5MLlxuLiMuXG5cbkwuLi5cbkwuLi5cbkwuIy5cbkwuLi5cblwiXCJcIiJdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>"Borrowing" the multiplication idea from Unrelated String (i.e. stealing lol). 0 for <code>#</code>, 1 for <code>.</code>, 2 for <code>L</code>.</p> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ÆfŒpQƑƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wW9rRSQWBxyYea/8fbWSiY2SqY2SmY2SuY2QRe7j9PwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Are brownie points redeemable for actual brownies? Similar to ovs' answer and my Vyxal answer.</p> | |
<p>Returns a bunch of duplicates because Jelly has no 'distinct prime factors' builtin.</p> | |
<pre><code>Æf Prime factors | |
Œp Cartesian product of all | |
Ƈ Filter by | |
Ƒ Remains same under | |
Q Uniquify | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>ṁƤinL | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzsZjSzLzfP4/3L3l0NbD7UcnPdw5QzPy///EpOSUVCDBlZiUmJyYlJoMAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>ṁƤinL - Main link. Takes a string S on the left | |
Ƥ - Over each prefix P of S: | |
ṁ - Mold to length S | |
i - First index of S | |
L - Length of S | |
n - Are these two unequal? | |
</code></pre> | |
<p>Essentially, the index and length will only be equal if the only reshaped prefix equal to S is the full prefix i.e. a non-proper prefix</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>‘²RÆṪċ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLigJjCslLDhuG5qsSLIiwiMTAgw4figqwiLCIiLFtdXQ=="" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>‘²RÆṪċ Main Link | |
‘ x + 1 | |
² (x + 1) ^ 2 | |
R range | |
ÆṪ totient | |
ċ count how many times x shows up | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŒḄV©ẒƊ#® | |
</code></pre> | |
<p><a href=""https://tio.run/##ARsA5P9qZWxsef//xZLhuIRWwqnhupLGiiPCrv///zE"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>By <a href=""https://codegolf.stackexchange.com/tags/sequence/info"">default sequence I/O rules</a>, this inputs a value <code>k</code> and outputs the prime corresponding to <code>k</code>.</p> | |
<p>This is a monadic link <code>f(k)</code> that returns the prime. It also outputs the <code>n</code> value for that prime as a side effect - this should be considered a function that returns the prime. I've included a 9 byte version that doesn't output anything extra below.</p> | |
<pre><code>ŒḄV©ẒƊ#ṛ® | |
</code></pre> | |
<p><a href=""https://tio.run/##AR0A4v9qZWxsef//xZLhuIRWwqnhupLGiiPhuZvCrv//MQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<hr /> | |
<p>Both can handle <span class=""math-container"">\$k = 1\$</span> on TIO, can't handle <span class=""math-container"">\$k = 2\$</span> or above.</p> | |
<h2>How they work</h2> | |
<pre><code>ŒḄV©ẒƊ#® - Main link. Takes k on the left | |
Ɗ# - Find the first n such that the following is true: | |
ŒḄ - Bounced range of n; [1, 2, ..., n, ..., 2, 1] | |
V - Evaluated as an integer: 12...n...21 | |
© - Save this in the register | |
Ẓ - Is this prime? | |
® - Print n and return the register | |
</code></pre> | |
<p>The second uses <code>ṛ®</code> instead of <code>®</code>. The <code>ṛ</code> causes the program to discard the value of <code>n</code> rather than printing it, and then <code>®</code> returns the register.</p> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 27 bytes</h1> | |
<pre><code>JŻḂ+ż⁸Fð"2,4^'/ị“+ - | +”Y | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/r6O6HO5q0j@551LjD7fAGJSMdkzh1/Ye7ux81zNFW0FWoUVDQftQwN/L////R0QY6hjpAHKsDZhnGxgIA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input like <code>[[0,1,0,1],[0,1,1]]</code>.</p> | |
<pre><code>Helper function: left input is a bit array, right input is a number | |
JŻḂ Alternate [0,1,0,1,…] one longer than the bit array | |
+ Add n | |
ż⁸F Interleave with the array: [n, a0, n+1, a1, n, a2, n+1] | |
Main function: input is two bit arrays [A, B] | |
ð"2,4 [helper(A, 2), helper(B, 4)] | |
^'/ Make a XOR table | |
ị“+ - | +”Y Index into “+ - | +” and join by newlines. | |
</code></pre> | |
<p>For example, for the input <code>[[0,1,0,1],[0,1,1]]</code> this computes</p> | |
<pre> | |
^ │ 2 <b>0</b> 3 <b>1</b> 2 <b>0</b> 3 <b>1</b> 2 | |
──┼─────────────────── | |
4 │ 6 4 7 5 6 4 7 5 6 | |
<b>0</b> │ 2 0 3 1 2 0 3 1 2 | |
5 │ 7 5 6 4 7 5 6 4 7 | |
<b>1</b> │ 3 1 2 0 3 1 2 0 3 | |
4 │ 6 4 7 5 6 4 7 5 6 | |
<b>1</b> │ 3 1 2 0 3 1 2 0 3 | |
5 │ 7 5 6 4 7 5 6 4 7 | |
</pre> | |
<p>And then translates {0, 1} → <code>+</code>, 3 → <code>-</code>, 5 → <code>|</code>, and everything else to spaces.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>³3,5ḍḄ⁼ʋ#Ṫ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///QZmMd04c7eh/uaHnUuOdUt/LDnav@/zdQ0LVT8CvNTUot4jIEsZ1Kq6q4jEAst0wgyxjGAon/N/hvCgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>This uses <code>0 = Number</code>, <code>1 = Buzz</code>, <code>2 = Fizz</code> and <code>3 = FizzBuzz</code></p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>1g15=ɗ#Ṫ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/98w3dDU9uR05Yc7V/0H8v6bAgA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Thanks to <a href=""https://codegolf.stackexchange.com/users/3852/lynn"">Lynn</a>. This uses <code>1 = Number</code>, <code>3 = Fizz</code>, <code>5 = Buzz</code>, <code>15 = FizzBuzz</code>. Included separately as the numbers could encode extra data</p> | |
<h2>How they work</h2> | |
<pre><code>³3,5ḍḄ⁼ʋ#Ṫ - Main link. Takes W=0,1,2,3 on the left, n on the right | |
ʋ - Last 4 links as a dyad f(k, W): | |
3,5ḍ - Divisible by 3 or 5? Yields [0,0], [0,1], [1,0], [1,1] | |
Ḅ - From binary; Yields 0, 1, 2, 3 | |
⁼ - Equals W? | |
³ #Ṫ - Starting from W, count up k = W, W+1, ..., returning the nth integer such that f(k, W) is true | |
</code></pre> | |
<p> | |
<pre><code>1g15=ɗ#Ṫ - Main link. Takes W=1,3,5,15 on the left, n on the right | |
ɗ - Last 3 links as a dyad f(k, W): | |
g15 - GCD(k, 15) | |
= - Does that equal W? | |
1 #Ṫ - Count up k = 1, 2, ..., returning the nth integer such that f(k, W) is true | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>18⁵rṖp8ḅ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/Q4lHj1qKHO6cVWDzc0fr/PwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>18 18 | |
⁵r Range from ⁵=10: [10..18] | |
Ṗ Remove last element: [10..17] ([a..h]) | |
p8 Cartesian product with [1..8] | |
ḅ Convert from base 18 | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>æḟ⁵ạƊƬINÄ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASsA1P9qZWxsef//w6bhuJ/igbXhuqHGisasSU7DhP///zg0OTU4MzIwNTczNDkz"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>9 bytes sure seems to be special here.</p> | |
<pre><code> Ƭ Collect results while unique from repeating: | |
ạ absolute difference from | |
æḟ⁵ greatest less than or equal power of 10. | |
Ä Take the cumulative sum of | |
IN each amount by which it decreased. | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ọ⁵⁵*ạoµƬU | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///h7t5HjVuBSOvhroX5h7YeWxP6//9/CxNLUwtjIwNTc2MTS2MA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Conceived of independently from, but very similar to, Arnauld's solution.</p> | |
<pre><code> µƬ Collect results while unique from repeating: | |
ọ⁵ How many times does 10 evenly divide it? | |
⁵* Raise 10 to that power, | |
ạ take the absolute difference, | |
o and keep the previous value (ending the loop) if it's 0. | |
U Reverse. | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>DLḶU⁵*xDÄ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/F5@GObaGPGrdqVbgcbvn//7@FiaWphbGRgam5sYmlMQA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>DL Digits, length | |
ḶU⁵* Compute [10^(n-1), …, 10, 1] | |
xD Use the digits as repeat counts for this array | |
e.g. 423 -> [100, 100, 100, 100, 10, 10, 1, 1, 1] | |
Ä Cumulative sum: [100, 200, 300, 400, 410, 420, 421, 422, 423] | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 23 bytes</h1> | |
<pre><code>,UV€€Ḅr/BḊṖṭ@¹Uz0ZUṖṾ€€ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCIsVVbigqzigqzhuIRyL0LhuIrhuZbhua1AwrlVejBaVeG5luG5vuKCrOKCrCIsIsOHWSIsIiIsWyJcIjAwMVwiIl1d"" rel=""noreferrer"">Try It Online!</a></p> | |
<p>Follows the input format very strictly (input as string, output as list of strings including padding zeroes).</p> | |
<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>,UḄr/ḊṖB | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCIsVeG4hHIv4biK4bmWQiIsIiIsIiIsWyIwLCAwLCAxIl1d"" rel=""noreferrer"">Try It Online!</a></p> | |
<p>Using actually reasonable I/O formatting, if we accept a list of digits and output as digit lists without doing leading zeroes, this is a lot more suitable for Jelly.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>8</s> 7 bytes</h1> | |
<pre><code>9Ṗ+pṖḅḤ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/y4c5p2gVA4uGO1oc7lvz/DwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 byte thanks to <a href=""https://codegolf.stackexchange.com/users/3852/lynn"">Lynn</a> by combining our answers, so make sure to upvote <a href=""https://codegolf.stackexchange.com/a/239652/66833"">their answer</a> as well!</p> | |
<h2>How it works</h2> | |
<pre><code>9Ṗ+pṖḅḤ - Main link. Takes no arguments | |
9 - Set the return value to 9, and execute with 9 on the left | |
Ṗ - Pop, yielding [1,2,3,4,5,6,7,8] | |
+ - Add 9 to each: [10,11,12,13,14,15,16,17] | |
Ṗ - Pop, yielding [1,2,3,4,5,6,7,8] | |
p - Cartesian product: [[10,1],[10,2],...,[17,8]] | |
Ḥ - Unhalve; Yield 18 | |
ḅ - Unbase; Convert [a, b] to 18a+b | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŒufØAṢŒɠ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opNK0wzMcH@5cdHTSyQX/D7drRv7/r56YnFZV5aiuo@4BVJWvEJ5flJOiCOTq6uoqqmkpqyQC2Ym4QYo6AA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŒuċⱮØA¹Ƈ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opNIj3Y82rjs8w/HQzmPt/w@3a0b@/6@emJxWVeWorqPuAVSWrxCeX5STogjk6urqKqppKaskAtmJuEGKOgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Both as full programs, taking advantage of Jelly's automatic smash-printing behavior.</p> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>O%12&ƊḌ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/99f1dBI7VjXwx09////f9S47VHjViA6tBlMbzi089AmEHsLmAuU3P6occejxp0A"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>O Get ordinal values | |
%12&Ɗ Apply x ↦ x%12&x | |
Ḍ Digits to number | |
</code></pre> | |
<p>I found the <code>x%12&x</code> formula by computer search. If I/O were super duper lenient, I guess <code>%12&</code> would be a valid 4-byte answer.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>DCSÐƤ«\ỊƑø# | |
</code></pre> | |
<p><a href=""https://tio.run/##AR4A4f9qZWxsef//RENTw5DGpMKrXOG7isaRw7gj////NjU"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of ovs's APL solution. Full program.</p> | |
<pre><code> ø# Starting from 0, collect the first [input] integers satisfying: | |
DC Subtract each decimal digit from 1. | |
SÐƤ Take the sum of each suffix. | |
«\ Are the cumulative minima | |
ỊƑ all equal to 1? | |
</code></pre> | |
<p><code>ø#</code> works by placing <code>#</code> in a niladic chain with no leading nilad, supplying it <code>0</code> as a starting value (note that it takes the number of values to gather from the last argument to the program, rather than anything within the link). The condition that the cumulative minima of the suffix sums are all 1 is equivalent to that the sum of the entire list is 1 and no suffix sum is less than 1.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 6 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ẈÄPƝḂẸ | |
</code></pre> | |
<p>A mondadic Link that accepts a list of lists of characters and yields <code>0</code> if valid or <code>1</code> if invalid.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hro7DLQHH5j7c0fRw147/h9sfNa35/z86OpZLJ1opWAlChUNoPyUdBSVXEOEXDiZdoeJgsWAIGY4kD1cfDCJwmwJXhsVANEOQzUc20A/EiQUA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>The only way to reach a square is via a sequence of an odd number of cardinal directions, after which if a diagonal direction is given the input is invalid. The cardinal directions are length one, while diagonal ones are length two. Thus if the cumulative sum of lengths of the input contains two odd numbers in a row it is an invalid instruction.</p> | |
<pre><code>ẈÄPƝḂẸ - Link: instuctions | |
Ẉ - length of each instruction | |
Ä - cumulative sums -> odd when taken to a square given a valid prefix | |
Ɲ - for neighbours: | |
P - product (only odd * odd is odd) | |
Ḃ - is odd? (vectorises) | |
Ẹ - any? | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>10</s> 8 bytes</h1> | |
<pre><code>3Rṁx@JṢƙ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9846OHOxgoHr4c7Fx2b@f9w@9FJD3fO0Iz8/z/aUEfBSEfBWEfBREfBVEfBTEfBXEfBQkfBMlZHIRooYKmjoGsEFtE1gykCihmCpC3AGnUNwdp0LcBadQ1jAQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>3Rṁx@JṢƙ - Main link. Takes L on the left | |
3R - [1,2,3] | |
ṁ - Mold to length L, repeating | |
J - Yield [1,2,...,len(L)] | |
x@ - Repeat 1 once, 2 twice, 3 thrice, 4 once, 5 twice, etc. | |
Ṣƙ - Sort chunks of L, grouped by the elements of [1,2,2,3,3,3,4,...] | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>J%6B§=1ÄṢƙ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJKJTZCwqc9McOE4bmixpkiLCIiLCIiLFsiWzUsIDksIC0yLCA4LCAtNiwgNCwgNSwgOSwgMV0iXV0="" rel=""noreferrer"">Try It Online!</a></p> | |
<pre><code>J%6B§=1ÄṢƙ Main Link | |
J [1, 2, 3, ..., len(input)] | |
%6 [1, 2, 3, 4, 5, 0, 1, 2, 3, ...] | |
B Binary; [[1], [1, 0], [1, 1], [1, 0, 0], [1, 0, 1], [0], ...] | |
§ Sum each; [1, 1, 2, 1, 2, 0, ...] | |
=1 Equal to 1?; [1, 1, 0, 1, 0, 0, ...] | |
Ä Cumulative sum; [1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 6, 6, ...] | |
Ṣƙ Sort chunks of the input grouped based on equal elements on the left side | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>10</s> 8 bytes</h1> | |
<pre><code>Żṗ‘}Ḅ=¥Ƈ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATYAyf9qZWxsef//xbvhuZfigJh94biEPcKlxof/w6cixZLhuZjigqxZ//8xLDUsMSw3/zAsMCwxLDQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <code>c</code> on the left, <code>n</code> on the right</p> | |
<p>Brute-force approach. Generates all lists of length <span class=""math-container"">\$n+1\$</span> containing the numbers <span class=""math-container"">\$0\$</span> to <span class=""math-container"">\$c\$</span>, meaning that it times out for <span class=""math-container"">\$n > 7\$</span> on TIO. For a <em>much</em> faster version, see the <a href=""https://codegolf.stackexchange.com/revisions/238103/1"">revision history</a>.</p> | |
<p>-2 bytes thanks partially to <a href=""https://chat.stackexchange.com/transcript/message/59797443#59797443"">a suggestion</a> by <a href=""https://codegolf.stackexchange.com/users/68942/hyper-neutrino"">hyper-neutrino</a></p> | |
<h2>How it works</h2> | |
<pre><code>Żṗ‘}Ḅ=¥Ƈ - Main link. Takes c on the left, n on the right | |
Ż - Generate the range [0, ..., c] | |
} - To n: | |
‘ - Yield n+1, to account for n = 0 | |
ṗ - Cartesian power. Yield all lists of length n+1 of the elements of [0, ..., c] | |
¥Ƈ - Keep those for which the following is true: | |
Ḅ - When converting from binary, | |
= - they equal n | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 20 bytes</h1> | |
<pre><code>Œ!ŒṖ€ẎL=¥Ƈ§E$ƇẎPÞLÞḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATsAxP9qZWxsef//xZIhxZLhuZbigqzhuo5MPcKlxofCp0Ukxofhuo5Qw55Mw57huKL///9bMSwyLDMsNF3/Mg"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Very messy port of my Vyxal answer. Full program.</p> | |
<p>-1 thanks to ovs.</p> | |
<pre><code>Œ! # Permutations | |
ŒṖ€ # Partitions of each of these | |
Ẏ # Flattened by depth 1 | |
---Ƈ # Filter by... | |
¥ # Last two links as a dyad... | |
L # Length | |
= # Equal to other input value? | |
---Ƈ # Filter by... | |
$ # Last two links as a monad... | |
§ # Vectorised sums... | |
E # All equal? | |
Ẏ # Flatten by one level | |
-Þ # Sort by... | |
L # Length | |
-Þ # Sort by (tiebreak) product | |
P # Product | |
Ḣ # Get the first item. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>O%11sJµZı*Ż€ÄFQL)MḢ | |
</code></pre> | |
<p>A monadic Link accepting a list of characters which yields an integer, the optimal number of Santas.</p> | |
<p><strong><a href=""https://tio.run/##AS0A0v9qZWxsef//TyUxMXNKwrVaxLEqxbvigqzDhEZRTClN4bii////dj5ePnY8Xjw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>1ŒrUj@ƒƊDFƊ¡ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/w6KSi0CyHY5OOdbm4Hes6tPD////mAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Fixed thanks to pxeger</p> | |
<pre><code>1 Ɗ¡ Repeatedly apply the given number of times, starting from 1: | |
Œr Encode as a list of [digit, run length] pairs, | |
U reverse each pair, | |
j@ƒƊ join each of them around the original value in sequence, | |
D decompose the elements of their results into digits, | |
F and flatten them. | |
</code></pre> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>ŒrZU2¦ṚżWDF | |
1Ç¡</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FtuOTiqKCjU6tOzhzllH94S7uHEZHm4_tHBJcVJy8dJDix7u6IGoW7DQEsIAAA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>Explanation:</p> | |
<pre><code>ŒrZU2¦ṚżWDF inner link | |
Œr run-length encode (list of pairs of [element, frequency]) | |
Z zip (produces [[list of elements], [list of corresponding frequencies]]) | |
U2¦ reverse the second element | |
Ṛ flat-reverse (changes to [list of corresponding frequencies], [list of elements]) | |
żW interleave with the input, producing [[[elements], [input]], [frequencies]] | |
NB: due to a bit of a quirk with Jelly's interleave function and vectorisation, | |
this makes [[a, b], c] not [a, b, c] as one would expect | |
D get digits of each item (in case an item has >=10 consecutive occurrences) | |
F flatten (smooths out both the oddity with interleave, and flattens the lists of digits) | |
1Ç¡ main link | |
1 starting with 1, | |
¡ repeatedly apply | |
Ç the above link | |
</code></pre> | |
<p>A naïve translation of the question description</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>1ŒrZṚU1¦$jƲDFƊ¡ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCIxxZJyWuG5mlUxwqYkasayREbGisKhIiwiIiwiIixbIjUiXV0="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>fixed for +3 bytes thanks to Unrelated String, and I can't be bothered to golf or re-explain it anymore</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>ḋƤJS | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLhuIvGpEpTIiwiIiwiIixbIjI3LjUwLCAyNS4wMCwgNS4wMCwgNzAuMDAsIDY1LjAwLCAyNS4wMCwgNTAwLjAwLCA0LjI1LCAyODkuNjUsIDMxOC4yNiwgMTAwLjgzLCAxMDAuMTMiXV0="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>-1 byte thanks to caird coinheringaahing</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>5</s> 4 bytes</h1> | |
<pre><code>JƤSḋ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/r2JLghzu6////b2SuZ2qgo2BkqmcApCCkuQGYMoPwYFIGEFETPSNToKCFpZ4ZkDY2tNAzMtNRMATKWhhDaENjAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 byte thanks to <a href=""https://codegolf.stackexchange.com/users/97857/pxeger"">pxeger</a>!</p> | |
<p>Ignores the strings as input, just takes a list of 12 prices</p> | |
<h2>How it works</h2> | |
<p>Basically, the number of each item is given as</p> | |
<pre><code>Day 1: 1 | |
Day 2: 1 2 | |
Day 3: 1 2 3 | |
Day 4: 1 2 3 4 | |
... | |
Day 12: 1 2 3 4 5 6 7 8 9 10 11 12 | |
Total : 12 22 30 36 40 42 42 40 36 30 22 12 | |
</code></pre> | |
<p>Which is just the prefixes of the range <code>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]</code>, summed down the columns. We then multiply each price by the quantity and take the total</p> | |
<pre><code>JƤSḋ - Main link. Takes a list of 12 prices P on the left | |
Ƥ - Over the prefixes of P: | |
J - Convert to a length range | |
S - Sums of the columns | |
ḋ - Dot product with P | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>ẆFS | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hrja34P///xuZ65ka6CgYmeoZACkIaW4ApswgPJiUAUTURM/IFChoYalnBqSNDS30jMx0FAyBshbGENrQGAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A port of <a href=""https://codegolf.stackexchange.com/a/237977/66833"">ovs' answer</a> - sublists, flatten, sum</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>17</s> <s>12</s> 11 bytes</h1> | |
<pre><code>ẆmþJẎ“£uƇ»e | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hrrbcw/u8Hu7qe9Qw59Di0mPth3an/n@4e8vh9kdNa45OerhzBpCO/P8/LzM5lSsvP7MquTSVKxEEQCJVQMCVB2Qlp6amclVwJSYlc2XmgVSCxaBURSpXQVFqMlCiBAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-5 bytes by adapting <a href=""https://codegolf.stackexchange.com/a/237937/66833"">emanresu A's approach</a><br /> | |
-1 byte thanks to <a href=""https://codegolf.stackexchange.com/users/64121/ovs"">ovs</a>!</p> | |
<h2>How it works</h2> | |
<pre><code>ẆmþJẎ“£uƇ»e - Main link. Takes a word W on the left | |
Ẇ - Contiguous substrings S of W | |
J - Yield the range 1 ≤ i ≤ len(W) | |
þ - For each pair (S, i): | |
m - Take the ith elements of s | |
Ẏ - Tighten into a list of strings | |
“£uƇ» - Compressed string; "nice" | |
e - Is this in the list of strings? | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>JẊị"żŒu$ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJK4bqK4buLXCLFvMWSdSQiLCIiLCIiLFsiaGVsbG93b3JsZCJdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>-2 bytes thanks to a clever trick from Adnan using cyclical indexing, thus tying pxeger's answer</p> | |
<pre><code>JẊị"żŒu$ Main Link | |
J [1, 2, ..., len(input)] | |
Ẋ random permutation of that | |
ị" vectorize - index (half of them are even, half are odd, and it wraps) | |
żŒu$ the input zipped with itself capitalized | |
</code></pre> | |
" | |
"97857","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŒuJḂẊTƲ¦</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FuuPTir1erij6eGurpBjmw4tW1KclFwMlVsVrZSYlJySmqYUCxUBAA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>Using the mod-2 trick from <a href=""https://codegolf.stackexchange.com/a/237903/97857"">Adnan's 05AB1E answer</a>.</p> | |
<p>Explanation:</p> | |
<pre><code>ŒuJḂẊTƲ¦ | |
Œu TƲ¦ uppercase at truthy indices: | |
J range [1..length(input()] | |
Ḃ each modulo 2 | |
Ẋ random permutation | |
</code></pre> | |
<p><code>JḂ</code> essentially creates <code>[0, 1, 0, 1, ..., 0, 1]</code> up to the length of the input.</p> | |
<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ŒuJẊŒHḢƲ¦</code></pre> | |
<p><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FhuPTir1erir6-gkj4c7Fh3bdGjZkuKk5GKo7KpopcSk5JTUNKVYqAgA"" rel=""nofollow noreferrer"">Attempt This Online!</a></p> | |
<p>Explanation:</p> | |
<pre><code>ŒuJẊŒHḢƲ¦ | |
Œu Ʋ¦ uppercase at indices: | |
JẊ random permutation of [1..length(input)] | |
ŒH split that list into two halves | |
Ḣ take the first of those two halves | |
</code></pre> | |
<p>I think there ought to be a shorter way of doing the <code>JẊŒHḢ</code>, <s>perhaps by picking a random combination</s><sup><a href=""https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FuuPTir1Ojo52cdDJeLYpkPLlhQnJRdD5VZFKyUmJaekpinFQkUA"" rel=""nofollow noreferrer"">nope</a></sup>. Or, at least, a shorter version of <code>ŒHḢ</code>.</p> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 18 bytes</h1> | |
<p>Very inefficient, <span class=""math-container"">\$n=4\$</span> is just on the edge of timing out on TIO.</p> | |
<pre><code>Œc_/€²§QƑ | |
pµŒPÇƇṪL | |
</code></pre> | |
<p><a href=""https://tio.run/##ATQAy/9qZWxsef//xZJjXy/igqzCssKnUcaRCnDCtcWSUMOHxofhuapM/8OH4oKs//8xLCAyLCAz"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><strong>Commented</strong>:</p> | |
<pre><code>Œc_/€²§QƑ -- helper function; verify a set of pawn coordinates is valid | |
Œc -- unordered pairs of coordinates | |
_/€ -- reduce each pair by subtraction | |
² -- square all values | |
§ -- sum to get the squared euclidean distance between each pair | |
QƑ -- is this invariant under deduplication? | |
p -- cartesian product of (implicit) ranges [1..n] and [1..n] | |
ŒP -- the powerset of this (sorted by length) | |
ÇƇ -- filter the coordinate subsets on the helper function | |
ṪL -- get the length of the last subset | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>HḞ,ĊƊ;’߀S‘µ0’? | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJI4bieLMSKxoo74oCZw5/igqxT4oCYwrUw4oCZPyIsIiIsIiIsWyIxMCJdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>I don't think this is close to optimal.</p> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 25 bytes</h1> | |
<pre><code>“ṠȷŀƤoĊịSAĊhJİⱮa¤XPṢḞɦ»ŒV | |
</code></pre> | |
<p><a href=""https://tio.run/##ATgAx/9qZWxsef//4oCc4bmgyLfFgMakb8SK4buLU0HEimhKxLDisa5hwqRYUOG5ouG4nsmmwrvFklb//w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Executes the Python code <code>open(*'aw').write('Hello World')</code>.</p> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>25</s> 23 bytes</h1> | |
<pre><code>ṣṪṣ”:ṣ”,⁾-ry$€VFƲ€ŒpƊ€Ẏ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzsUPd64Cko8a5lpBKJ1Hjft0iypVHjWtCXM7tglIHZ1UcKwLSD/c1ff/4e4th9vBYg93zgDSkf//G@oa6ZhaGRroGhrpG1gZ6hrrcxlYGehzAVlWRvpcJlamumb6XJY6hgY6hoZWlrqGhkA5A6ASXUMdIx1jXRN9Q5A6EGFsZaJvamWmb25loW8JNFIfAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-2 bytes from reading Kevin Cruijssen's answer.</p> | |
<pre><code>ṣṪṣ”:ṣ”,⁾-ry$€VFƲ€ŒpƊ€Ẏ | |
ṣ Split on | |
Ṫ last character, removing it from the string | |
Ɗ€ For each: | |
ṣ”: Split on ":" | |
Ʋ€ For each: | |
ṣ”, Split on "," | |
$€ For each: | |
y Replace | |
⁾-r "-" with "r" | |
V Evaluate as Jelly programs (r = range) | |
F Flatten | |
Œp Cartesian product | |
Ẏ Tighten (shallow flatten) | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>Ẇ§2ḍS | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hrrZDy40e7ugN/h9toWOqY6ljAiQNdQxiD7f/BwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Similar to my Vyxal answer, but Jelly's builtins are nicer. A monadic link.</p> | |
<pre><code>Ẇ # Sublists | |
§ # Sum (vectorised) | |
2ḍ # Is divisisible by 2? (vectorised) | |
S # Sum (non-vectorising) | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 47 bytes</h1> | |
<pre><code>ḢɓL,“¥ṃkŒ»ƊḷḊ?“ and ”;;“@k»ʋ;“ is”$ḷ?ṭ⁹“Æʋ@1'ɼ» | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjkUnJ/voPGqYc2jpw53N2UcnHdp9rOvhju0Pd3TZA0UVEvNSFB41zLW2BnIcsg/tPtUNYilkFgMFVYDq7B/uXPuocSdQ7HDbqW4HQ/WTew7t/v8/WsmpNCkpJ7VIKZYrWsmjsiC1yC@1tKQoMy9fSUdBqbQYKpOam5hXlFpcquAIEs6prEjMATG88hW8M/PSwUoKKlLTgaqBonmlOTlUo0FGGxpQ31iE14GBpFBSWQDyB1A2sxhEJhalgqm8FKVYAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Full program, as it uses Jelly's smash-printing and nilad dumping.</p> | |
<h2>How it works</h2> | |
<pre><code>ḢɓL,“¥ṃkŒ»ƊḷḊ?“ and ”;;“@k»ʋ;“ is”$ḷ?ṭ⁹“Æʋ@1'ɼ» - Main link. Takes a list of usernames U on the left | |
Ḣ - Chop off the first username, B, and set U' to be U without its head | |
ɓ - Start a new dyadic link f(U', B) | |
? - If: | |
ḷ - U' is non-empty | |
ʋ - Then: | |
? - If: | |
Ḋ - U' has more than one element | |
Ɗ - Then: | |
L - Take the length of U' | |
“¥ṃkŒ» - Compressed string: " others" | |
, - Pair; [len(U'), " others"] | |
ḷ - Else: Yield B | |
“ and ”; - Prepend " and " | |
;“@k» - Append " are" | |
$ - Else: | |
;“ is” - Append " is" | |
ṭ⁹ - Tack all of this to the end of B | |
“Æʋ@1'ɼ» - Unparseable nilad. Smash print the previous stuff, then print " typing..." | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>1Æd×ọÆsƲ# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/wcFvK4ekPd/cebis@tkn5P1DECAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>More boring than the other answer:</p> | |
<pre><code> Implicit input: an integer z. | |
1 Ʋ# Count up from 1, finding z numbers for which... | |
Æd× divisor_count(n) × n | |
ọ is divisible by | |
Æs divisor_sum(n). | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ÆDpWSḍ/µ# | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLDhkRwV1PhuI0vwrUjIiwiIiwiMTIiLFtdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>This is horribly scuffed because I couldn't figure out how to get it working with precision. I had the same idea as ovs it turns out, but <code>ÆDÆmḍµ#</code> fails due to precision issues.</p> | |
<p>I honestly hate how this is written.</p> | |
<pre><code>ÆDpWSḍ/µ# Main Link | |
µ# nfind; return first n values satisfying: | |
ÆD divisors of n | |
p cartesian product with | |
W [n] (returns [[a, n], [b, n], ...]) | |
S sum (returns [divisor sum, divisor count * n]) | |
ḍ/ reduce by divisibility check | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>15</s> 14 bytes</h1> | |
<pre><code>ċⱮØ(Iɓ”)ØD;faƒ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9I96ON6w7P0PA8OflRw1zNwzNcrNMSj036f7hdM/L/fyUlHSUNQ20IqWGkb4xgaSIxNXUtUHlaGuh8DVNMEU0sQppKAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 because I actually looked at other solutions and remembered <code>ċ</code> exists</em></p> | |
<p>Returns falsy (empty list) for open or truthy (nonempty list) for close. Took a hell of a lot of permuting to get here from <code>=€Ø(ISaṪe”)ṭØD¤Ɗ</code>.</p> | |
<pre><code> ØD; Concatenate "0123456789" and | |
”) a closing parenthesis. | |
f Keep only its elements which are also elements of | |
ɓ aƒ the input reduced LtR by logical AND starting with: | |
ċⱮØ( Count the opening and closing parentheses in the input, | |
I and subtract the opens from the closes. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 46 bytes</h1> | |
<pre><code>®Ṭ€z0aḷżṚ⁸ṭṚŻ€4¡o⁶ð“><+-.,[]”iⱮxṠoŒQÄ©ŒQƲ$$ịŻ€ | |
</code></pre> | |
<p><a href=""https://tio.run/##jdAxTwIxFAfw/T7FGxg0wIXBkTC5YKLE0RCGUh5clWsvvZ4RjAkYNzdHo4m6GBMgaoxyOSfI@T3aL3IeoIZBolNf37@/tH372G53kmQy0uHAnA66BaLHb/G7Di9Nf6zDYVrEURpsTG6F6b9OH03vqlTM5u1ctWZ618w8jY50eCPii93p2eQhXT6eMxkdnc9VoqMXPb6b3mf2kqRaK5aOT9bWs9l83rZzOWtbHCIoB8ETjCuUoMR8K1nLUSvTNjaVVeZUootczVsuukJ2gKZ/AaKWkbWJ/zxYCZQXLFrUIZLQ2ZU@a3HWZNiAemcR/SLLfAbJEiO8Ab4SEoEpYHyl3ApcDzzifz2OKOow3oIasOYqA8yHwgLWCT34HsqPrf5hueBdlMLaEVDxUBLFBP8E"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Program on the left and list of descriptions on the right. I suspect this can lose a few bytes fairly easily, but I'm posting it now in order to preserve one of the most hideous things I have ever written for posterity.</p> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>b⁹+⁹_0¦⁹ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/pUeNObSCONzi0DEj9///foMLQAAwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>Explanation</h2> | |
<pre><code>b⁹+⁹_0¦⁹ | |
b Convert to base | |
⁹ 256 | |
+ Add | |
⁹ 256 | |
¦ At index | |
0 last | |
_ subtract | |
⁹ 256 | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>7</s> 6 bytes</h1> | |
<pre><code>ÆDDṀḌ= | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wm4vLw50ND3f02P4/3H6s/f9/ExMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-7 bytes (50%!) thanks to Kevin Cruijssen!<br /> | |
-1 byte thanks to ovs!</p> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ḶU|%Ḃ‘ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjm2hNaoPdzQ9apjx3/3h7i3Wj5rWPGqYY6Wg8KhhrrXS4eX6QAGQxLGuyP//o6MNdQxjdYCkEZA0ArONwGxjMNsYzDYBs03AbEsw2xLMNjSAaDYA8mIB"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Like Dingledooper's answer, but a bit different.</p> | |
<pre><code>ḶU range [L-1..0] | |
|% bitwise OR by L%A | |
(if L%A=0, this does nothing; | |
if L%A=1, it makes the whole range odd) | |
Ḃ‘ mod 2, add 1 | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ŒṗƲẠ$ƇṪU | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIc7px9uO7Tp4a4FKsfaH@5cFfpf53A7SHiGirdm5P//hjpGOsY6JjrmOhY6ljqGRjqGxjrGBjqmBgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ŒṗfƑƇ²€ṪU | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIc7p6cdm3is/dCmR01rHu5cFfpf53A7SHiGirdm5H9jAx1Tg/@GOkY6xjomOuY6FjqWOoZGOobGAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Times out for test cases larger than 50.</p> | |
<h2>How they work</h2> | |
<pre><code>ŒṗƲẠ$ƇṪU - Main link. Takes n on the left | |
Œṗ - Integer partitions of n; Ways to sum positive integers to n | |
$Ƈ - Keep those partitions P for which the following is true: | |
Ạ - All elements are: | |
Ʋ - Square numbers | |
ṪU - Take the last (the shortest) and reverse it | |
ŒṗfƑƇ²€ṪU - Main link. Takes n on the left | |
Œṗ - Integer partitions of n; Ways to sum positive integers to n | |
€ - For each integer to n: | |
² - Yield its square | |
ƑƇ - Keep partitions that are unchanged after: | |
f ²€ - Removing all non-squares | |
ṪU - Take the last (the shortest) and reverse it | |
</code></pre> | |
" | |
"48934","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>14</s> 12 bytes</h1> | |
<pre><code>ØAiⱮ’Ä%26ƊƬL | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wDMfMRxvXPWqYebhF1cjsWNexNT7///9X8gh3j/R0CgJCH0eXsMiQCB8lAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>s2UF | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJzMlVGIiwiIiwiIixbIjEsMiwzLDQsNSw2Il1d"" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<pre><code>s2 Slices of length 2 | |
U Reverse each | |
F Flatten | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>%‘;2ṁḷU | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/1/1UcMMa6OHOxsf7tge@t/y8HLD/wA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Thanks to Unrelated String for making this work! Port of dingledooper's answer.</p> | |
<pre><code>%‘ṭ2ṁḷU # Dyadic link taking two arguments | |
ṁ # Mold... | |
;2 # 2 appended to... | |
% # The modulo of the two inputs | |
‘ # Plus 1 | |
ṁ # To length... | |
ḷ # Left argument (length input) | |
U # Reversed | |
</code></pre> | |
" | |
"107299","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 2 bytes</h1> | |
<pre><code>bL | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/J5////4YGBkAMAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Finally, a Jelly answer using ASCII only.</p> | |
<pre><code>bL - Main link. Takes a number on left, base on right | |
b - Obtain left base right | |
L - Get the length of the string representation of the result | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>œ&ƑƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///oZLVjE4@1/z@8XMn7UdOayP//o5USi5V0FJSK80FkCZjMTywpVorVUYDJAUWReHCVqCogMhhiJfkQI4vwSv0HSkAEkWgQVVVVWVUBVlyUnwuii/Lzc0uUAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>œ&ƑƇ - Main link. Takes a list of words L on the left, a word W on the right | |
Ƈ - Keep those words from L such that: | |
Ƒ - They are unchanged after taking: | |
œ& - The multiset intersection with W | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ṢŒrUFVµ¡ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzkVHJxWFuoUd2npo4f///w0tkMB/QwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Credit to hyper-neutrino for the <code>µ</code> trick, and for telling me <a href=""https://chat.stackexchange.com/transcript/message/59537861#59537861"">I was wrong</a> :P</p> | |
<p>Full program. Takes <code>n</code> then <code>k</code> on the command line</p> | |
<h2>How it works</h2> | |
<pre><code>ṢŒrUFVµ¡ - Main link. Takes n on the left, k on the right | |
µ - Last links as a monadic chain f(n): | |
Ṣ - Sort the digits of n | |
Œr - Run length encode | |
UF - Reverse each and flatten | |
V - Eval as a single number | |
¡ - Iterate f(n) k times | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 18 bytes</h1> | |
<pre><code>_þµṂ>Ɠa~¤×¬Ḥ+ḂŒBŒḄ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATEAzv9qZWxsef//X8O@wrXhuYI@xpNhfsKkw5fCrOG4pCvhuILFkkLFkuG4hP/Dh0f/Mv81"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 from caird, who noted that I could get rid of a backtick by reading <code>b</code> from stdin.</p> | |
<pre><code> For inputs (a, b): | |
_þµ Make a subtraction table over [1..a], and operate on that. | |
Ṃ Get the minimum row: this is always [1-a, 2-a ... 0]. | |
>Ɠa~¤ Which elements are greater than (b and ~b)? | |
For example for (5, 2): Ṃ → [-4, -3, -2, -1, 0] | |
Ṃ>-3 → [ 0, 0, 1, 1, 1] | |
׬ Multiply this vector by the a×a identity matrix "¬table" | |
Ḥ and double the result (generating the 2s) | |
+Ḃ then add to an a×a checkerboard of 1s "table % 2": | |
0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 | |
0 0 0 0 0 1 0 1 0 1 1 0 1 0 1 | |
0 0 2 0 0 + 0 1 0 1 0 → 0 1 2 1 0 | |
0 0 0 2 0 1 0 1 0 1 1 0 1 2 1 | |
0 0 0 0 2 0 1 0 1 0 0 1 0 1 2 | |
ŒBŒḄ Finally, palindromize both ways to make the full output. | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 bytes</h1> | |
<pre><code>^þ | |
ÇḂ+UṚŒḄŒBɓa‘{ǬḤ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/u8D6uw@0PdzRphz7cOevopIc7Wo5Ocjo5OfFRw4zqw@2H1jzcseT/4eX67ppZjxr3cXH9/x9tpKNgEKujAKINQbQxlG@M4BuBaBOouAlU3AQhbhwLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>With some inspiration from hyper-neutrino's Vyxal solution.</p> | |
<pre><code>^þ Monadic helper link: | |
þ Table the (range from 1 to the) argument with itself by | |
^ XOR. | |
Ḃ The parities of the cells form a checkerboard, | |
¬ and the diagonal consists of zeroes while the rest is truthy. | |
ÇḂ+UṚŒḄŒBɓa‘{ǬḤ Dyadic main link: | |
Ǭ Generate an identity matrix of size | |
ɓ b | |
‘ + 1 | |
a { or 0 if b is 0, | |
Ḥ then double it. | |
+ Add that to (the top left corner of) | |
ÇḂ an a by a checkerboard, | |
UṚ rotate the result 180 degrees, | |
ŒḄŒB and palindromize it in both dimensions. | |
</code></pre> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>25</s> <s>24</s> <s>23</s> <s>22</s> 21 bytes</h1> | |
<pre><code>^þ | |
ÇḂ+ŒḄŒBðÇUoḶ>¥*¬ḤU | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/u8D6uw@0PdzRpH530cEfL0UlOhzccbg/Nf7hjm92hpVqH1jzcsST0/@Hl@u6aWY8a93Fx/f8fbaSjYBCrowCiDUG0MZRvjOAbgWgTqLgJVNwEIW4cCwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>That feels better. <span class=""math-container"">\$a\$</span> on the left, <span class=""math-container"">\$b\$</span> on the right.</p> | |
<pre><code>^þ Monadic helper link: | |
þ Table the (range from 1 to the) argument with itself by | |
^ XOR. | |
Ḃ The parities of the cells form a checkerboard, | |
¬ and the diagonal consists of zeroes while the rest is truthy. | |
ÇḂ+ŒḄŒBðÇUoḶ>¥*¬ḤU Dyadic main link: | |
Ç Generate an a by a matrix of zeroes on the diagonal and nonzeroes elsewhere. | |
U Mirror it, | |
o and replace zeroes with corresponding elements from: | |
Ḷ ¥ for each 0 .. a-1, | |
> is it greater than b? | |
* Raise each to the bth power, | |
¬ logically negate, | |
Ḥ double, | |
U and mirror back. | |
+ ð Add that to | |
ÇḂ an a by a checkerboard, | |
ŒḄŒB then palindromize in both dimensions. | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 bytes</h1> | |
<pre><code>LØ.ṗ+ḟ0÷SḋÆl$ƊɗÐṂ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/n8Ay9hzunaz/cMd/g8Pbghzu6D7flqBzrOjn98ISHO5v@H25/uGPR0UkPd87QjPz/P9pYx0jHUMcwVgfIgrANdAyAPEMjIM8YLGECxOY65jpmQGgKkjIw0DE1AOsCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>LØ.ṗ+ḟ0÷SḋÆl$ƊɗÐṂ - Main link. Takes a list A on the left | |
L - Length of A | |
Ø.ṗ - Cartesian power of [0, 1] to the length of A | |
ɗÐṂ - Output the bitlist B with the minimum value f(B, A): | |
+ - Add the elements of B to A | |
ḟ0 - Remove any zeros | |
Ɗ - Last 3 links as a monad g(A+B \ {0}): | |
÷S - Divide each by the sum | |
$ - Last 2 links as a monad h([A+B \ {0}] ÷ sum): | |
Æl - Natural log of each | |
ḋ - Dot product | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>13</s> 12 bytes</h1> | |
<pre><code>Ø.,æ*ÆḊN,ÆṭƲ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wDD2dw8u0Drc93NHlpwOkdq49tun////GOrpG/40B"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input as <code>[v, u]</code> on the left, and <code>a</code> on the right. Outputs as <code>[β, α]</code></p> | |
<p>-1 byte thanks to ovs!</p> | |
<p>Uses xnor's formula that</p> | |
<p><span class=""math-container"">$$\alpha = \operatorname{tr} \left( \begin{bmatrix} 0 & 1 \\ v & u \end{bmatrix}^a \right) \\ | |
\beta = -(-v)^a = - \det \left( \begin{bmatrix} 0 & 1 \\ v & u \end{bmatrix}^a \right)$$</span></p> | |
<h2>How it works</h2> | |
<pre><code>Ø.,æ*ÆḊN,ÆṭƲ - Main link. Takes [v, u] on the left, a on the right | |
Ø. - Yield [0, 1] | |
, - Pair; [[0, 1], [v, u]] | |
æ* - Matrix power to a; Call this M | |
Ʋ - Last 4 links as a monad f(M): | |
ÆḊ - Determinant of M | |
N - Negated | |
Æṭ - Trace of M | |
, - Pair; [-det(M), tr(M)] | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 bytes</h1> | |
<pre><code>0BUJNÆḞḋƲ=ʋ1#ḢȯRB | |
</code></pre> | |
<p><a href=""https://tio.run/##AT4Awf9qZWxsef//MEJVSk7DhuG4nuG4i8ayPcqLMSPhuKLIr1JC/zEwxZJSICzDh8WS4bmYJCTigqwgS@KCrFn//w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>+3 bytes (<code>ḢȯR</code>) to output <code>[]</code> instead of <code>0</code></p> | |
<p>I'm sure this can be beaten by some clever mathematical trick; this just counts up in binary, converts from nega-Zeckendorf and stops when it equals the input</p> | |
<h2>How it works</h2> | |
<pre><code>0BUJNÆḞḋƲ=ʋ1#ḢȯRB - Main link. Takes n on the left | |
ʋ - Group the previous 4 links into a dyad f(k, n): | |
B - Convert k to binary | |
U - Reverse the bits | |
Ʋ - Group the previous 4 links into a monad g(bin(k)): | |
J - Indices | |
N - Negate | |
ÆḞ - nth Fibonacci number | |
ḋ - Dot product with bin(k) | |
= - Does g(bin(k)) equal n? | |
0 1# - Find the first integer k such that f(k, n) is true | |
Ḣ - Extract k | |
ȯR - If k = 0, replace with [] | |
B - Convert to binary | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>b©1ḋ®;Ɗ¡)Uœi | |
</code></pre> | |
<p><a href=""https://tio.run/##NY8xTsQwEEX7fwq3SIPk/@04jlbiFrQUaFMsWlEiuAKUewJKGmrqSHAPThIcD@neeMbz5j/M5/PLut4vH/z9els@Dz@vy/vV7ffltK4K1zdBJiSHhLxBtozBXzLKBsUKRm8NqN4aMG2QGjBuxGiMIP3DCPb1lFHgv6GAXcFszGC3VJvArmExtonR9zbqKlZjBafdQaj7FE0Rom8eIY/T8ghKuztB3ahsytDgKdp0N6qYCjTuNw2Qx6umCk1@X4uVujJFSxF3IYbT43F@no@H8BS4Fyv5Bw"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Multidimensional first index rocks again. Outputs <code>(which n-bonacci sequence, 1-based index in it)</code>.</p> | |
<h3>How it works</h3> | |
<pre><code>b©1ḋ®;Ɗ¡)Uœi Full program; Input = n, the number to search for | |
) For each of i=1..n, | |
b©1ḋ®;Ɗ¡ Generate i-bonacci sequence up to n+i terms: | |
b©1 i copies of 1; save it to register | |
¡ Repeat n times: | |
ḋ®;Ɗ Prepend the sum of first 3 terms to the current list | |
U Reverse each list | |
œi Find the multi-dimensional index of the first occurrence of n | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>TżU$Ṭḋ⁸S | |
</code></pre> | |
<p><a href=""https://tio.run/##LY2xEcIwDEX7zEH5C0u2IzwHUPlc0nBZgBIaClbJAOGOjmOQZBHz41Dp6/3T0@U8DNdaj9/3aTe/xnl6LrfpUD@P5T7WmrucYyng8IgFOcBtq6GHOBJ1EI8QGCOYt1qJoNJuNMDYGKMQKgikbzJDguj/RBnphAgtyHt2DhFiTW2QSKdvi29GXe1p5ZKIlL@78gM"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>T -- truthy indices of the argument, since every row is non-empty, this is [1 .. len(z)] | |
żU$ -- zip with its reverse | |
Ṭ -- for each pair of integers, create a list with 1's at those two indices | |
ḋ⁸ -- for each resulting list, take the dot product with the corresponding row vector of the input matrix | |
S -- sum the results | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>BCḄẒƲ# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/J@eGOloe7Jh3bpPz/vykA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes an input <code>n</code> from STDIN and outputs the first <code>n</code> Gobar numbers. If we have to output all Gobar numbers, the following works for 9 bytes</p> | |
<pre><code>ṄBCḄẒƲ¡‘ß | |
</code></pre> | |
<p><a href=""https://tio.run/##AR0A4v9qZWxsef//4bmEQkPhuIThupLGssKh4oCYw5///w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 21 bytes</h1> | |
<pre><code>æịþḶFµḢ;ⱮṖŒ!;€ṪƲIỊẠ€S | |
</code></pre> | |
<p><a href=""https://tio.run/##AT8AwP9qZWxsef//w6bhu4vDvuG4tkbCteG4ojvisa7huZbFkiE74oKs4bmqxrJJ4buK4bqg4oKsU/8xLDPDh@KCrP8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes forever for <code>n>3</code> because it tries to generate all permutations of <code>n**2-2</code> items.</p> | |
<pre><code>æịþḶFµḢ;ⱮṖŒ!;€ṪƲIỊẠ€S Monadic link. Input: n | |
æịþḶF Generate complex numbers (1..n)+(0..n-1)i | |
µḢ;ⱮṖŒ!;€ṪƲ Generate all permutations with 1st and last fixed: | |
Ḣ;Ɱ Chain 1st to each of... | |
ṖŒ!;€ Permutations of the middle with... | |
ṪƲ The last chained to the end of each | |
IỊẠ€S Count those whose pairwise distances are all 1 | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>»*@Żœcḷœċ§QƑɗƇḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8n5lXUFpipZCpo5DNlambnJ@blJmXWJKZn1eskJ@mUJSYl55qoJGbWKGRqZOtpZWpqWmtkJaZU5JapJGWX6SQmJOjUFCUmpZZkVpspVBcmgvWla1bhGJQYlGqQkpmcUlmXnIJWH9Rccn/Q7u1HI7uPjo5@eGO7UcnH@k@tDzw2MST04@1P9yx6P///yb/jQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <code>i</code> and <code>k</code> and returns the first <code>i</code> elements of the <code>k</code>th sequence. Extremely slow.</p> | |
<p>The <code>i</code>th term (1-indexed) cannot exceed <code>1+k+..+k**(i-2)</code> since the <code>k</code>-combinations without replacement of the set <code>0, 1, 1+k, 1+k+k**2, ..., 1+k+...+k**(i-2)</code> has distinct sums (because each added term is strictly larger than the previously existing maximum sum) and, as the terms strictly smaller than the bound emerge, the bound for the next term will only go lower. This bound can be relaxed to <code>max(i, k**i)</code> by considering the cases where <code>k=1</code> and <code>k>=2</code>.</p> | |
<pre><code>»*@Żœcḷœċ§QƑɗƇḢ Dyadic link. Left = i (#terms to return), Right = k | |
»*@ bound = max(i, k**i) | |
Żœcḷ All i-combinations of 0..bound | |
ƇḢ Filter and take the first sequence satisfying... | |
œċ§QƑɗ All k-combinations without replacement have distinct sums | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<p>Returns all valid alphabets and the empty list as a falsy value.</p> | |
<pre><code>FQŒ!iⱮⱮṢƑ¥Ƈ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/98t8OgkxcxHG9cB0cOdi45NPLT0WPv/hzs2HW6P/P/fUcExUcHRUcEpScEpEQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>F -- flatten the word list into a single string | |
Q -- get the unique characters | |
Œ! -- get all permutations of those characters | |
Ƈ -- keep the permutation that return a truthy value for: | |
¥ -- group the last two links into dyad | |
-- which is called with the permutation on the left and the word list on the right | |
iⱮⱮ -- for each character of each word get its index in the permutation | |
ṢƑ -- is the resulting list invariant under sorting? | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>12</s> 9 bytes</h1> | |
<p>-3 bytes thanks to Jonathan Allan</p> | |
<p>A dyadic function taking a list of lines on the left and a list of words on the right.</p> | |
<pre><code>Z;⁸KḲḊƇfƑ | |
</code></pre> | |
<p><a href=""https://tio.run/##TZExcsMgEEX7nGI7Gt0g1VqsLMUYNIBGgzUq4yLjC6RMmsykyynSpEqlPjO@h30RhQUpDoXe18KH5fP0eDo9z/Ph/voy7S7T92V6P78dzx/zz@f19Wueh0HssQUQhTCAbRupqQcT6YFIRdYogcRY3A1Coi4bveXVAAg8knREsXyrmlxWeAjgs9UZKxsJy0kdrGZF1GPImgBu9X86kPNkJYa0axoIedu9UWhjGZelFr1jljb/1@XSY81MFouuRLV6eHKDu9z@hnvnuzdOoZYpBPgzPphQdSpfzVQVWTGO8yBQFCAwfzlAWGNimSIEsTWeEaNkcC6J6e6s4hskGO1rFhodJmN8DEaLPSVraxQxbZewBh9VnFAhK06a1S238Rc"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Z;⁸ -- concatenate list of columns and list of rows | |
KḲ -- join on spaces and split on spaces to get list of words | |
Ƈ -- keep words that are truthy (non-empty) | |
Ḋ -- when the first character is removed | |
Ƒ -- is this resulting word list invariant when | |
f -- all words not in the dictionary are removed? | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <sup><s>10</s></sup> 9 bytes</h1> | |
<pre><code>ŒcÆḊ=¥Ƈ;€ | |
</code></pre> | |
<p><a href=""https://tio.run/##AR0A4v9qZWxsef//xZJjw4bhuIo9wqXGhzvigqz///82NQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Backport of my improved <a href=""https://codegolf.stackexchange.com/a/236384/78410"">Vyxal answer</a> to use pairs without replacement. -1 byte because I just realized there's a 2-byte norm built-in that saves a square. Passes all small test cases and moderately large ones (like 850) but 1105 times out, and might not work for larger inputs due to floating-point errors.</p> | |
<h3>How it works</h3> | |
<pre><code>ŒcÆḊ=¥Ƈ;€ Monadic link; Input = n, the hypotenuse | |
Œc Pairs of 1..n without replacement | |
ÆḊ=¥Ƈ Filter those whose norm (sqrt of self-dot-product) equals n | |
;€ Append n to each pair | |
</code></pre> | |
<hr /> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>R²+²)=²ŒṪ;€ | |
</code></pre> | |
<p><a href=""https://tio.run/##AR8A4P9qZWxsef//UsKyK8KyKT3CssWS4bmqO@KCrP///zI1"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h3>How it works</h3> | |
<pre><code>R²+²)=²ŒṪ;€ Monadic link; Input = n, the hypotenuse | |
) For each number i of 1..n, | |
R²+² collect the values of j^2+i^2 for j in 1..i | |
=²ŒṪ Coordinates (i,j) where j^2+i^2 = n^2 | |
(only gives the coordinates where i>j) | |
;€ Append n to each pair | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, <s>9</s> 7 bytes</h1> | |
<pre><code>ṡJ§Ṁ€⁼Ä | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLhuaFKwqfhuYDigqzigbzDhCIsIj3igJ0xw4cpWSIsIiIsWyInMDAwMDAnLCcxMTAxMDEwMTEwJywnMTExMTAxMTAxMTAwMTAwJywnMTExMDEwMTAxMTAxMTAwMTEwMDAnLCcxMTEwMDEwMTEwMTAwMTExMDAxMDAwMDExJywnMDAwMDEnLCcxMDExMDExMDAwJywnMTEwMTAxMTAxMTAwMTAwJywnMTEwMTAxMDAwMDExMDAwMDExMDEnLCcxMTEwMTAwMTAwMTEwMTAxMDEwMDEwMTExJyJdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>-2 bytes thanks to Unrelated String</p> | |
<pre><code>ṡJ§Ṁ€⁼Ä Main Link | |
ṡ Take overlapping slices of length(s) | |
J [1, 2, ..., length] | |
§ Take the sum of each slice of each length | |
Ṁ€ Is the maximum sum for each length | |
⁼ Equal to | |
Ä The cumulative sum of the original list? | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>9</s> 8 bytes</h1> | |
<pre><code>ẆẈṀƙ§Ɗ⁼Ä | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hrraHuzoe7mw4NvPQ8mNdjxr3HG75b/uoYa7h4XbNyP//1Q1AQF1H3dDQAAwNIRxDMBOIgGJQEZg8WNDQAC4MFQUJQpSDWEA5MAOkBqYJYQ2qyWCDDaCGgiXhFkKMNYAqAWkzVAcA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>It feels like something less naive should be shorter yet, but I haven't had any luck.</p> | |
<pre><code>Ẇ Get every substring of the input. | |
§ Sum each substring, | |
ƙ Ɗ group the sums by | |
Ẉ the lengths of the corresponding substrings, | |
Ṁ and take the largest element of each group. | |
⁼Ä Is the resulting list equal to the cumulative sums of the input? | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>ḊVṢ1;Ḍ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjq6whzsXGVo/3NHz//9/Q1MA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 thanks to Unrelated String</p> | |
<pre><code>Ḋ # Dequeue (Remove head from implicit range) | |
V # Eval (Jelly stringifies each, concatenates & evals, which does exactly what I want) | |
Ṣ # Sort | |
1; # Prepend a 1 | |
Ḍ # Decimalify, convert into base-10 number | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 <a href=""https://github.com/DennisMitchell/jelly/iki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ṀRḟṣṪṪƊƲƤ⁼W€ | |
</code></pre> | |
<p>A monadic Link that accepts a list of positive integers and yields <code>1</code> if a prefix of some infinite fractal sequence, or <code>0</code> if not.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hzoaghzvmP9y5@OHOVUB0rOvYpmNLHjXuCX/UtOb////RhjoKQGSko2CMyjABs00h3FgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///hzoaghzvmP9y5@OHOVUB0rOvYpmNLHjXuCX/UtOb/4XYQ@T862jBWRyHaUEcBhKBMIx0FYwQTSRRIGsMYJghFUC2oDBMw2xTCBSm0tLSEqjfGaSLMLogRpjCGOZAdGwsA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>Checks that every non-empty prefix contains all integers up to and including its maximum <em>after</em> the penultimate* occurrence of its ultimate value.<br /> | |
* If a prefix only has one occurrence of its ultimate value then the whole prefix is used.</p> | |
<pre><code>ṀRḟṣṪṪƊƲƤ⁼W€ - Link: list, L | |
Ƥ - for each non-empty prefix, P, of L: | |
Ʋ - last four links as a monad, f(P): | |
Ṁ - maximum -> M | |
R - range -> [1,2,3,...,M] = X | |
Ɗ - last three links as a monad, f(P): | |
Ṫ - tail -> ultimate value = U | |
ṣ - P split at occurrences of U | |
Ṫ - tail -> values after "penultimate" U = T | |
ḟ - filter discard -> X without any of T | |
W€ - wrap each of L in a list | |
⁼ - equal? | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>,U$yJ}ị | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCIsVSR5Sn3hu4siLCIiLCIiLFsiMSwgNiIsIlsgMywgOCwgMSwgNCwxMCwxMCwxMCwxMF0iXV0="" rel=""noreferrer"">Try It Online!</a></p> | |
<p>A totally different Jelly 7-byter, so I figured I'd post this too. This is 1-indexed.</p> | |
<pre><code>,U$yJ}ị Main link; take indices on the left | |
,U$ Pair the indices with the reverse of itself ([[a, b], [b, a]]) | |
y Apply this as a translation to | |
J} The indices of the right list (J takes a list of length L and returns [1, 2, ..., L]) | |
ị Index back into the original list | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>7</s> 5 bytes</h1> | |
<pre><code>œPżịF | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o5ICjex7u7nb7H/qoYcbh5UpHJz3cOeNR05rI//@jjXUUzGN1FKINdBRMobQJlDaE0/@jDXWMdIx1THRMdcx0zHUsdCx1DA1A0gpA/RZAJUBdQBE4AkmZ6hgCNQC1QThmIMoIyDeKBQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes indexes as 1 indexed and reversed (so <code>[b, a]</code>), the Footer on TIO does this for you.</p> | |
<h2>How it works</h2> | |
<pre><code>œPżịF - Main link. Takes indices I on the left, array A on the right | |
œP - Partition A at the indices in I, not keeping the borders | |
ị - Retrieve the elements of A at the indices in I; [A[b], A[a]] | |
ż - Zip together | |
F - Flatten | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>31</s> <s>28</s> 27 bytes</h1> | |
<p>Takes input as a list of lines. Incredibly slow.</p> | |
<pre><code>œẹⱮ⁾+#ŒP;€¥/Œ!ạƝ§ṀƊ€ṂƊÞḢL_2 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o5Ie7dj7auO5R4z5t5aOTAqwfNa05tFT/6CTFh7sWHpt7aPnDnQ3HuoCCD3c2Hes6PO/hjkU@8UYgbTsXA/VwcT3cveVwuwpQwf//ytraylwKCtraXFzKQBaQqaCsDSIVwKQ2hAQLAwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><strong>Comments</strong> (slightly outdated):</p> | |
<pre class=""lang-haskell prettyprint-override""><code>ạƝ§=1Ạ -- helper function: is this a connected path? | |
ạƝ -- element-wise absolute differences of adjacent coordinates | |
§=1Ạ -- do all differences sum to 1? | |
Ɱ⁾+# -- call with right arguments '+' and '#' | |
œẹ -- multidimensional indices of right argument in inputs | |
¥/ -- call next two functions with '+'-indices on the left and '#'-indices on the right | |
ŒP -- all subsets of the '+'-indices | |
;€ -- append '#'-indices to each subset | |
ƊƇ -- filter; keep subsets where the following three functions yield a thruthy result | |
Œ! -- all permutations of the subsets | |
Ç€ -- call the helper function for each subset | |
Ẹ -- is any result truthy? | |
Ḣ -- take first (shortest) subset | |
L_2 -- length - 2 | |
</code></pre> | |
" | |
"92116","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>RḤÆfṀ€<7T | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/o4Y4lh9vSHu5seNS0xsY85P///4YGAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Returns all hamming numbers under n.</p> | |
<p><strong>How?</strong></p> | |
<pre><code>RḤÆfṀ€<7T Main Link. Takes n on the left | |
T Filter by | |
R Inclusive range | |
Ḥ Double each | |
Æf Prime factors | |
€ For each | |
Ṁ Maximum | |
<7 Less than 7 | |
</code></pre> | |
<p>My first serious jelly answer</p> | |
" | |
"92116","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>ṣ”(Ḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##7VjNbtw2EL77KQg0hZ0mu4kDtChycxPHMWDHge20PQQouBKlZSyRKkllvT31RXppX6IFeuuTpC/ifkNKWkq766RNblUOQaIlhzPfzHzz80YUxfLm5t0fv/398y97737/9ebm5pQbJxX75q8/nVPCsL39Rw/vPt5h/s@xkk7ygiW6LKVrPh6kKZtxKxNWGf1GJO33V1XKnWDnhwdPTw@nZRodNyIX10xXTmplGVcpy42oWKlTYZtjp8Lkgs0MV8mc7ZbcOmF2mc5YLt28nk2hwuNyVguv5QMjoDSPXrBVIZ0X2Hu2Kngihp/PYMthWbklywqeM6c33y60rsKJTJttshx@tksoWzJxzcuqiH@c1bJISb7R2rFUGoClzbI58cQIwuvk@Mnhi4sBYKlO6lIoxwkxkjBE9VS/Fe2Ltnsi00UqzMcjei7KIN/httC1bZ9CJFSy89kWjx9eAyrE1KPJCp37jHeA4P@Vx7TVf/ppYgDKwkEhyjxm6y57Jq@hRM4WEAiXJjpX0kqVbzpLIs9r2Ly//7BVdRr9BoRMwavowVPuoPhAxET49EHQTwqphI@oAYA9b0eaumWlI0mVkcqRsre8GCCs6qKAeT/Wwjr2GdTPjC7ZS6Nzw8tnZ98/MOXElVXf2/AS3CIpnvzxaWIpwT9FNGWcAh@q32cvwTfsePsvx5HBZV04aRFEok0/QinOemirXIQHh90xq2yJ0MvjE8ZnunbsKTTAK9/yohYHzhk5q534RJQEqwoxIUQbDTtWhaBSpJJU8@aBE21rzGzJ0qDUdAjFJGBBxGSn7Lvjl@9n3mTOVS4KnX8am2SutBEQC4wbtvGZXAljtUKlqG2L3islsyWTZGvm8zIDA2aZMGRksLoVXBR6wUp57WM76//YBOcJkTEVjssoyQHCPSYtU7hu59o4r8ve3Wl3d6HNFbMC2edkYkn4RRwynjn9mRkshi2eFzy@m6D1Cjx5fvDi6PDk7GhwYsAUffWtLkUALa1Ra5LA6yEEG40GtAE7lUVVEqaLEu9ytpdqYdWuI6ibwroU7m7rX34lBne9fQ3h4fQHG/bEh85AGOIJDiCokoJb@75E87RMJGRrSPDuOSclpg3fxhGOwPJnbcSADcdWFBklcV334AUsQgjDf0qryazQyRUdkqqq1xuVDLQXYoE0UGLR8b0kXw2514PY71n85ct@KUHpIEwXhkxDaG2yrKVxKNaAEyl3RzFhE14JX8BXDIeaCYWuN6Zsc2y3j/vQd96CifX6MjcXLaV4R1MlnpSeLpO5FG/DCV1V2sqO/LYI9nVIFonRi0Ba9cw66UCa1mNLJS4TIrW3i3muXQZk6MapVvr2wy/grxlPriwibh6Rva2ryghrqfDLgrzfvr6iIBfC73LSZxxYQVGwFs0k9nISefm8cW/42MFnfGoYYGcsLyKpu3p3JYMt5hI@k8oK42xAGX8ZMJK73eR@dhJMPa08s/PK1YZYpUbEeDgaVxA8vQhqemGQ@Qq6bWd95Nz57J6P@Pjba58rS9bOBhdEaYDfmTqBIgQ/6UlG9qRX3NiuJ/VRP1Wb3ve3W6PAiLmbx4WnJNqEO2dizt9KXYe6c@eLLTh6T/USbgtDHQkUOl5I29RVQic3uq7CnNKld9UZA0s/vpgSL/iigG7UUpU0Oq0TVFbwBEGIcHTrYxfKbGgiG3U@j8cVibMhCUNX6CM@Hhf8CViZgxFh5Vk8jq1QsKjxMkOJUq5YRtoG5szBk62oLpsqigvKp/ACZHeJRbZFXSpRxgJT6FBvunNEIyEpc4BifdTOh@sWUnpFNYlw2HRwywTQJvSFH/lCQ9Vmdc@qc8HxBX9RZP8kjG66NIEYoEDqHW5qZXh4Lfd@8DoHAHyUd7RjqD3oEciK3jTJakLRN@QX3ZTKUCQwTXb@2RLbw6T4kF9aarzQxs8avSj67/G@hef8PGb0lVCBpxNuY0emZslMrVpQBsk@7G2bXr6p3AS0pZ5wjfnB2sr7XNMTEsr36H/9QrnKp8g/sK820E0h@GslMWwNWpQWynARXYB4DB3bBlBE1Y1yesIX3IhbmPm849rY9J1mgXOoUr@9@apb3hC2JTdXqV4oysLNo0B/VPzy6xBqQCgVDs1B8aAimyb7feih8JVtuhYdVwnf76MqU3C78AENWUC7dv6fSCOT@3mXyAExhDxDDFG9oYALaxJg6ltWmCx4uZZmocyTAq8V@ZubtKBOAHKQ8Q6@L5srL2lo9rKo117rFGw0bw2SKXDHBTnvksChVhO@ojhtih3c3b9DSfOvLgyI7MPutk31GtmvOmfMIgotL8tg7sZbEf3Z4YFwYp2ON5/2h6OwXj/m69zqrKe0du7dC5NRbWgshNNTTaNNhWy8O5QQWvmVnDCm7ay2Goj@LvjD3JVuXWrsEAdE56kbbbotv3UZ16LjWnRci45r0XEtOq5Fx7XouBYd16LjWnRci45r0XEtOq5Fx7XouBYd16LjWnRci45r0f/ZWvQf"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>My first Jelly answer!</p> | |
<p><strong>How?</strong></p> | |
<pre><code>ṣ”(Ḣ - Main Link. Takes a string X on left | |
ṣ - Split X on the occurrences of | |
”( - Literal "(" | |
Ḣ - Head | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 18 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ŒĠạⱮ§ỊSʋÐṀ⁸$€ẎŒṬ¬a | |
</code></pre> | |
<p>A monadic Link that accepts a list of list of positive integers and yields a list of lists of non-negative integers (<code>0</code> representing the unclued cells).</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///opCMLHu5a@GjjukPLH@7uCj7VfXjCw51Njxp3qDxqWvNwV9/RSQ93rtE@tCbx////0dGGOgoQZKajYA5BsToKIGEjMDKDI6gwRMYUjkDCpkgCxjoKJkAEErbQUYAjY4gMSNhSRwGCLCBKQcKxAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///opCMLHu5a@GjjukPLH@7uCj7VfXjCw51Njxp3qDxqWvNwV9/RSQ93rtE@tCbx/9HJD3cuftS479A2INz6cPeWMKAKIDrcnv@oYa5epGYWVPL/f3V19RguQxDgMjQyMjLkAnOMuYxBgMsYKGTEBZMHCxkaG5nASCMIaQQiQYqMQIpQSEOIgUBDkCWMoRJQA03ABhqDSEOwgYYwY03Aus3Mzc1BrjMDApASUyDgAhFAnVwWQADUy2VpaWlhYmIC9A8A"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>ŒĠạⱮ§ỊSʋÐṀ⁸$€ẎŒṬ¬a - Link: list of lists, A | |
ŒĠ - group multi-dimensional indices by their values | |
€ - for each group (a list of coordinates, G, where one of the values are): | |
$ - last two links as a monad, f(G): | |
⁸ - using G as the right argument... | |
ÐṀ - filter G keeping those [a,b] which are maximal under: | |
ʋ - last four links as a dyad, f([a,b], G) | |
Ɱ - map across G with: | |
ạ - absolute difference (vectorises) | |
§ - sums (-> Manhatten distances) | |
Ị - insignificant? (0 or 1?) | |
S - sum | |
Ẏ - tighten to a list of coordinates (of the blanks in the puzzle) | |
ŒṬ - multi-dimensional untruth | |
¬ - logical NOT (vectorises) | |
a - logical AND with A (vectorises) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 20 </s> 19 <a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ØDṗ2ḣ“ð<‘Œpj€”:ðṙiḢ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##ATYAyf9qZWxsef//w5hE4bmXMuG4o@KAnMOwPOKAmMWScGrigqzigJ06w7DhuZlp4bii////MjM6NTk"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Surprisingly tricky to get anything below 22 in Jelly, no time-based functionality while parsing, evaluating and then adding leading zeros where needed is expensive, so I went with constructing all strings as a list and getting the next string cyclically.</p> | |
<pre><code>ØDṗ2ḣ“ð<‘Œpj€”:ðṙiḢ - Link: characters, S | |
ØD - digit characters -> "0123456789" | |
ṗ2 - Cartesian power 2 -> ["00",...,"99"] | |
“ð<‘ - list of code-page indices -> [24, 60] | |
ḣ - head to -> [["00",..."23"],["00",...,"59"]] | |
Œp - Cartesan product -> [["00","00"],...,["23","59"]] | |
j€”: - join each with colons -> ["00:00",...,"23:59"] | |
ð - start a new dyadic chain, f(Times, S) | |
i - first 1-indexed index of S in Times | |
ṙ - rotate Times left by that | |
Ḣ - head | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>r/Ḋ€p/)ẎQL | |
</code></pre> | |
<p>A monadic Link that accepts a list of rectangles each composed of a list of opposing corner coordinates as specified.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/79I/@GOrkdNawr0NR/u6gv0@f//f3R0tLGOeaxOtKWOcSyQirbQMTQA0oYmOiaxsbEA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Constructs the coordinates of a corner of each unit square of each rectangle, and counts the unique values found in the resulting collection.</p> | |
<pre><code>r/Ḋ€p/)ẎQL - Link: integer rectagle corner coordinates, R | |
) - for each rectangle, r in R: | |
/ - reduce by: | |
r - inclusive range | |
Ḋ€ - dequeue each (we exclude one edge, consistently, from each dimension, as we | |
want "fences", rather than "fence-posts") | |
/ - reduce by: | |
p - Cartesian product -> all the coordinates we want for the rectangle | |
Ẏ - tighten -> all coordinates used by all rectangles | |
Q - deduplicate | |
L - length | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>*)P | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/19LM@C/zuH2rEcNcxR07RQeNczVjPz/3wIA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>*)P - Main link. Takes n on the left | |
) - Over each integer 1 ≤ i ≤ n: | |
* - Raise i to the power i | |
P - Product | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 29 28 27 </s> 25 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Probably not the right tool for the job.</sup></p> | |
<pre><code>Zż€Ẏ€ | |
×þ`Dz€⁶Z€ç”|K€ç”-ZY | |
</code></pre> | |
<p>A full program that accepts a positive integer and prints the formatted multiplication table.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/q6J5HTWse7uoDklyHpx/el@BSBWQ@atwWBaQOL3/UMLfGG8bSjYr8//@/kQEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Zż€Ẏ€ - Link 1: transpose & insert chars: list of lists, M; character, C | |
Z - transpose M | |
ż€ - zip each with C | |
Ẏ€ - tighten each | |
×þ`Dz€⁶Z€ç”|K€ç”-ZY - Main Link: integer N | |
` - use N as both arguments of: | |
þ - table using: | |
× - multiplication | |
D - covert to decimal digits (vectorises) | |
€ - for each (list of digit lists): | |
z ⁶ - transpose with filler of a space character | |
Z€ - transpose each | |
ç”| - call last Link (1) as a dyad, f(that, pipe charater) | |
K€ - join each with space characters | |
ç”- - call last Link (1) as a dyad, f(that, dash charater) | |
Z - transpose | |
Y - join with newline characters | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ṣm0m2 | |
</code></pre> | |
<p>A monadic Link that accepts a list of positive integers and yields a list of positive integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hzkW5BrlG////jzbRUTDUUTDSUTAGk5Y6CkARMzDbIhYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ṣm0m2 - Link: list of positive integers, F | |
Ṣ - sort F | |
m0 - append the reverse (m is overloaded to do this when given 0) | |
m2 - modulo-2 slice (get every other value) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 44 <a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>s€3;"3/Ẏ;;ZFs9ƲQ€ƑȧZṙ3;"Ɗ;"`IƲȦȧḊm3FƊ⁺ĠƊṁ€Ƒ2 | |
</code></pre> | |
<p>A monadic Link that accepts a list of twenty-seven length six lists of integers that yields <code>1</code> if valid or <code>0</code> if not.</p> | |
<p>The input is a list of the twenty-seven columns starting with one adjacent to a bold border and reading around the strip, where each column reads in the same order as every other such that it starts at one edge of the Mobius-strip then reads one side followed by the other with wrapping (at the other edge of the Mobius-strip).</p> | |
<p><strong><a href=""https://tio.run/##TZEtbgMxEIWvYgVbqvy3trU8UmFpViuVlEQpCipM4IJIhWVFDQkKSoIra6@xuYhjz4zXYfY3fvOeZ9Yfm81XjNv7/qTahXqZboe2XS23PpzfEgvf43E1XX9SLQzt4v01nMe/8Thdhk@1DMN9d/v/DcN03cFbGWPsOs2Z5MxzJjiznDU9Z10DR8OZg4rKTMBNAU4CnVkCSd4ASBWRmQGJhA6p6DJTc3eQ@8zwpou1zMxDWUCz1NtmJssNnUxms6mF146y2GJtamYDco/ymmX@myZfDYC6Uj4JAOMYmot/Go2k/2JLDOUpMwZWGJG0dXjkgaa2zECR1j9FbOrfyICyiJIPbVyd3zztkg9Vru4NX7iykrIPXRaZl9D3Dw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>It's a long chain so I'll break it down...</p> | |
<pre><code>s€3;"3/Ẏ;;ZFs9ƲQ€Ƒ - are all nonets, columns, and rows distinct sets?: columns | |
s€3 - split each column into threes | |
3/ - three-wise reduce by: | |
;" - zipped concatenation | |
Ẏ - tighten -> the eighteen nonets | |
; - concatenate with the twenty-seven columns | |
Ʋ - last four links as a monad, f(columns): | |
Z - transpose | |
F - flatten | |
9 - nine | |
s - split (flatten result) into slices of lenth (9) | |
-> the eighteen rows | |
; - (nonets & columns) concatenate (rows) | |
Q€Ƒ - is invariant under deduplicate-each? | |
-> 1 if all nonets, columns, and rows are distinct sets | |
else 0 | |
ȧZṙ3;"Ɗ;"`IƲȦ - ...and there are no adjacent cells which are equal? | |
(note that the distinct sets check performed earlier automatically | |
checked rows & columns. Rows get checked again here as it is golfier) | |
Ʋ - last four links as a monad, f(columns): | |
Z - transpose -> the six half-Mobius-strip-rows on the "front" and "back" | |
Ɗ - last three links as a monad, f(half-Mobius-strip-rows): | |
3 - three | |
ṙ - rotate (half-Mobius-strip-rows) left by (3) | |
;" - zipped concatenation -> full-Mobius-strip-rows | |
;"` - zipped concatenation with itself (to cater for row-wise wrapping) | |
I - incremental differences ([b-a, c-b, ...] for each) | |
ȧ - (current check result) logial AND (that) | |
Ȧ - non-empty and contains no 0 when flattened? | |
-> 1 if all nonets, columns, and rows are distinct sets | |
AND no adjacent cells are equal | |
else 0 | |
ȧḊm3FƊ⁺ĠƊ - ...if so get the middles of all nonets grouped by values, otherwise 0 | |
Ɗ - last three links as a monad, f(columns): | |
Ɗ - last three links as a monad, g(columns): | |
Ḋ - dequeue | |
m3 - modulo-3 slice | |
F - flatten | |
⁺ - repeat -> g(that result) -> middles of all nonets | |
Ġ - group indices by value | |
ȧ - (current check result) logial AND (that) | |
-> those groups if all nonets, columns, and rows are distinct sets | |
AND no adjacent cells are equal | |
else 0 | |
ṁ€Ƒ2 - ...and the groups (or the 0 we have instead) are all length 2? | |
Ƒ - is invariant under: | |
ṁ€ 2 - mould each like [1,2] | |
-> 1 if a valid fill of an empty Mobius-strip-Sudoku | |
else 0 | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>19</s> <s>13</s> 12 bytes</h1> | |
<pre><code>OZ%3;ƲḂŒgẎ§Ṁ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/98/StXY@timhzuajk5Kf7ir79Dyhzsb/j/cveXhjq6HO6cdbtf8/19dXZ1LAQhqFMAAxtYFAjRxXV1tXV1kNRhsoFk6CjADFZAUaCOxFbCwERqB1tYgW42FAVesC9GsWwMCMB6yG2og2mrgtnFpg/yljaSoRluXS1e7BqwPAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input as a list of lines/a character matrix</p> | |
<p><s>First attempt, can probably be improved by a lot.</s> Ports <a href=""https://codegolf.stackexchange.com/a/235802/66833"">wasif's Vyxal answer</a> for the conversion to <code>1</code>/<code>0</code> matrices, so make sure you drop them an upvote as well.</p> | |
<p>-1 byte thanks to <a href=""https://codegolf.stackexchange.com/users/53748/jonathan-allan"">Jonathan Allan</a>!</p> | |
<h2>How it works</h2> | |
<pre><code>OZ%3;ƲḂŒgẎ§Ṁ - Main link. Takes a matrix M on the left | |
O - Convert each character to an ordinal | |
Ʋ - Last 4 links as a monad f(ord(M)): | |
Z - Transpose | |
%3 - Mod by 3 (|,+ -> 1, space -> 2, - -> 0) | |
; - Concatenate to ord(M) | |
Ḃ - Mod each 2 (1 -> 1, 45, 43 -> 1, 32, 124, 2, 0 -> 0) | |
Œg - Over each list, group adjacent equal elements | |
Ẏ - Drop into a list of lists | |
§ - Sums of each (lists of 0 -> 0, lists of 1 -> length) | |
Ṁ - Maximum | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>ṛ+⁵ðx’ß@ƒ>2¥ðỊ? | |
</code></pre> | |
<p><a href=""https://tio.run/##DcqhDoJAGAfwzlP8ow4MMhMBeRXAAz7HPhh3DK5p0hltzmCyUwzOJpvvwb3IyX71txdlqS1x3SoZgD1oD71DGRgkQSwpZ8oojVkF0G7vVKoQTUdSzHu1xkIjrWoScolG7NpUINEw51MEqeJGEefoSBXg0LfT@@6a42scenO4jY/odw3973Mcps9la63dzPw/"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Writing a 3-argument program in Jelly is hard, though at least we need to use one of them only once in this problem. So this program takes three arguments in the order of <code>n y x</code> and recurses as a dyadic function. Roughly a hybrid of <a href=""https://codegolf.stackexchange.com/a/235779/78410"">this Ackermann solution</a> with <a href=""https://codegolf.stackexchange.com/a/215427/78410"">user's APL answer</a>.</p> | |
<h3>How it works</h3> | |
<pre><code>ṛ+⁵ðx’ß@ƒ>2¥ðỊ? Main program as a dyadic link. | |
Left = n, Right = y, 3rd arg (⁵) = x | |
A..ðB.......ðC? If C then A else B | |
Ị If n <= 1 | |
ṛ+⁵ Then y + x | |
x’ß@ƒ>2¥ Else... | |
x’ y copies of n-1 | |
ß@ƒ>2 Reduce with the program itself flipped, with | |
the default value being n>2 (1 or 0) | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>+‘ð;x’ß@ƒ1ðỊ? | |
</code></pre> | |
<p><a href=""https://tio.run/##AS8A0P9qZWxsef//K@KAmMOwO3jigJnDn0DGkjHDsOG7ij//M8W7w6fDvjEwxbvCpFpH/w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Again uses <a href=""https://codegolf.stackexchange.com/a/40172/78410"">proud haskeller's approach</a>: <code>A(m+1,n)</code> is <code>A(m,?)</code> applied <code>n+1</code> times to 1.</p> | |
<p>The base case should've been simply <code>A(0,n) = n+1</code>, but unfortunately it (the code at the bottom) times out badly, so I had to use <code>A(m,n) = m+n+1 if m <= 1</code> instead.</p> | |
<h3>How it works</h3> | |
<pre><code>+‘ð;x’ß@ƒ1ðỊ? Dyadic link. Left = m, Right = n | |
AAðBBBBBBBðC? If C, do A; otherwise, do B | |
Ị If m <= 1... | |
+‘ Return m+n+1 | |
;x’ß@ƒ1 Otherwise do this: | |
;x Concatenate m to n copies of m (which gives n+1 copies of m) | |
’ Decrement each number (n+1 copies of m-1) | |
ƒ1 Reduce with seed 1... | |
ß@ This function, args swapped (since new m is on the right side) | |
</code></pre> | |
<hr /> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes, times out on A(3,9)</h1> | |
<pre><code>;x’ß@ƒ1ð‘}ḷ? | |
</code></pre> | |
<p><a href=""https://tio.run/##ASwA0/9qZWxsef//O3jigJnDn0DGkjHDsOKAmH3huLc//zPFu8Onw741xbvCpFpH/w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 20 </s> 19 bytes</h1> | |
<p><sup>There is probably* a terser way to swap the items...</sup></p> | |
<pre><code>’RŒBF!‘œ?@ƒ⁹Ƒ | |
ṗçƇR{ | |
</code></pre> | |
<p>A dyadic Link that accepts the number of balls, <span class=""math-container"">\$n\$</span>, on the left and the number of moves, <span class=""math-container"">\$m\$</span>, on the right and yields a list of lists of valid move sequences using 0-indexing.</p> | |
<p><strong><a href=""https://tio.run/##AS4A0f9qZWxsef//4oCZUsWSQkYh4oCYxZM/QMaS4oG5xpEK4bmXw6fGh1J7////NP82"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Filters all length <span class=""math-container"">\$m\$</span> potential instructions consisting of the alphabet <span class=""math-container"">\$[1,n]\$</span> keeping those which cause no change when applied.</p> | |
<p>In order to perform a single instructed swap the code translates this to an equivalent sequence of swaps of adjacent elements. The swaps are then applied in turn starting with an ordered list where the rightmost element is the first index and the leftmost is the last.</p> | |
<p>To swap the <span class=""math-container"">\$k^{\text{th}}\$</span> element with the <span class=""math-container"">\$1^{\text{st}}\$</span> we actually perform multiple swaps of neighbouting pairs, first to move the <span class=""math-container"">\$1^{\text{st}}\$</span> element to position <span class=""math-container"">\$k\$</span> and then to move the original <span class=""math-container"">\$k^{\text{th}}\$</span> element to to position <span class=""math-container"">\$1\$</span></p> | |
<p>For example starting with elements <code>GFEDCBA</code> (A being the "first") to swap the sixth element (<code>F</code>) with the first (<code>A</code>) we swap like so:</p> | |
<pre><code>(indices): 7654321 | |
start: GFEDCBA moving A from index 1... | |
swap(2,1): GFEDCAB . | |
swap(3,2): GFEDACB . | |
swap(4,3): GFEADCB . | |
swap(5,4): GFAEDCB . | |
swap(6,5): GAFEDCB done, now moving F to index 1... | |
swap(5,4): GAEFDCB . | |
swap(4,3): GAEDFCB . | |
swap(3,2): GAEDCFB . | |
swap(2,1): GAEDCBF done. | |
</code></pre> | |
<p>This is then performed by noting that <code>swap(n,n-1)</code> can be performed by calculating the <span class=""math-container"">\$((n-1)!+1)^{\text{th}}\$</span> lexicographical permutation of the current state (which I wrote a built-in for a few years ago, <code>œ?</code>).</p> | |
<pre><code>’RŒBF!‘œ?@ƒ⁹Ƒ - Link, is transform an invariant?: instruction string, [1..n] | |
’ - decrement (each instruction) e.g. [4,1,3] -> [3,0,2] | |
R - range -> [[1,2,3],[],[1,2]] | |
ŒB - bounce -> [[1,2,3,2,1],[],[1,2,1]] | |
F - flatten -> [1,2,3,2,1,1,2,1] | |
! - factorial -> [1,2,6,2,1,1,2,1] | |
‘ - increment -> [2,3,6,3,2,2,3,2] | |
-> this is an equivalent set of instructions swapping neighbouring pairs in | |
turn, as lexicographical permutation indices. | |
⁹ - right argument = [1..n] | |
Ƒ - is invariant under?: | |
ƒ - apply the new instructions to [1..n] in turn using: | |
œ?@ - nth index-lexicographical permutation | |
ṗçƇR{ - Main Link: n, m | |
ṗ - (n) Cartesian power (m) -> all length m strings of alphabet [1..m] | |
R{ - range (n) -> [1..n] | |
Ƈ - filter (the strings) keeping those for which: | |
ç - call last Link (1) as a dyad, f(potential_string, [1..n]) | |
</code></pre> | |
<hr /> | |
<p>* Although this is 20:</p> | |
<pre><code>J=o⁸ɗḊ⁹;ị⁸ | |
ṗçƒ⁹Ƒ¥ƇR{ | |
</code></pre> | |
<p><sup>10 bytes to swap to list elements by index; perhaps Jelly should have a <code>œ.</code> built-in to swap elements of a list by indices?</sup></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 16 </s> 12 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<p><sup>I thought 16 seemed a bit much!</sup></p> | |
<pre><code>Zµ=Ɱ×ṙ"N»/)Z | |
</code></pre> | |
<p>A monadic Link that accepts a list of lists of integers and yields a list of lists of integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/q0FbbRxvXHZ7@cOdMJb9Du/U1o/7//x8dbaCjAERGYNIwVkchGsIzBCMDkIAxTAVMAKIFimJjAQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Zµ=Ɱ×ṙ"N»/)Z - Link: matrix, M | |
Z - transpose -> columns of M (top to bottom) | |
µ ) - for each (c in columns of M): | |
Ɱ - map (across v in c) with: | |
= - (c) equals (v)? (vectorises) | |
× - multiply by (c) (vectorises) | |
-> [c with zeroed out non-v's for each v in c] - call this X | |
N - negate (c) | |
" - (X) zip (negated c) with: | |
ṙ - rotate left by | |
/ - reduce by: | |
» - maximum (vectorises) | |
Z - transpose -> back to rows | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>c€ŻFċ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATUAyv9qZWxsef//Y@KCrMW7RsSL/yzDh2rigJwgLT4g4oCdKVn//zIsNCw2LDEwLDI4LDIwLDEyMA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>c€ŻFċ - Main link. Takes n on the left | |
Ż - Range from zero; [0, 1, ..., n] | |
€ - Over each integer 1 ≤ i ≤ n: | |
c - Calculate iCr for each r in [0, 1, ..., n] | |
F - Flatten | |
ċ - Count occurrences of n | |
</code></pre> | |
" | |
"78850","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ŻcŻ$€Fċ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o7uSju1UeNa1xO9L9//9/MwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A port of my Vyxal answer, and contains part of my <a href=""https://codegolf.stackexchange.com/a/235665/78850"">Jelly answer</a> to the "vanilla" pascal triangle generation.</p> | |
<p>(yes, this is the exact same as caird's answer but with an extra atom and quick because fgitw reasons)</p> | |
<h2>Explained</h2> | |
<pre><code>ŻcŻ$€Fċ # A monadic chain with argument n. Let the current value be λ | |
Ż # λ = [0, n] | |
€ # over each item in λ: | |
cŻ$ # yield item choose [0, item] (vectorising) | |
F # flatten that | |
ċ # and get the count of n | |
</code></pre> | |
" | |
"78850","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ḶcŻ$€K€Y | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjm3JR3erPGpa4w3Ekf///7cEAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Mmm yes the output format here really do be fun tho - 5 bytes for the triangle generation, and 3 for the formatting.</p> | |
<h2>Explained</h2> | |
<pre><code>ḶcŻ$€K€Y # A monadic chain with argument n. Let the current value be λ | |
Ḷ # λ = [0, n) | |
€ # over each item in λ: | |
cŻ$ # yield item choose [0, item] (vectorising) | |
K€ # join each sublist on spaces | |
Y # and join that on newlines | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 11 10 </s> 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<p>-1 using <a href=""https://codegolf.stackexchange.com/a/235642/53748"">ovs's observation</a>.</p> | |
<pre><code>;Ɲẇ€ṣ1ẈṀ‘ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/62NyHu9ofNa15uHOx4cNdHQ93NjxqmPH//3/1goz8kvzkjNTczOKSokr1/@qlQJEcMBsA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<hr /> | |
<h4>10 byter</h4> | |
<pre><code>Ẇ;ƝẇƇ¥ÐḟṪL | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hrjbrY3Mf7mo/1n5o6eEJD3fMf7hzlc/////VCzLyS/KTM1JzM4tLiirV/6uXAkVywGwA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ẇ;ƝẇƇ¥ÐḟṪL - Link: A, B | |
Ẇ - sublists of A (from shortest to longest) | |
Ðḟ - filter discard those for which: | |
¥ - last two links as a dyad, f(substringOfA, B): | |
;Ɲ - length 2 sublists of substringOfA | |
Ƈ - keep those (pairs) for which: | |
ẇ - is this pair a sublist of B? | |
Ṫ - tail -> longest uncommon substring | |
L - length | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>ẆẆḊƇẇ€SʋÐḟẈṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hrjYQ2tF1rP3hrvZHTWuCT3UfnvBwx/yHuzoe7mz4f3i50v//SgUZ@SX5yRmpuZnFJUWVSjoKSokIAOcmwblJiQio9F@pFKg/B6ETTCZBFSoBAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>ẆẆḊƇẇ€SʋÐḟẈṀ - Main link. Takes A on the left, B on the right | |
Ẇ - All contiguous substrings of A | |
ʋÐḟ - Keep substrings S for which the dyadic link f(S, B) is 0: | |
Ẇ - Substrings of S | |
ḊƇ - Remove singleton lists | |
€ - Over each substring: | |
ẇ - Is B a contiguous substring? | |
S - Sum | |
ẈṀ - Get the maximum length | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>r1)⁺⁺Fị@ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/IUPNR4y4gcnu4u9vh/@H2R01r/v83MgAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Because it is extremely cumbersome to produce infinite output in Jelly, it instead applies countdown 3 times to the input's range and outputs the input-th item. The part without indexing (6 bytes) ties with <a href=""https://codegolf.stackexchange.com/a/235530/78410"">05AB1E's equivalent</a>.</p> | |
<pre class=""lang-none prettyprint-override""><code>r1)⁺⁺Fị@ Monadic main link. Input = n | |
r1) [x,x-1..1] for each number x (autorange) | |
⁺⁺ Do the above; do the above (no autorange) | |
Fị@ Flatten and get the nth item | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>fØ(µO-*ĬṖk | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/t8AyNQ1v9dbUOtxxa83DntOz/h9sjNbMeNe7j4vr/X0lDQ0NTM0VTSUcBwgQhDTDS1ISIZmikauRo5mjma2qUa@RrFmnmaKQAmZoZGokaJZoaxZqlmgVKAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>The Footer just runs all the test cases, joins each cluster by a single newline and each test case by 2.</p> | |
<h2>How it works</h2> | |
<pre><code>fØ(µO-*ĬṖk - Main link. Takes a string S on the left | |
fØ( - Remove all non-"()" characters | |
µ - Use this string of parentheses P as the argument from here: | |
O - Convert to ords ("(" -> 40, ")" -> 41) | |
-* - Raise -1 to that power, yielding "(" -> 1, ")" -> -1 | |
Ä - Cumulative sum | |
¬ - Logical NOT, converting 0 -> 1, everything else -> 0 | |
Ṗ - Remove the trailing 1 | |
k - Split P at the indices of the 1s | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>An OP accepted, but somewhat rule-bending, 13 byter since all the integers are now wrapped in lists - so it only works if we may assume any truthy/falsey operator will vectorise - that can be fixed for 1 byte for a different 14 to my original, e.g. add <code>F</code>.)</sup></p> | |
<pre><code>M_5+Ṡ$×<¥ⱮḊ;0 | |
</code></pre> | |
<p>A dyadic Link that accepts the opponent classification on the left and the number of turns to play on the right and yields a list of wrapped integers (non-zeros are truthy in Jelly, while zeros are falsey).</p> | |
<p><strong><a href=""https://tio.run/##ASwA0/9qZWxsef//TV81K@G5oCTDlzzCpeKxruG4ijsw////J2RldGVjdGl2ZSf/NQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/9833lT74c4FKoen2xxa@mjjuoc7uqwN/h9erv@oaU3io4a5kflAwi/rUeM@Lq7//6Oj1dOLSlPSU4vUdRSMY7l0otVTUktSk0syy1KBIqZgkcSc8sTK4uSM1MQSoJg5slh@fkFqUWIJSK2lJVgiOb@gMhlJIbJxJliMs4TqQzjDMJYrFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>There are, for the purpose of our choices, only three classes of opponent here:</p> | |
<ol> | |
<li>If we face <code>alwayscheat</code> or <code>alwayscooperate</code> we should always cheat</li> | |
<li>If we face <code>grudger</code> or <code>copycat</code> we should cooperate until our penultimate turn and then cheat on our final turn.</li> | |
<li>If we face <code>detective</code> we should cooperate from the fourth turn (if it is not our last turn) until our penultimate turn and then cheat on our final turn.</li> | |
</ol> | |
<pre><code>M_5+Ṡ$×<¥ⱮḊ;0 - Link: opponent, turns | |
M - maximal indices | |
-> alwayscheat:[5] alwayscooperate:[5] grudger:[3] copycat:[4] detective:[8] | |
^ ^ ^ ^ ^ | |
_5 - subtract five | |
-> alwayscheat:[0] alwayscooperate:[0] grudger:[-2] copycat:[-1] detective:[3] | |
+Ṡ$ - add the sign of that (call this "category") | |
-> alwayscheat:[0] alwayscooperate:[0] grudger:[-3] copycat:[-2] detective:[4] | |
Ɱ - map (across turn in [1..turns]) with: | |
¥ - last two links as a dyad, f(category, turn) | |
< - (category) less than (turn)? | |
× - (category) multipied by (that) | |
Ḋ - dequeue | |
;0 - concatenate a zero | |
</code></pre> | |
<hr /> | |
<p>14: <code>OḢ%4C×4×<¥ⱮḊ;0</code></p> | |
<p>And another 14: <code>OḢ%4ȯ7B¤Ṭo¥@’ṁ</code></p> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>ZṢ€Z | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/q4c5Fj5rWRP0/uSDscPv/6GhDHQMdQx0IaRCrE22gYwBhgyCQD5MHQ7A8TLUhVN4Qrt4wNhYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A monadic link which takes a 2d array of booleans.</p> | |
<pre><code>Z # Transpose | |
€ # For each | |
Ṣ # Sort | |
Z # Transpose back | |
</code></pre> | |
" | |
"42248","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 37 bytes</h1> | |
<pre><code>ŒJ§ị3ṗ2$’’A§ĠịƲḊ;\¤+"Ʋf€$œị⁸§ṁ,+¥=3o/ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///oJK9Dyx/u7jZ@uHO6kcqjhplA5Hho@ZEFQLFjmx7u6LKOObREW@nYprRHTWtUjk4GCj9q3AHUsrNRR/vQUlvjfP3///9HRxvqKBiAEZBhGKvDpQASMYSJGIBF4AoMkEQMcegCCcbGAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A monadic link taking and returning a 2D list of 0 and 1.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>20</s> 15 bytes</h1> | |
<pre><code>ị“???7ȷ%Ñ£¡‘&\Ƒ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///h7u5HDXPs7e3NT2xXPTzx0OJDCx81zFCLOTbx/@F2zcj//6MNdUx0zIDQQMcgVkch2kjHUMcIKGSuYw7imupYAKEBQtZAxwiZawxUagrjmgJ1wRQDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-5 bytes thanks to <a href=""https://codegolf.stackexchange.com/users/3852/lynn"">Lynn</a>!</p> | |
<h2>How it works</h2> | |
<pre><code>ị“???7ȷ%Ñ£¡‘&\Ƒ - Main link. Takes a list of integers on the left | |
“???7ȷ%Ñ£¡‘ - Integer list; [63, 63, 63, 55, 26, 37, 16, 2, 0] | |
ị - For each i in the input, get the ith element of the list | |
Ƒ - Is the list of numbers unchanged when doing: | |
\ - Scan by: | |
& - Bitwise AND | |
</code></pre> | |
<p>We can avoid having to convert to binary by using bitwise AND instead of logical AND. By scanning a column (treating the numbers as binary) with a zero bit "hole" with AND, it'll overwrite it as a <code>1</code>, thus changing the number represented. If there are no holes, none of the numbers will change.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>L’cŻ$⁼ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/nUcPM5KO7VR417vl/uP3opIc7Z2hG/v8fzRVtGKsDJHSMdKAMYyCEMk11DA1AyBQmYKZjaKpjZAAizWBi5jpGQE2mIGQE4oGFjSByQGNBDAMdEyA0gFtkgLDNCGibCdACM5jlphALQW7gigUA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>As each row of Pascal's triangle has a unique length <span class=""math-container"">\$n\$</span>, all we have to do is reconstruct the row, given its length, and check if it equals the original input. As each row is given by <span class=""math-container"">\$\binom{n-1}{i}, 0 \le i < n\$</span>, we just calculate that (as Jelly has a 1 byte for binomial coefficient)</p> | |
<p>In fact, if we can take the length of the input as a second input, we can get <a href=""https://tio.run/##y0rNyan8//9Rw8zko7tVHjXu@a/jc3i5g77m///RXNGGsTpAQsdIB8owBkIo01TH0ACETGECZjqGpjpGBiDSDCZmrmME1GQKQkYgHljYCCIHNBbEMNAxAUIDuEUGCNuMgLaZAC0wg1luCrEQ5AauWAA"" rel=""noreferrer"">5 bytes</a></p> | |
<h2>How it works</h2> | |
<pre><code>L’cŻ$⁼ - Main link. Takes a list L on the left | |
L - Length of L | |
’ - Decrement | |
$ - Last 2 links as a monad f(len-1): | |
Ż - Range from 0 to len-1 | |
c - Binomial coefficient of len-1 and each element in the range | |
⁼ - Does that equal the input? | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>Ḣ€Oị2¦“×+ _÷”V | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjkWPmtb4P9zdbXRo2aOGOYenayvEH97@qGFu2P/D7UcnPdw5QzPy//9oLs5ocx0F9cSUFHUdBYtYHSDfEsgvycxNLQaK6BqBhYxMgGIpmWWZKalAQYgYSCg3M68UpMwUKBILAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input as e.g. <code>[7, 'add', 8]</code>. Requires no leading <code>0</code> for floats (e.g. <code>-.5</code> instead of <code>-0.5</code>)</p> | |
<h2>How it works</h2> | |
<pre><code>Ḣ€Oị2¦“×+ _÷”V - Main link. Takes a list [l, op, r] | |
Ḣ€ - First of each. | |
O - Convert to ordinal | |
2¦ - To the element at the 2nd index (the op): | |
ị “×+ _÷” - Index into the string “×+ _÷” | |
V - Evaluate as Jelly | |
</code></pre> | |
<p>For example, consider <code>[7, 'add', 8]</code>. Getting the <code>Ḣ</code>ead of a number leaves it as is in Jelly, so <code>Ḣ€</code> turns this into <code>[7, 'a', 8]</code>. We then get the char code of each. Again, <code>O</code> leaves numbers as they are, so this maps it to <code>[7, 97, 8]</code>. We then change only the second element by indexing into <code>“×+ _÷”</code>. Jelly indexing is modular, so we get the <span class=""math-container"">\$97 \bmod 5\$</span>th element of this list (i.e. the second, or <code>+</code>). This yields <code>[7, '+', 8]</code>, which we then concatenate into a string <code>7+8</code> and evaluate as Jelly.</p> | |
<p>Consider:</p> | |
<div class=""s-table-container""> | |
<table class=""s-table""> | |
<thead> | |
<tr> | |
<th style=""text-align: center;"">Input operator</th> | |
<th style=""text-align: center;"">First character</th> | |
<th style=""text-align: center;"">Ordinal</th> | |
<th style=""text-align: center;""><span class=""math-container"">\$\bmod 5\$</span></th> | |
<th style=""text-align: center;"">Index into <code>“×+ _÷”</code></th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td style=""text-align: center;""><code>add</code></td> | |
<td style=""text-align: center;""><code>a</code></td> | |
<td style=""text-align: center;"">97</td> | |
<td style=""text-align: center;"">2</td> | |
<td style=""text-align: center;""><code>+</code></td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;""><code>times</code></td> | |
<td style=""text-align: center;""><code>t</code></td> | |
<td style=""text-align: center;"">116</td> | |
<td style=""text-align: center;"">1</td> | |
<td style=""text-align: center;""><code>×</code></td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;""><code>minus</code></td> | |
<td style=""text-align: center;""><code>m</code></td> | |
<td style=""text-align: center;"">109</td> | |
<td style=""text-align: center;"">4</td> | |
<td style=""text-align: center;""><code>_</code></td> | |
</tr> | |
<tr> | |
<td style=""text-align: center;""><code>divide</code></td> | |
<td style=""text-align: center;""><code>d</code></td> | |
<td style=""text-align: center;"">100</td> | |
<td style=""text-align: center;"">0</td> | |
<td style=""text-align: center;""><code>÷</code></td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
<p>Note that <code>0</code> maps to <code>÷</code> as 1-indexed modular indexing means that <code>0</code> is the last element</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ZŒPZ€Ṁ€€i | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/q6KSAqEdNax7ubACSQJT5//BypaOTHu6cAeRE/v8fHW2oY6RjHKsTbaRjCKaNgXzD2FgdBWQpY6AQSAoogiyFzPwPVAZWrgBmGIEZIMIgFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Outputs <code>0</code> for falsey, non-zero for truthy</p> | |
<p>-3 bytes thanks to <a href=""https://codegolf.stackexchange.com/users/68942/hyper-neutrino"">hyper-neutrino</a>!</p> | |
<h2>How it works</h2> | |
<pre><code>ZŒPZ€Ṁ€€i - Main link. Takes a list of inputs I on the left and outputs O on the right | |
Z - Transpose I | |
ŒP - Powerset of the columns | |
Z€ - Transpose each | |
€ - Over each column powerset: | |
Ṁ€ - Get the maximum of each column | |
i - Index of O in this list of lists, or 0 if not found | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>ḢeØc‘⁾anḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjkWph2ckP2qY8ahxX2Lewx2L/z/cveXQ1oc7Fz9qmGsFlD7crhn5/39iZlFBTmJeqpVCYh5XeWJJahGQxVWcl5gNEuLKqEwqykwBsTLTc/LzwarCHUNcg0BCnuk5/v5gIY/8ULC@0jzPstSiYIhplfmlIR5AFgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>The footer simply extracts the test case from the <code>:</code> separated string</p> | |
<h2>How it works</h2> | |
<pre><code>ḢeØc‘⁾anḣ - Main link. Takes a string S on the left | |
Ḣ - Extract the first character of S | |
Øc - Yield vowels; "AEIOUaeiou" | |
e - Is the first character in that string? Yield 1 if so, else 0 | |
‘ - Increment, yielding 2 for vowel-starting strings, 1 otherwise | |
⁾anḣ - Take that many characters of the string ⁾an | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 33 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>ṣ”[Ṗ€ṣ€”;VṆ€k$ḟ0;ɗ"Ẏɗ/j”;ḟ0Ø[j”f; | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields a list of characters.</p> | |
<p><strong><a href=""https://tio.run/##hVA7EoIwEO09hmOv/HXePZxxdiilQC5g51BoZ6k2joUtpYVoScUxwkViEgIiIqbYfZ/d7CbhMorWnLP0WmzOxNJDESeSxIngmLN0K@BqxO6XCfLjkD32@XEcSk9K2YkkDsDZ85btROmC84AMfyACymjKVMfKM2FVoM6kJMAA3oDMJoYF@4N/UcBViqFjNbpEekRNRKe@oSURnF8yueizyOt3oR/cPB0KVct26qSI/be/XUcOXHiYYiYXVN9ZLub5Lw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ṣ”[Ṗ€ṣ€”;VṆ€k$ḟ0;ɗ"Ẏɗ/j”;ḟ0Ø[j”f; - Link: list of characters, S | |
ṣ”[ - split (S) at '[' | |
Ṗ€ - pop (i.e. remove ']' from) each | |
ṣ€”; - split each at ';' | |
V - evaluate as Jelly code | |
-> list of projections with zeros at empty slots | |
/ - reduce by: | |
ɗ - last three links as a dyad, f(P, Q): | |
$ - last two links as a monad, f(P): | |
Ṇ€ - logical NOT each | |
k - partition (P) after truthy indices (of that) | |
-> P split after each empty slot | |
" - zip (across [t in that] and [q in Q]) with: | |
ɗ - last three links as a dyad, f(t, q): | |
0 - zero | |
ḟ - (t) filter discard (zeros) | |
; - concatenate (q) | |
Ẏ - tighten (to a flat list) | |
j”; - join with ';' | |
ḟ0 - filter discard zeros | |
Ø[j - "[]" join (that) | |
”f; - 'f' concatenate (that) | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <sup><s>13</s></sup> 9 bytes</h1> | |
<pre><code>;0+HBU_/U | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/aQNvDKTReP/T/4fZHTWv@/zfVMdcxNDICYmMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-4 bytes (<code>^/&$</code> removed) thanks to @m90's observation that we don't need to clear shared 1 bits.</p> | |
<p>Look ma, no Unicode!</p> | |
<p>Literal translation of Prodinger's algorithm. x3 goes before xh, and <code>U</code> is used twice to align the binary representations of the two.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 29 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>Feels clunky to me at present.</sup></p> | |
<pre><code>ZḢiȧị¥⁸0ị | |
;1ịç@ɗ¥⁹ḊḊʋḊȦ$¡ƬẠƇṪ | |
</code></pre> | |
<p>A dyadic Link that accepts the initial word on the left and the production rules (<span class=""math-container"">\$P\$</span>) on the right and yields the result.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/q4Y5FmSeWP9zdfWjpo8YdBkAGl7UhkDy83OHkdJDYzoc7uoDoVDeQOLFM5dDCY2se7lpwrP3hzlX/Dy@PcnvUtMbw0LKoY121//@rJyUmqv@PjlZPVNdRUEpOTkr0UIrVUYhWT4LwEyG8ZAhPKTYWAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (Each production rule is <code>[chr, [chr, ...]]</code>, but a list of these cannot be passed as an argument to a program so the footer translates them from a list of <code>[[chr], [chr, ...]]</code>)</p> | |
<h3>How?</h3> | |
<pre><code>ZḢiȧị¥⁸0ị - Link 1, get new characters (or zero): rules, R; character, C | |
Z - transpose (R) | |
Ḣ - head -> alphabet | |
i - first 1-indexed index of (C) in (alphabet) or, when C=Halt, zero | |
¥⁸ - last two links as a dyad, f(I=that, R) | |
ị - (I) index into (R) | |
ȧ - (I) logical AND (that) -> relevant rule or zero | |
0ị - tail -> new characters or zero | |
;1ịç@ɗ¥⁹ḊḊʋḊȦ$¡ƬẠƇṪ - Link: initial word, W; rules, R | |
Ƭ - collect up, starting with W, while no duplicates found with: | |
¡ - repeat... | |
$ - ...number of times: last two links as a monad, f(current): | |
Ḋ - dequeue | |
Ȧ - has elements and none are zero (found when processing a halt) | |
ʋ - ...what: last four links as a dyad, f(current, R) | |
⁹ - right argument, R | |
¥ - last two links as a dyad, f(current, R) | |
ɗ - last three links as a dyad, f(current, R) | |
1 - one | |
ị - index into (current) -> head character | |
ç@ - call Link 1 as a dyad, f(R, character) | |
; - (current) concatenate (that) | |
Ḋ - dequeue | |
Ḋ - dequeue | |
Ƈ - keep those for which: | |
Ạ - all truthy (are not the result of processing a halt) | |
Ṫ - tail | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>÷5CPC×5 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wdlPnAOfD003///8fbaxjGAsA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><span class=""math-container"">$$ | |
5\times(1-\prod_{i=1}^n 1-{x_i \over 5}) | |
$$</span></p> | |
<p>Read this from right to left to get the Jelly code. The formula is derived from the same sympy output as the 05AB1E answer. This has a nice symmetry to it as <code>C×5</code> is the inverse of <code>÷5C</code>.</p> | |
<hr /> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<p>Port of my Python answer</p> | |
<pre><code>+_×÷5ɗɗ/ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/187/vD0w9tNT04/OV3/////0aY6hrEA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 18 13 </s> 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>ḲẈṣ0H«1§ĊS | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields an integer.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjk0Pd3U83LnYwOPQasNDy490Bf9/uHvL4fZHTWv@/9clALjQ@AqYChTw6VcAKVAgoABEKuA1AZ8bFLA4UgHTkQr43AFVoAsA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Jimmies can't help if the gap is greater than one, so the result is the sum of Jimmies required for each section after partitioning at such gaps. In each section, we need one Jimmy per platform minus one Jimmy for every two length-one platforms, since then Jimmies can share the load of these and any intermediate platforms.</p> | |
<pre><code>ḲẈṣ0H«1§ĊS - Link: list of characters, P | |
Ḳ - split at spaces | |
Ẉ - length of each -> lengths of platforms with zeros between sections | |
ṣ0 - split at zeros -> list of section platform lengths | |
(potentially including phantom empty sections) | |
H - halve (vectorises) | |
«1 - minimum with one (vectorises) | |
§ - sums | |
Ċ - ceiling (vectorises) | |
S - sum | |
</code></pre> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>21</s> <s>20</s> 19 bytes</h1> | |
<pre><code>OḂŒrµ=1EƇṣØ0Ẉ:2SạSḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9//4Y6mo5OKDm21NXQ91v5w5@LDMwwe7uqwMgp@uGth8MMdi/4/3L3lcPujpjX//@sSAFxofAVMBQr49CuAFCgQUAAiFfCagM8NClgcqYDpSAV87gAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>This may or may not be an incredibly stupid way to do it.</p> | |
<p>Based on the following observation: the best way is to use one Jimmy per platform, unless there are two platforms of length 1 such that all spaces between them are also length 1, in which case they can be connected by Jimmies, saving one Jimmy.</p> | |
" | |
"42248","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>b⁹Ọ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/pUePOh7t7/v//b1BhZmyWBoTJRslGBmapZpZAvikA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Same as <a href=""https://codegolf.stackexchange.com/a/235201/42248"">@emanresu’s Vyxal</a> answer but in Jelly, so be sure to upvote that one too!</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>+;_ɗJ;⁸1ḟ1#; | |
1Ç¡Ḣ | |
</code></pre> | |
<p>A full program that accepts a non-negative integer, <span class=""math-container"">\$n\$</span>, and prints the sequence element at that (0-indexed) index.</p> | |
<p><strong><a href=""https://tio.run/##ASYA2f9qZWxsef//KztfyZdKO@KBuDHhuJ8xIzsKMcOHwqHhuKL///83MA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Keeps the natural numbers (i.e. 1-indexed row indices) in a list (initially <code>[1]</code> (well, <code>1</code> but Jelly :D)) and repeatedly finds the first row in which a queen may be placed in the next column by counting up from 1 until a number is reached that is not on an any, thus far, occupied row, leading diagonal, or trailing diagonal.</p> | |
<pre><code>+;_ɗJ;⁸1ḟ1#; - Link 1, prefix with next element: list (current elements in reverse), E | |
J - range of length -> [1,2,...,length(E)] | |
ɗ - last three links as a dyad - f(E, J(E)): | |
+ - add (vectorises) -> occupied trailing diagonal row indices | |
_ - subtract (vectorises) -> occupied leading diagonal row indices | |
; - concatenate these together | |
;⁸ - concatenate E | |
1 1# - start with 1 and count up, collecting the first 1 that are truthy under: | |
ḟ - filter discard -> singleton list containing the next available row index | |
; - concatenate E -> a new, slightly longer, list of elements in reverse | |
1Ç¡Ḣ - Main Link: non-negative integer, n (0-indexed) | |
1 - start with 1 | |
Ç¡ - repeat Link 1 n times | |
Ḣ - head of the resulting list | |
</code></pre> | |
" | |
"42248","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 21 bytes</h1> | |
<pre><code>+L}Rṗ⁸;€b1ZƑ$Ƈ | |
0ç1#Ḣç | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/1/bpzbo4c7pjxp3WD9qWpNkGHVsosqxdi6Dw8sNlR/uWHR4@X@dw@1HJz3cOQMonfWoYY6Crp3Co4a5XIfbgQKR//9Hc0UbxupwRRuBCGMQYaijABGB0sYIPpIQjGkCZhohmDBRIAIbZwpmIqk1RDUPxOOKBQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A full program taking a list of integers as its argument and printing the shortest list satisfying the requirements. The TIO link includes all test cases.</p> | |
<h2>Explanation</h2> | |
<h3>Helper link</h3> | |
<p>Left argument is the number of additional digits to prepend, right argument is the original list</p> | |
<pre><code>+ | Add: | |
L} | - Length of original list | |
R | Range 1..this | |
ṗ⁸ | Cartesian power with number of new digits | |
;€ | Prepend each to the original list | |
b1ZƑ$Ƈ | Convert to unary and test whether unchanged by transposition | |
</code></pre> | |
<h1>Main link</h1> | |
<pre><code>0ç1# | Starting with zero, identify how many additional digits are needed to make the list meet the requirements | |
Ḣ | Head | |
ç | Then call the helper link again one last time | |
</code></pre> | |
<hr/> | |
<h1>An alternative <a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a> answer uses less brute force, 21 bytes</h1> | |
<pre><code>b1S+⁹ḣɗⱮṀŻ$;€⁸b1ZƑ$ƇḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/JMFj7UePOhzsWn5z@aOO6hzsbju5WsX7UtOZR444kw6hjE1WOtT/csei/zuH2o5Me7pwBlMl61DBHQddO4VHDXK7D7UCByP//o7miDWN1uKKNQIQxiDDUUYCIQGljBB9JCMY0ATONEEyYKBCBjTMFM5HUGqKaB@JxxQIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"42248","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 bytes</h1> | |
<pre><code>Ṁ×3Rḟḟ+;_ɗJ$Ṃ; | |
1Ç¡Ḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzobD042DHu6YD0Ta1vEnp3upPNzZZM1leLj90MKHOxb9///fyAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A full program taking a zero-indexed n as the argument and printing the relevant term.</p> | |
<p><a href=""https://tio.run/##y0rNyan8///hzobD042DHu6YD0Ta1vEnp3upPNzZZM1leLj9UeOOQwsf7lj038jg4Y5tQH7Tmv8A"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Here’s the first twenty terms</a> with a slightly modified pair of links that can be passed an argument from within (rather than always using the command line argument).</p> | |
<h2>Explanation</h2> | |
<h3>Helper link - extend sequence z</h3> | |
<pre><code>Ṁ | Max | |
×3 | Times 3 | |
R | Range (1..this) | |
ḟ | Filter out existing sequence members z | |
ḟ $ | Filter out values guven by the following applied to the current sequence: | |
+;_ɗJ | - z plus indices of z concatenated to z minus indicies of z | |
Ṃ | Min | |
; | Concatenate existing sequence z | |
</code></pre> | |
<h3>Main link</h3> | |
<pre><code>1Ç¡ | Starting with 1, call the helper link the number of times indicated by the argument | |
Ḣ | Head | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 6 bytes</h1> | |
<pre><code>²×¥þœi | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLCssOXwqXDvsWTaSIsIjM2w4figqxVRyIsIiIsW11d"" rel=""noreferrer"">Try It Online!</a></p> | |
<p>TFW <a href=""https://codegolf.stackexchange.com/a/83815/78410"">you outgolf Dennis by 33%</a> :P</p> | |
<p>Outputs <code>[b, a]</code>.</p> | |
<p>This does not use any prime factorization built-ins. Instead, it uses an array-oriented built-in <code>œi</code> (multi-dimensional index of), which is interestingly not found in any of APL/J/K/BQN.</p> | |
<h3>How it works</h3> | |
<pre class=""lang-none prettyprint-override""><code>²×¥þœi Monadic link. Input: the positive integer n. | |
²×¥þ Compute the table of (x^2 * y) for both x and y in 1..n | |
For n = 3, this returns: | |
× | 1 4 9 | |
--+-------- | |
1 | 1 4 9 | |
2 | 2 8 18 | |
3 | 3 12 27 | |
œi Find the multi-dimensional index of n in the matrix above | |
[3, 1] | |
</code></pre> | |
<p>Since it finds the first occurrence in the matrix, <code>b</code> (first index) is guaranteed to be minimized, and <code>n</code> always appears at least once in the matrix at the coordinates <code>[n, 1]</code>.</p> | |
" | |
"42248","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 bytes</h1> | |
<pre><code>²2*×!!ŒṗQƑƇfƑƇɗÐḟ²€ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///QJiOtw9MVFY9OerhzeuCxicfa00DEyemHJzzcMf/QpkdNa/7jkeMyNTjc/v@/EQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A monadic link taking an integer <code>n</code> as its argument and returning a list of integers. Implements @Bubbler’s method for determining the upper bound, so be sure to upvote that one too! While this answer would end in a finite time, it would be a very very long time even for n=2, and requires a huge amount of RAM (enough to generate integer partitions of <span class=""math-container"">\$3072!\$</span>). I’ve therefore included a footer on TIO which demonstrates that the rest of the code works for integers up to 50.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>22</s> 20 bytes</h1> | |
<pre><code>Ṗ+<¬Ṫɗ+%"24ɓṣ”:f€ØDV | |
</code></pre> | |
<p><a href=""https://tio.run/##TY0xCsJAEEX7OcUiWAVxZzarZhErzxDwAFqIB9BObOwV1MYqRUBSiUWCncEix1gvss5uLKz@nzf/zyznq9XGOVudovGrsNWtOUfdDsXN0VbZZ3s1i8@uqC/T1P3m1M852PJuy4zqvP8@2OoC9vmo97yaOaeN0mK9NrEWvYnQrICJQfIM0TOSbEAb1AIjpiokB6yAZJRsKQaKMRsYGUqECpQCJTYQ@6zvy/aTkkDK6MQzGT5JVkC/EaT/6kNf5yOyzY4CVGy@"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes the time as <code>[hh, mm]</code> on the left and the <code>xx</code> string on the right.</p> | |
<p>-2 bytes thanks to <a href=""https://codegolf.stackexchange.com/users/3852/lynn"">Lynn</a> by a clever exploitation of Jelly's vectorising atoms!</p> | |
<h2>How it works</h2> | |
<p>This uses the <code>ɓ</code> chaining structure to group a series of links to act only on the string, then we run the main links on the result of those links and on <code>[hh, mm]</code>. The <code>ɓ</code> splits the program into two links: <code>Ṗ+<¬Ṫɗ+%"24</code> and <code>ṣ”:f€ØDV</code>. The first one is dyadic (as two arguments are passed to the program), and the second one is dyadic but with the arguments in the opposite order as the first.</p> | |
<p>For a program that consists of two dyadic links <code>x (f g) y</code>, we calculate <code>x f (x g y)</code>. Non-notationally, this means that we run the second dyad on the two arguments, returning a value <code>z</code>. We then run the first dyad with <code>x</code> on the left and <code>z</code> on the right. The standard way of writing this would be <code>f ð g</code>. Using <code>ɓ</code> however, we reverse the arguments to <code>g</code>, so <code>f ɓ g</code> is <code>x f (y g x)</code>.</p> | |
<p><code>g</code> is <code>ṣ”:f€ØDV</code>, run dyadically with the string <code>S</code> on the left and the time <code>T</code> on the right. <code>g</code> consists of 5 atoms: <code>ṣ</code>, <code>”:</code>, <code>f€</code>, <code>ØD</code>, <code>V</code>, which can be grouped into <code>ṣ”:</code>, <code>f€ØD</code>, <code>V</code>, a series of dyad-nilad pairs and a monad. This means that the right argument to the link is essentially ignored, and only the left argument is modified. We could try to use a monadic link for this, but by reversing the arguments implicitly with <code>ɓ</code>, we can avoid any quicks to indicate that a monadic link should be run on <code>S</code>.</p> | |
<p><code>g</code>, given <code>S</code>, extracts the offset and minutes from the string, returning <code>[offset, mins]</code> as a pair of integers. <code>f</code> is then run as a dyadic link, with <code>T</code> (the time) on the left and <code>[offset, mins]</code> on the right.</p> | |
<p><a href=""https://codegolf.stackexchange.com/users/3852/lynn"">Lynn</a> noticed a clever exploitation of Jelly's vectoriser that allows us to save 2 bytes here. Essentially, if we have a list and an integer, <code>[a, b] + x</code> will vectorise across that list, yielding <code>[a+x, b+x]</code>, and if we have two lists <code>[a,b,c] + [x,y]</code>, we'll get <code>[a+x,b+y,c]</code>. The <code>"</code> (<em>vectorise</em>) quick will take a dyad <code>h</code> and force this behaviour.</p> | |
<p>Therefore, if we want to apply a dyad to just the first element of a list, we can use <code>"</code> and turn the right argument into a singleton list. For example: <code>[a, b] +" x ⁼ [a+x, b]</code>. Here, we calculate whether or not the <code>mins</code> is already past the current <code>minutes</code> of <code>T</code>. If so, we add <code>1</code> to <code>hours</code>. Therefore, we remove <code>minutes</code> from <code>T</code>, yielding <code>[hours]</code> and add this to the comparison, to yield <code>[hours + (mins ≥ minutes)]</code>. We then add this to <code>[offset, mins]</code>, to yield <code>[hours + (mins ≥ minutes) + offset, mins]</code>. Finally, we use <code>"</code> on <code>%24</code> so that we only modulo the first element by 24.</p> | |
<h3>How it works, in detail</h3> | |
<pre><code>Ṗ+<¬Ṫɗ+%"24ɓṣ”:f€ØDV - Main link. Takes [h, m] on the left and S on the right | |
ɓṣ”:f€ØDV - Dyadic chain with S on the left, [h,m] on the right: | |
ṣ”: - Split S on ”: | |
€ - Over each half: | |
f ØD - Only keep digits | |
V - Evaluate each as integers, [a, b] | |
Ṗ+<¬Ṫɗ+%"24ɓ - Links to the left as a dyadic chain g([h,m], [a,b]): | |
Ṗ - Pop; Yield [h] | |
ɗ - Last 3 links as a dyad f([h,m], [a,b]): | |
<¬ - [¬(h < a), ¬(m < b)] | |
Ṫ - ¬(m < b) | |
+ - [h + ¬(m < b)] | |
+ - [h + ¬(m < b) + a, b] | |
%"24 - [(h + ¬(m < b) + a) % 24, b] | |
</code></pre> | |
" | |
"106844","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ØAṄ4¡€* | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wDMeHO1tMDi181LRG6/9/AA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>Explanation</h2> | |
<pre><code>ØAṄ4¡€* | |
ØA: alphabet | |
Ṅ: print w/ new line | |
4¡: repeat 4 times | |
€: each | |
*: to error out(see below) | |
</code></pre> | |
<p>The reason I use the <code>*</code> is to error out the code so it wont print the whole alphabet at the end (I'm very new to jelly). If anyone can tell me what character to use in combination with <code>Ṅ</code> to achieve this, I would appreciate it!</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŒPS=¥ƇẈṂ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIBg20NLj7U/3NXxcGfT/8PLlSL//4821DHVMdcxBmMzIDYCkbE6CtGmQIZl7H9DAx0FQyMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Outputs <code>0</code> if there's no solution</p> | |
<h2>How it works</h2> | |
<pre><code>ŒPS=¥ƇẈṂ - Main link. Takes L on the left and n on the right | |
ŒP - Powerset of L | |
¥Ƈ - Keep those lists for which the following is true: | |
S - The sum... | |
= - ...equals n | |
Ẉ - Lengths of those kept | |
Ṃ - Minimum | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 41 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>“dÞ¦£‘Fd0¦¥ƒFJx$ȯWị“&ḍṘṭ.½6²EmSFʂ5ȥṙẠ»Ḳ¤K | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##AVcAqP9qZWxsef//4oCcZMOewqbCo@KAmEZkMMKmwqXGkkZKeCTIr1fhu4vigJwm4biN4bmY4bmtLsK9NsKyRW1TRsqCNcil4bmZ4bqgwrvhuLLCpEv///8xMzc"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>“dÞ¦£‘Fd0¦¥ƒFJx$ȯWị“...»Ḳ¤K - Link: non-negative integer, n | |
“dÞ¦£‘ - [100,20,5,2] | |
ƒ - reduce starting with n, using: | |
¥ - last two links as a dyad: | |
F - flatten i.e. n->[n] or [....,[q,r]]->[...,q,r] | |
d0¦ - divmod the tail by (the next divisor) | |
F - flatten | |
Jx$ - repeat indices - e.g. [0,3,2,2,0] -> [2,2,2,3,3,4,4] | |
W - wrap -> [n] | |
ȯ - logical OR (if n was 0 we now get [0] in place of []) | |
“...»Ḳ¤ - ["ale","mute","luka","tu","wan","ala"] | |
ị - index into (1-indexed and modular) | |
K - join with spaces | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>OIS | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/fM/j/oc2H2///9wAK5CuE5xflpCgCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A monadic link, I think.</p> | |
<p>Charcodes, deltas, sum.</p> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>⁹œc3P-Ƥ€§ṬCTḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/I4OjkZOMA3WNLHjWtObT84c41ziEPdyz@b2xwuB0o4v4fAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Monadic link that returns the first n terms. The leading <code>⁹</code> (constant 256) is necessary to get the correct output for n = 1 and 2 (otherwise the output is empty for those two inputs). The linked code has <code>⁹</code> replaced by <code>20</code> for demonstration purposes.</p> | |
<h3>How it works</h3> | |
<pre class=""lang-none prettyprint-override""><code>⁹œc3P-Ƥ€§ṬCTḣ Monadic link. Left arg = n, the number of terms | |
⁹œc3 3-combinations of 1..256 | |
P-Ƥ€§ ab+bc+ca for each row | |
ṬCT List of numbers in 1..max(above) that do not appear | |
in the above list | |
ḣ Take first n | |
</code></pre> | |
<p>In order to filter out all <code>ab+bc+ca</code> numbers before 1848, the input numbers should be at least:</p> | |
<ul> | |
<li>56 if you use "3-combinations of 1..(some fixed number)"</li> | |
<li>44 if you use "cumulative sums of 3rd cartesian power of 1..(some fixed number)"</li> | |
</ul> | |
<p>In both cases, the hardest one to filter out is <code>(5, 12, 56) → 1012</code>. The next hardest is <code>(8, 17, 51) → 1411</code>.</p> | |
<hr /> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 14 bytes</h1> | |
<pre><code>³œc3P-Ƥ€§2ȷR¤ḟ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASEA3v9qZWxsef//wrPFk2MzUC3GpOKCrMKnMsi3UsKk4bif//8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Full program that prints all 65 terms. This one finishes within a few seconds without modification.</p> | |
<h3>How it works</h3> | |
<pre class=""lang-none prettyprint-override""><code>³œc3P-Ƥ€§2ȷR¤ḟ Niladic chain. | |
³œc3 3-combinations of 1..100 | |
P-Ƥ€§ Compute ab+bc+ca for each row | |
2ȷR¤ḟ Filter out the above from 1..2000 | |
</code></pre> | |
" | |
"100664","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>2ȷœc3ṙ€1ḋƊḟ@R | |
</code></pre> | |
<p><a href=""https://tio.run/##ASEA3v9qZWxsef//Msi3xZNjM@G5meKCrDHhuIvGiuG4n0BS//8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>First Jelly answer! Prints all ideonal numbers.</p> | |
<p>Gosh this was painful. This <em>should</em> work given several terabytes of RAM and a couple of hours. To see, replace <code>2ȷ</code>(2000) with 20 or something.</p> | |
<p>-10 thanks to Dude coinheringaahing.</p> | |
<pre><code>2ȷœc3 # Combinations of 1..2000 of length 3 | |
ṙ€1ḋ # Calculate ab+ac+bc for each | |
Ɗḟ@ # Remove these from | |
2ȷ R # 1...2000 | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>“ÑṆ6Ẉ’Ds3ZU$Ƭ;U$ | |
</code></pre> | |
<p>A niladic Link that yields a list of eight lists of lists of digits, the eight magic squares.</p> | |
<p><strong><a href=""https://tio.run/##AS8A0P9qZWxsef//4oCcw5HhuYY24bqI4oCZRHMzWlUkxqw7VST/w4dH4oKsauKBvgoK/w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Builds one then constructs the other seven using rotations and reflections.</p> | |
<pre><code>“ÑṆ6Ẉ’Ds3ZU$Ƭ;U$ - Link: no arguments | |
“ÑṆ6Ẉ’ - base 250 literal = 276951438 | |
D - decimal digits -> [2,7,6,9,5,1,4,3,8] | |
s3 - split into threes -> [[2,7,6],[9,5,1],[4,3,8]] | |
Ƭ - collect up until a fixed point is found under: | |
$ - last two links as a monad - f=rotate(current): | |
Z - transpose - i.e. swap rows with columns | |
U - upend - i.e. reverse each row | |
$ - last two links as a monad - f=add_reflections(four_rotations): | |
U - upend - i.e. revese each row of each rotation | |
; - (four_rotations) concatenate (upended) | |
</code></pre> | |
<hr /> | |
<h4>Alternatives</h4> | |
<pre><code>⁽Xð×3Œ?s3ZU$Ƭ;U$ | |
</code></pre> | |
<pre><code>“=ẹʋ‘×3D‘ZU$Ƭ;U$ | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>22</s> 18 bytes</h1> | |
<pre><code>9Œ!i⁼ṛɗƇ5s€3§;SEƲƇ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATUAyv9qZWxsef//OcWSIWnigbzhuZvJl8aHNXPigqwzwqc7U0XGssaH/8OHR@KCrGrigb7CtsK2/w"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>The Footer simply formats the output into a nice column of grids, remove it to see the list of matrices</p> | |
<p>-4 bytes thanks to <a href=""https://codegolf.stackexchange.com/users/53748/jonathan-allan"">Jonathan Allan</a></p> | |
<h2>How it works</h2> | |
<pre><code>9Œ!i⁼ṛɗƇ5s€3§;SEƲƇ - Main link. Takes no arguments | |
9 - Set the left argument to 9 | |
Œ! - All permutations of [1,2,3,4,5,6,7,8,9] | |
ɗ 5 - Group the previous 3 links into a dyad f(p, 5): | |
i - Index of 5 in p | |
ṛ - Yield 5 | |
⁼ - Does the index of 5 equal 5? | |
Ƈ - Keep those permutations for which f(p, 5) is true | |
s€3 - Split each into a 3x3 matrix | |
ƲƇ - Keep those matrices for which the following is true: | |
§ - Sums of the rows | |
S - Sums of the columns | |
; - Concatenate | |
E - Are all equal? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 21 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>;1DṀ+ṂƊ+Ɗ€</¦⁻/пḢ€QL | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer and yields a positive integer (using the 1-indexed option).</p> | |
<p><strong><a href=""https://tio.run/##ATQAy/9qZWxsef//OzFE4bmAK@G5gsaKK8aK4oKsPC/CpuKBuy/DkMK/4bii4oKsUUz///8xNDk3"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>Perhaps there is a more terse approach, but I have not thought of one yet.</p> | |
<p>Starts with the input and <span class=""math-container"">\$1\$</span> and applies <span class=""math-container"">\$f\$</span> to the minimum of the two while they are unequal, then counts the number of values visited from the input to the final value.</p> | |
<pre><code>;1DṀ+ṂƊ+Ɗ€</¦⁻/пḢ€QL - Link: integer, x | |
;1 - concatenate a one | |
п - collect while... | |
⁻/ - ...condition: reduce by not-equal | |
€ ¦ - ...do: sparse application... | |
</ - ...to indices: reduce by less-than | |
Ɗ - ...action: last three links as a monad, f(v) | |
D - decimal digits | |
Ṁ+ṂƊ - minimum plus maximum | |
+ - add (v) | |
Ḣ€ - head each (all the values we got from x's side) | |
Q - deduplicate | |
L - length | |
</code></pre> | |
<hr /> | |
<h4>0-indexed alternative</h4> | |
<p>Also 21 bytes:</p> | |
<pre><code>;1DṀ+ṂƊ+Ɗ€</¦⁻/пnƝSḢ | |
</code></pre> | |
" | |
"42248","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>ṗŒP§QƑƊƇ¥1# | |
</code></pre> | |
<p><a href=""https://tio.run/##AR4A4f9qZWxsef//4bmXxZJQwqdRxpHGisaHwqUxI////zQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A monadic link taking and returning an integer. Terribly inefficient since it takes the powerset of the Cartesian power. Replacing <code>ṗ</code> with <code>œc</code> improves efficiency at the cost of a byte, but still very slow.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>10</s> 8 bytes</h1> | |
<pre><code>e€Ø[œpm2 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/1UdOawzOij04uyDX6//9/VWVFdHlsWXRpSXRxbFF0dGFBbHR2VmxmbHpabHRKbDQIJsdGJwGpxNhYAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> or <a href=""https://tio.run/##nZIxbsJAFET7PQVnyG2i0RR/vSyyIYnBYLDLNBwgTerUqRAFUkorB3EusvzFkSKl@2y10u7TzJ/51Xy16lKa/7x@Du/4fqufHtJ4OY2Xj@Hoxq/zcNSXx5TEFzPrUcYJPK2kFA5ix1TMo6DZpAPt002z8T7OF@BdehqmMZZfLoMmUqbqNM9gkgsTZnWZG8@bYovFZ7FskdEkFqf9Qoi07ReEGqbQgInIrfCAuCirJZ9f6jU3zRY7tMBeazl02k@vF/4r7gbo13bfu7476OcWuy0aboB1TSwrllxEImjgyF1pGvyzp0zblHIF"" rel=""noreferrer"" title=""Jelly – Try It Online"">see all test cases</a></p> | |
<p>Full program as we use Jelly' smash printing. Uses some tricks from <a href=""https://codegolf.stackexchange.com/a/233885/66833"">Jonah's J answer</a>, so be sure to upvote that as well!</p> | |
<p>-2 bytes thanks to <a href=""https://codegolf.stackexchange.com/users/42248/nick-kennedy"">Nick Kennedy</a>.</p> | |
<h2>How it works</h2> | |
<pre><code>e€Ø[œpm2 - Main link. Takes a string S on the left e.g. S = "a[b[c]d]e" | |
Ø[ - Builtin constant; Yield "[]" | |
€ - Over each character in S: | |
e - Is it a bracket? e.g. [0,1,0,1,0,1,0,1,0] | |
œp - Partition S at the truthy indices e.g. [['a'], ['b'], ['c'], ['d'], ['e']] | |
m2 - Take every second sublist e.g. [['a'], ['c'], ['e']] | |
Smash-print and return e.g. 'abc' | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 10 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>e€ØcTạⱮJṂ€ | |
</code></pre> | |
<p>A monadic Link that accepts a list of characters and yields a list of non-negative integers.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/1UdOawzOSQx7uWvho4zqvhzubgAL///9XKs7ILyhILVICAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>e€ØcTạⱮJṂ€ - Link: list of characters, S e.g. "shopper" | |
Øc - vowels "aeiouAEIOU" | |
€ - for each (c in S): | |
e - (c) exists in (vowels)? [0,0,1,0,0,1,0] | |
T - truthy indices [3,6] | |
J - range of length (S) [1,2,3,4,5,6,7] | |
Ɱ - map with: | |
ạ - absolute differences [[2,5],[1,4],[0,3],[1,2],[2,1],[3,0],[4,1]] | |
Ṃ€ - minimum of each [2,1,0,1,1,0,1] | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>ḷⱮ¡ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hju2PNq47tPD///8mAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Like Lynn's solution which heavily inspired this, a full program only.</p> | |
<pre><code> ¡ Repeat [input] times, starting with the input on the left and right: | |
Ɱ Produce an array containing, for every element of the right argument, | |
ḷ the left argument. | |
</code></pre> | |
<p>Although dyadic <code>¡</code>, rather than reusing its right argument, uses the previous left argument for each successive iteration, in this case either behavior would do the same thing--since each intermediate result has the same length as the (implicitly rangified) initial input.</p> | |
" | |
"42248","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>6</s> 5 bytes</h1> | |
<pre><code>ÇÐṀḊ¿ | |
</code></pre> | |
<p><a href=""https://tio.run/##AR0A4v9qZWxsef81WOKAmf/Dh8OQ4bmA4biKwr////8yNw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A monadic link taking <code>m</code> as its argument and expecting the blackbox function to be in the previous link (e.g. header on TIO). Thanks to @JonathanAllan for pointing this out as per <a href=""https://codegolf.meta.stackexchange.com/a/13707/53748"">this meta post</a> and also for saving a byte with a suggested switch to 1 indexing!</p> | |
<h2>Explanation</h2> | |
<pre><code> | Implicit range 1..m | |
Ḋ¿ | While list length > 1 (literally while the list with its first member removed is non-empty): | |
ÐṀ | - Take the list member(s) that are maximal when: | |
Ç | - The supplied function is run for each list member | |
</code></pre> | |
<hr/> | |
<p>If the function had to be provided as an argument, here is an alternative:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ṛ⁴V$ÐṀḊ¿ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASQA2/9qZWxsef//4bmb4oG0ViTDkOG5gOG4isK/////Mjf/NVjigJk"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A full program taking <code>m</code> and the Jelly code for <code>f</code> as its two arguments. If it’s mandatory to also take <code>n</code>, this can be provided as an (unused) third argument.</p> | |
<h2>Explanation</h2> | |
<pre><code> | Implicit range 1..m | |
Ḋ¿ | While list length > 1 (literally while the list with its first member removed is non-empty): | |
$ÐṀ | - Take the list member(s) that are maximal when: | |
ṛ⁴V | - The supplied function is run for each list member | |
</code></pre> | |
<hr/> | |
<h1>Previous answer: <a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 bytes</h1> | |
<pre><code>³lĊ⁵V¤€ḅʋ⁴¤<³¬$¿ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATQAy/9qZWxsef//wrNsxIrigbVWwqTigqzhuIXKi@KBtMKkPMKzwqwkwr////83Mv84/zhY4oCZ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A full program that takes <code>n</code>, <code>m</code> and the Jelly code for <code>f</code> as its arguments and prints the resulting random number to STDOUT.</p> | |
<h2>Explanation</h2> | |
<pre><code> <³¬$¿ | While not < m: | |
³ ʋ⁴¤ | - Do the following, taking m as the left argument and n as the right: | |
l | - m log n | |
Ċ | - Ceiling | |
⁵V¤€ | - Execute f that many times | |
ḅ | - Convert from base n | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>38</s> <s>35</s> 34 bytes</h1> | |
<pre><code>“SWCR”p“¬,ĖṆḷ⁸»Żṗ4XʋⱮ4ẸƇƊṆ¿o⁾--j”: | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw5zgcOegRw1zC4DMQ2t0jkx7uLPt4Y7tjxp3HNp9dPfDndNNIk51P9q4zuThrh3H2o91AaUP7c9/1LhPVzcLqM3q/38A"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>This <em>just</em> about finishes on TIO most of the time (it has a <span class=""math-container"">\$1\$</span> in <span class=""math-container"">\$33^{16}\$</span> chance of taking longer), taking around 55 seconds. Full program, as we require Jelly's smash-printing to get the correct output</p> | |
<p>-4 bytes thanks to <a href=""https://codegolf.stackexchange.com/users/53748/jonathan-allan"">Jonathan Allan</a>!</p> | |
<p>The first sample output I got was:</p> | |
<p><a href=""https://i.stack.imgur.com/jk18Ls.png"" rel=""nofollow noreferrer""><img src=""https://i.stack.imgur.com/jk18Ls.png"" alt=""generated shape"" /></a></p> | |
<p><a href=""https://viewer.shapez.io?SbSyRwWy.WwWgRyCg.RrScRuWc.WgCyRuCr"" rel=""nofollow noreferrer"">External link</a></p> | |
<h1>How it works</h1> | |
<pre><code>“SWCR”p“¬,ĖṆḷ⁸»Żṗ4XʋⱮ4ẸƇƊṆ¿o⁾--j”: - Main link. No arguments. Left argument = 0 | |
Ɗ - Group the previous 3 links into a monad f(_): (ignores the argument) | |
“SWCR” - Set the return value to “SWCR” | |
ʋ - Group the previous 4 links into a dyad g(“SWCR”, i): (ignores i) | |
“¬,ĖṆḷ⁸» - Compressed string: “rugbypcw” | |
p - Cartesian product with “SWCR” | |
Ż - Prepend a zero (represents “--”) | |
ṗ4 - 4th Cartesian power | |
X - Choose a random list | |
Ɱ4 - Yield [g(“SWCR”,1), g(“SWCR”,2), g(“SWCR”,3), g(“SWCR”,4)] | |
ẸƇ - Remove any that are just zeros | |
¿ - While: | |
Ṇ - The left argument is falsey ([] or 0) | |
Ɗ - Set the left argument to f(_) | |
o⁾-- - Replace all zeros with “--” | |
j”: - Join by ”: and smash-print | |
</code></pre> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22 bytes</h1> | |
<pre><code>ṬµØ0jḄ3Ƥị236B¤µ39СYo⁶ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATYAyf9qZWxsef//4bmswrXDmDBq4biEM8ak4buLMjM2QsKkwrUzOcOQwqFZb@KBtv///1szOCwzOV0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Took some inspiration from Erik's answer.</p> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>Ä2œPF_@\ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wi9HRyQFu8Q4x////jzbUMdIx0bHQMTTTMTbSMTPRMTSyiAUA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Based on the older approach below. <code>Ä</code> generates cumulative sums, and <code>2œPF</code> (ew) throws away the second one. Then <code>\</code> scanning by <code>_@</code> flipped subtraction gives:</p> | |
<pre><code> [a, | |
a+b+c-(a), | |
a+b+c+d-(a+b+c-(a)), | |
a+b+c+d+e-(a+b+c+d-(a+b+c-(a))), | |
...] | |
= [a, b+c, a+d, b+c+e, ...] | |
</code></pre> | |
<p>I feel like there has to be something shorter than <code>2œPF</code> to remove the 2nd element of a list.</p> | |
<h1>Jelly, <s>9</s> 8 bytes</h1> | |
<pre><code>Jḟ2b1^\ḋ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/LzsjZ@tDSmIc7uh7u6P7//3@0oY6CkY6CiY6ChY6CoZmOgjGQZwbkGhpZxAIA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Based on rak1507's observation that when the input is <span class=""math-container"">\$[a,b,c,d,e,f...]\$</span>, the answer is <span class=""math-container"">$$[a, ~~b + c, ~~a + d, ~~b + c + e, ~~a + d + f, \dots].$$</span></p> | |
<p>That is: cumulative sums of even and odd elements, but with the first two elements swapped.</p> | |
<p>That means we can calculate (<code>ḋ</code> is dot product, padding the shorter argument with 0s at the end):</p> | |
<pre><code>ḋ(input, [1]) = a | |
ḋ(input, [0, 1, 1]) = b + c | |
ḋ(input, [1, 0, 0, 1]) = a + d | |
ḋ(input, [0, 1, 1, 0, 1]) = b + c + e | |
ḋ(input, [1, 0, 0, 1, 0, 1]) = a + d + f | |
ḋ(input, [0, 1, 1, 0, 1, 0, 1]) = b + c + e + g | |
... | |
</code></pre> | |
<p>In this program, <code>Jḟ2b1^\</code> computes the triangle <code>[[1], [0,1,1], [1,0,0,1]…]</code> and <code>ḋ</code> takes dot products with the input.</p> | |
<p><code>Jḟ2</code> is <code>[1,3,4,5,…,n]</code>. <code>b1</code> generates lists of 1s of those lengths, and <code>^\</code> is a XOR scan.</p> | |
" | |
"95516","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>11</s> 10 bytes</h1> | |
<pre><code>-œ?UŒœÄZFḊ | |
</code></pre> | |
<p>Thank you very much to caird/Dude/ChartZ for helping golf this in TNB.</p> | |
<p>-1 thanks to Lynn!</p> | |
<p>Explanation:</p> | |
<p>I tried to look for a pattern that could be used to solve this more easily, so a quick <a href=""https://sagecell.sagemath.org/?z=eJyFj8sKgzAQRfeC_3C7MsGp0C4FvyS4iBofYG2Its3nd0ItLvpwVsO5986jMS3cIrzM4whcHgW8yvPjqXwBZ2ZGyismK3r0w2gwmoljOBQ4r9lQmlAR6jAls1crJH00m9kj5dEhghR1uQm8NNPWmqkRVVrL9yXLzU1B24xxNA7zIi7airt2hERXdWPark8kp6wbpkXwe2o9q_xKCc1PgWD-aYR2RyZ0-w5Cz6YneUllfw==&lang=sage&interacts=eJyLjgUAARUAuQ=="" rel=""noreferrer"">sage script</a> did the trick.</p> | |
<p>From that, we get the pattern</p> | |
<pre><code>[a, b + c] | |
[a, b + c, a + d] | |
[a, b + c, a + d, b + c + e] | |
[a, b + c, a + d, b + c + e, a + d + f] | |
[a, b + c, a + d, b + c + e, a + d + f, b + c + e + g] | |
[a, b + c, a + d, b + c + e, a + d + f, b + c + e + g, a + d + f + h] | |
</code></pre> | |
<p>From this, we can see it is an interleaved cumulative sum of [a, d, f, h...] and [b, c, e, g...]. Flipping a and b makes this nicer, [b, d, f, h...] and [a, c, e, g...].</p> | |
<pre><code>-œ?UŒœÄZFḊ | |
- -1 | |
œ? -1th ordered permutation, i.e. second-from-last. This will always be the array reversed with the last 2 elements swapped | |
U un-reverse | |
Œœ uninterleave | |
Ä cumulative sum | |
Z zip | |
F flatten | |
Ḋ tail | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/1/36GT70KOTjk4@3BLl9nBH1//D7Y@a1vz/H22oo2Cko2Acq6MAYuoCMRYKImukY6xjomOqY6ZjrmOhYwnVAtRtoqNgAVRpBjQHyDMDcg2NLKDSBhBjDMAmIXFiAQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 bytes</h1> | |
<pre><code>ḣ2S;ɗḢṄ$ḷ"ƊḊḊ$¿Ḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjsVGwdYnpz/csejhzhaVhzu2Kx3rergDhFQO7QeK/v//P9pQR8FAR0EXQqFyYgE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Blegh. Full program, outputs each on a separate line</p> | |
<h2>How it works</h2> | |
<pre><code>ḣ2S;ɗḢṄ$ḷ"ƊḊḊ$¿Ḣ - Main link. Takes a list L on the left | |
¿ - While: | |
$ - Condition: | |
ḊḊ - The list is non-empty after dequeuing twice | |
Ɗ - Body: | |
$ - Last 2 links as a monad f(L): | |
Ḣ - First element, X | |
Ṅ - Print and return | |
ɗ - Last 3 links as a dyad f(L[1:], X): | |
ḣ2 - First 2 elements | |
S - Sum | |
; - Concat with X | |
ḷ" - Replace the first 2 elements of L with this pair | |
Ḣ - Get the first element of the final pair | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>ṢU0Hƭ€S | |
</code></pre> | |
<p><a href=""https://tio.run/##ASQA2/9qZWxsef//4bmiVTBIxq3igqxT/8OHxZLhuZj//1syMCwxMF0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Based on <a href=""https://codegolf.stackexchange.com/a/233642/66833"">Adám's method</a>, so go upvote that as well</p> | |
<h2>How it works</h2> | |
<pre><code>ṢU0Hƭ€S - Main link. Takes a list L on the left | |
ṢU - Sort L in descending order | |
ƭ€ - Tie the previous 2 atoms, and alternate between the two for each element: | |
0 - At odd-indexed elements: Replace the element with 0 | |
H - At even-indexed elements: Halve the element | |
S - Sum | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, (26?) 27 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p><sup>26 if the result need not be flat (while still consistent) - remove trailing <code>F</code></sup></p> | |
<pre><code>iⱮ’“¡©“®¢‘xⱮj€12b4;,a"4,1ɗF | |
</code></pre> | |
<p>A dyadic Link that accepts the starting data stack in reverse on the left and the final data stack in reverse on the left and yields a list of integers:</p> | |
<pre><code>0 >r | |
1 r> | |
2 swap | |
3 dup | |
4 drop | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z/z0cZ1jxpmPmqYc2jhoZUgat2hRY8aZlQAxbMeNa0xNEoysdZJVDLRMTw53e3/4eUPd3cDVRXZAYni8sQCIJVSCiaL8kGUXdGjhrne//@nJCcl/k9MSk4BAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (Footer formats like the question does.)</p> | |
<p>Or see the <a href=""https://tio.run/##vVRNj9MwEL37Vww5pVJSCbhVaiUOCwcOe1m4VD24zoS1NtiW46i7Qvz2Mv5I0naTwsKKKKo/5703byY1T@5eq/fHY4U14COKzmHeOi4eChC6wsWKAT1hB9Zx3K52YdP2u9u4rrWFg7YVSBVil61ppMsThH9kHS@s15BVVptsPBpYlkabfDHsY3MW1E3HcGNQVVH4tny7m4tvD3wSwMcU/fTdbsiU5sV4YwZ0Yy8g7XNRMas5WXZzLSs7g9DiBS2XLcJX3nR4Y622eZ19UQ9KH1RgWsEPP/zMIgZvW7RuKKKvYpFWsbroOquiEsZ8ezhsneAt5ljXKNxZg@yRqo8F8NqhJfu@c0OJ29gCBcSI1BBZWWYpEWefxhx05yiyb8IeMZCEO/go0LjxvrFSEdodyYKaywarVdZTjT4FV1jqPk/xZh1VvhQo3fqknT8lpAsO@BAclVoF96Nn39A1UmH/Efg55SiV6Vxq8sM9EYaDJRkmqcahJU4aYiIoFcefMDaYGKHubHfSGDELCh@UDEfe2cmD6UKz6D/c3H4MCUYOQ33EWPLm9nO2OB457KEswQ@cbSzYDfjvDujjBVqGedxOO9fv0P9E/KFFeBlLDHvPwf4IJO5MYQn4d7QJecJDit6CE7gZ2BN4el@H3g9/Rf@yukzSV15ARZaK6y0QaSYE/kboueBZV65pO63OKwj4P2U@S4jeXw"" rel=""nofollow noreferrer"" title=""Python 3 – Try It Online"">Python suite of test results</a>.</p> | |
<h3>How?</h3> | |
<p>This builds the reverse of the final data stack in the return stack one item at a time by "copying" the item from the data stack, leaving the data stack unaffected, then it drops all of the original items from the data stack and pulls all the copied items back.</p> | |
<p>To "copy" an item it pushes all those above it, then repeatedly pulls and swaps so that all the original main items are back on the data stack with the required item on top, then duplicates and pushes and then performs the conjugate of everything before the duplication to get main back to how it started.</p> | |
<p>For example, to push <code>d</code> from <code>abcd...</code> (where <code>a</code> is on top):</p> | |
<pre><code>>r >r >r r> swap r> swap r> swap dup >r swap >r swap >r swap >r r> r> r> | |
</code></pre> | |
<p>...or</p> | |
<pre><code>(>r)*3 (r> swap)*3 (dup >r) (swap >r)*3 (r>)*3 | |
</code></pre> | |
<p>Where <code>3</code> is three because there are three items on top of <code>d</code>.</p> | |
<h5>Code breakdown</h5> | |
<pre><code>iⱮ’“¡©“®¢‘xⱮj€12b4;,a"4,1ɗF - Link: starting (reversed); final (reversed) | |
Ɱ - map with: | |
i - first index of (final item) in (starting items) | |
’ - decrement -> 0-based indices | |
“¡©“®¢‘ - code-page indices = [[0,6],[8,1]] | |
Ɱ - map with: | |
x - times - e.g. 3 -> [[0,0,0,6,6,6],[8,8,8,1,1,1]] | |
j€12 - join each with twelves | |
b4 - convert from base four | |
0->[0]; 6->[1,2]; 12->[3,0]; 8->[2,0]; 1->[1] | |
ɗ - last three links as a dyad - f(starting, final): | |
, - pair -> [starting, final] e.g. ["abc","ba"] | |
4,1 - [4,1] [4,1] | |
" - zip with: | |
a - logical AND [[4,4,4],[1,1]] | |
; - concatenate | |
F - flatten | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 25 24 23 </s> 21 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-1 thanks to <a href=""https://codegolf.stackexchange.com/users/42248/nick-kennedy"">Nick Kennedy</a>! (use of <code>)</code> to avoid repeated mapping)</p> | |
<p>-2 thanks to <a href=""https://codegolf.stackexchange.com/users/100664/emanresu-a"">emanresu A</a>! (Accuracy is only required to be within <span class=""math-container"">\$0.1\$</span>mm of the true value)</p> | |
<pre><code>ØQœi×4:3+ɗ\)ạ/×4.76ÆḊ | |
</code></pre> | |
<p>A monadic Link that accepts a list of two upper-case characters and yields a floating-point number.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///wjMCjkzMPTzexMtY@OT1G8@GuhfpAnp652eG2hzu6/v//7@gEAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8///wjMCjkzMPTzexMtY@OT1G8@GuhfpAnp652eG2hzu6/j/cvUXncLvKo6Y13kAc@f@/oxOXUyCXuzOXhxeXjxdXQARXZCQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<p>Finds horizontal and vertical distances measured in quarter-key lengths of <span class=""math-container"">\$\frac{19.05}{4} = 4.7625\$</span> then takes the norm of the vector (i.e. uses Pythagoras). Since <span class=""math-container"">\$4.76\$</span> is good enough* for requirements, that is used as the quarter-key length.</p> | |
<pre><code>ØQœi×4:3+ɗ\)ạ/×4.76ÆḊ - Link: characters, [A, B] | |
) - for each (c in [A, B]): | |
ØQ - Qwerty keyboard -> ["Q..P","A..L","Z..M"] | |
œi - first multi-dimensional index of c in Qwerty keyboard | |
×4 - multiply by four | |
-> [row(c)×4, column(c)×4] | |
\ - cumulative reduce by: | |
ɗ - last three links as a dyad: | |
3 - three | |
: - (row(c)×4) integer divide (3) i.e. 4->1; 8->2; 12->4 | |
+ - add (column(c)×4) -> [row(c)×4, column(c)×4+(row(c)×4:3)] | |
(i.e. quarter steps down and right from a point a quarter | |
left of the top-left of Q required to reach the bottom | |
right of each of [A, B]) | |
/ - reduce by: | |
ạ - absolute difference -> [vertical, horizontal] quarter steps | |
×4.76 - multiply by 4.7625 -> [vertical, horizontal] distances | |
ÆḊ - vector norm -> distance between keys | |
</code></pre> | |
<p>* <a href=""https://tio.run/##y0rNyan8///wjMCjkzMPTzexMtY@OT1G8@GuhfpAnp65mZHp4baHO7q4cKsAywNNcHy4c7rRoa2H24FShyfa6Blq/v8PAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Here</a> is a suite showing all values are within <span class=""math-container"">\$0.1\$</span>mm of the actual values - checking that all possible pairs using a quarter-key length of <span class=""math-container"">\$4.76\$</span> are within <span class=""math-container"">\$0.1\$</span> of those calculated using a quarter-key length of <span class=""math-container"">\$4.7625\$</span>. (All results are actually also within <span class=""math-container"">\$0.1\$</span>mm of Matt Parker's <span class=""math-container"">\$2\$</span> decimal place values - see <a href=""https://tio.run/##PZm7rutaFYb7/RQuaBCSiVeykhVEcxInseNLfIsvES0F6LwALQVHoqU4tLSICoF0gI4tCh5j8yKb/x//8GyWZuzpOcf4xnXO9etffvvtb75@/fzH9j9/@NXn73c/2/7kv9//4sdf/vmnn@JXfNh//t2XH37/9csPf/3336@fv8PzL//48/ijn8fJpy//@tvn7/732798/fpN9E20@fRNdIo@DvHHG0bn6D2J344YpdH2I0749sLRjqNr9H6Ik3eMbtFhH7/xWRYd3@M3Psuj5O0YH/nxPUqSXbzl@yJKttt4ywlllLy/aaUKc/HZB4Z1lGz28Y6fPaJk9xF/7DFsomR/iA8HDNsoOcb7HUZd9P4eHzjq@WzDRYfosI2PW4ye2DSJE645RvtjvOXEKXrbxh8JRnO03enZEh0hBpd@RW8JxTwBhBCcAIO/z67@CSCE5AQQe5D9wOjqa50AYl0hC6OcmKDxCRzWeUVYpXTZToCw7lG7OicgOLzFBz5roo9jvONubXT8oF4nAtjE@y1GfVhliHZ4xpWf0W5HFCfov643RR@b@LjHaHbjnaC/DHqC/jLjGfpLvjP0l1RnMODf1PU6Q3/tdIb@67Oba3iG/usKuUt@hv6S8gz9xfdML5C9zwCwbl@7cGf6wOYQbzizMSfZJBi2jv4MBBL@DATr1oMrfgYC4TsHBGcgELQzEKzPFjfRGQikbgoE6@jkqqRAIEVTYODfi/tiCgRaKyUC/y5zLVIgkIulQCAdUyBQpKREoPBIgUBcUiAQq5QI5MipIbCYSoFgt4@PCUad@3QawiAFAmFJicACIgUCAUqBYLsh8hQIVoUWD6aUCGzeRQiwygUIBPwCBLL6BQik/AUYOOfqq16AQLJdgGD9Lnd1L0DwsY2TA0ZIBpuEol/I4G0Tv3Nm5f59AQN568UYGKILGSiDXMBAqC9gIM0vYCAaFzGwt0@HfgEDGf8CBusXc9BycYNdwEAudGUk2LMrI8G4XIMbXMVgw7cX1/4KDnxzC28yl@MKBrLFFQzWVQuX7QoEInQFAdn@ykAw17uCgFzoSgDyh2uIg6sA7PlJH7YbHMUVAGTcKwCsok9upGtIhdeQCq4AoI1vACABbwCgb29Mh/bFLdSFG9OBrXcLsXADBL7Jwu/c5bgxFfp3haO4AcC6UxV2r8NOD4d3AwChuEF/udKNecDw36D/ut7gTG7QX3rdgv436C92N6ZC321xYjfoLxNk0F9myYL@WaiLGcuB7ZaFcpAxEEy3LDhBBgb8nbscGUuivynC7DKsVbnWGfRf93w4uwz6i0TGWqgAygBA@DMAEMaMEWBQMgCQYlnIAhlrgcHLAGBVdnFkGQAoE@UA4EknZya0PJmDgJJ6DgKyRg4CIpWDgCTMQUBS5woD6J6DAv/eXaScacA2zUFAAucqhja79lDMmQSMWQ4CYpaTgLJBDgLSO2ceVITkQCCmOfsB/3r0qpAzCSit5CwGKjS5osBWf60l504KmnoPieAOCgJ3BwVtfgcFYb2H/ugeasI9xMIdFKT/HST4pghvyjC7cuvfgx/cQUFk7qAgtndSUPa8g4Lc8A4KMsedBdF84y4Ie34yugvfCUFOdAcEGf1OBmaJOxmoQBdkINhFqIkFPcG@KegJtmHBuqglC7qCgSnoCoajCBmxYJNo8hQhIAqA4Jsy/F4hFCEZFIAgeIVcYce3dAX4JCXp3AaFucJOXw9OpmA62EijtTMsSEEIC3MF13hxcoW7AlrUkhjUuJasi/Z9CQz@UcmioD1LgtCqJUCIThm65TJ0CCUzw0Zfr5mxDB5RAgZ/r1mhDGWhVEzs@axxJCVBvH/EWw671RAlSch4JUgIT8ke0fQrQUJmLElCHEuSWJVenF5JEojIZPepstRg76vQJ1YgIfUqgNCaFVOD1fQKGESsoj@YEhX9Yadna4KsmB7M6hUwrKMyzKsi/l775AoYlCQqBoWlqMr8AXImGHbeSFSkIDNVwR8qUrCepmJUmEEqSw3v8fGA4eyWq9ggWPtQEYJsXBOClqwBQQLVrBC2UA0IUrhmZjApamYGU70ODXMdDgw1IEiZOkCoWSV8Xhm@rcJudcQ5D1e9ZoWwDFcTgtSoQ2aoAUF2qZkeTaE6lMiaFcIsWYOBrFYDgWxaMyKMVQ0EwvIgAR3UHiCgnR8WEJZQHxYQlo8fDAhxezAgrHA8GBBWLh4MCEtpD2WGDVe/u2QPeoK5@EPZYc95lcN66NCw5RePiLObsEK7BuwDEFah@7WsPXhoNO0eopBwNHqBe1g8bLXwvNaDR@gVHxYP2/jt8KkhCB1TGx6i7fuGIPRRQxDasyEIrdqwXxKeBiTEpAEJMWkUE5CpYddodBo1DTs@K51Jw6bpoAVrN0ITSmYDGvwNEock3vFBt1qiIQrZrwEK8WnYM5qCDc9OsmRDFiLZkMWq9uL8GrLYJ/Eh@dSShZmoBQq5Uct6aS7YgoQST6v7BKjXMjX425snqJb1UgmspUeIWMtiobTa2oWCZavWLhQs77UMDcV@yyShCGhJQ9K3dA6BaMGEDzpXt2UDbam4DX7R2mWCwWrpGBbFbThCtOwgLYxaXiYYv5ZHCAuUjkcIM1vHqmnzOl0oQJKOB2ozYKfTJNbr1EHv@cXNhelAQsQ6HiNMrI4HaiPW8UBtxDo7UCdasHJRO54mfeLDBezsHGE6dUAg5Ttg4O8@SDcEmZ5hzhg0m9x2HQgoDLvQPXU8Q5hD9vKFDUdrwezDGaIPh6geBMSiDz10H9qGniFhevd0BUVMDwTSp6cnSJ@eDOQqPT1B2bnncdLSXk9HUBz2pCDf73mc3GjmeqvQgwT/Dm7BHhQUoH1ooHr5wZ5v1@N0z5Cw8O3DpdLAk5Q9G0BBBAcep3d6lvqeQ4iIgRcrxmPQSQJ7DCyWJuWgiyWQGQBBvjEAggw9gIE8YuBx0p/V7n8DT1PGcuBpygAO0H99th6nB56mTPMBDPjmGWQbg7xTkGN2iw86SNgKL09GT2uhzWpPAjC1n@wW/HXqeJ4AIEGeLJS2/VMt9I7PMofyDDXiqe5xz3mF43kCgKA8WSMM95MdpK/ycEWe6hgSrtKuHvQM6eDJNtos/gwXCk9Q4N/RtX2yUBrDJztoS/vPQOBpHbTlzxEI5P5jaBVG1gcfpR4SIwjIUGO4WxvD3eIY@qWRqcDojawN5o4jXcD3KN3hR9WGhHvUrsQIAhJ1ZAysAraeMkYeKA3aSB/wpddrpVHZYMsFx4i/19P0qOsU22BxI4/KBNh@AgAZb2KBtJ0m9kqm7EQAZrwp5MIJAGTGCQC0xwQA8u3JMoGZbKIPKPFNTAWqD5OlAqsPE1OBKsEECipJE1OBUsVEDCoPky6ZbfvO1Zl0uwYfm8KhcmI6MMNPPEm4cFPE2bPjm0J1nHS5iPVn3qyZBWcdqbHWHPxgDnesc7hsn8Md8xz65pm3a0c9y1cLzrxeM6PPdr1mqW@26zVr1Gder5nIM9sEE2y2fGgtymz50Mr6zKpgdpnpC2bJmddrLtrgHjADghxpDq3jzNslU38GCP5e3FFnRoOpufBmxSJr0eEBai7qm7d8m3roLwwGQ7SoKti8m/vRohP1nvPWRmlhy2h@tICBvGfhRbsZaGEwmF4L7xZMykW9s@3ROJWFF@1GaglOsPByxZLUEirjEm4WFlbGnd5OYZXZNV/AgH9fTuvFWDCWL3bNNvsV/tHwCsngxZs1W/UVzg0vxsJRbzO398v@42JWfFksmOlfFgtm@he9QCe3l8XCTpvXrubL/uFitn/ZP1yskXvxptkgvZQUt5zZB9EHV@9FDPLBVzhGvdQh7Ph6vW1/gcNK4BVt/g8"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">this</a>)</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 7 bytes</h1> | |
<pre><code>;Uĵ\Ṫ€ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCI7VcOEwrVcXOG5quKCrCIsIiIsIiIsWyJbMCwgMSwgLTEsIDIsIC0zLCA1LCAtOF0iXV0="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>Given the previous row, we can reverse it, append it to the next element in the source list, and cumulatively sum. (Reverse + append-to is the same as append + reverse)</p> | |
<p>Therefore:</p> | |
<pre><code>;Uĵ\Ṫ€ Main Link | |
\ Cumulatively reduce the source list; each time, with the | |
last row as the left and the next element as the right: | |
; Append the element to the last row | |
U Reverse the whole thing | |
Ä Cumulative sum | |
Ṫ€ Get the last element of each | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22 bytes</h1> | |
<pre><code>’1ŀ_+1ŀ’}¥ð‘ị³ðṛ? | |
J’Ç€ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw0zDow3x2kACyKw9tPTwhkcNMx7u7j60@fCGhztn23N5AcUPtz9qWvP///9oAx0FQx0FIx0FYx0Fk1gA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Horrible recursive definition, I'm sure there's a better approach. Full program. <a href=""https://tio.run/##y0rNyan8//9Rw0zDow3x2kACyKw9tPTwhkcNMx7u7j607vCGhztn23N5AcUPtz9qWvP/0M5DKw@3H530cOcMzcj//6MNDWJ1FKINdBQMdRSMdBSMdRRMEAK6EEFdoKgpkLIAyUCFsVCxAA"" rel=""nofollow noreferrer"">Here</a>'s a modified version to run as a test suite.</p> | |
<h2>How it works</h2> | |
<p>We just implement</p> | |
<p><span class=""math-container"">$$T(n,k) = \begin{cases} | |
a_n & \text{if } k = 0 \\ | |
T(n-1,n-k) + T(n, k-1) & \text{otherwise} | |
\end{cases}$$</span></p> | |
<p>then calculate <span class=""math-container"">\$T(i,i)\$</span> for each index <span class=""math-container"">\$i\$</span> of <span class=""math-container"">\$a\$</span></p> | |
<p>The first line defines <span class=""math-container"">\$T(n,k)\$</span>, and the second calculates <span class=""math-container"">\$T(i,i)\$</span> for each index <span class=""math-container"">\$i\$</span>.</p> | |
<pre><code>’1ŀ_+1ŀ’}¥ð‘ị³ðṛ? - Helper link. T(n,k). | |
ṛ? - If k: | |
ð - Then: | |
’ - n-1 | |
_ - n-k | |
1ŀ - T(n-1, n-k) | |
¥ - Last two links as a dyad g(n,k): | |
’} - k-1 | |
1ŀ - T(n, k-1) | |
+ - T(n-1, n-k) + T(n, k-1) | |
ð - Else: | |
‘ - n+1 (due to Jelly's 1 indexing) | |
ị³ - Index into a | |
J’Ç€ - Main link. Takes a on the left | |
J - Indices of a | |
’ - Decrement to 0 index | |
€ - Over each index i: | |
Ç - Yield T(i,i) | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""noreferrer"">Jelly</a>, 23 bytes</h1> | |
<pre><code>ḤḤ,’÷3ƊƊḂ?€FḞƑƇ>Ƈ1 | |
1ÇС | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCLhuKThuKQs4oCZw7czxorGiuG4gj/igqxG4biexpHGhz7GhzFcbjHDh8OQwqEiLCLDh8WS4bmY4oKsWSIsIiIsWyIxNSJdXQ=="" rel=""noreferrer"">Try It Online!</a></p> | |
<p>I doubt this is optimal; I kind of ended up patching together like three fixes in a row on my original idea. Might retry later if I have time and remember.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 23 </s> 22 <a href=""https://github.com/DennisMitchell/jelly/iki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Quite possibly still beatable...</p> | |
<pre><code>ĖUṙFḢƊƬḢ€⁺JœṖ€$§ṪọɗƇLṪ | |
</code></pre> | |
<p>A monadic Link that accepts the list and yields a list of lists.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///ItNCHO2e6Pdyx6FjXsTVA6lHTmkeNu7yOTn64cxqQrXJo@cOdqx7u7j05/Vi7D5D5/3A7UPjopIc7ZwDpyP//o6MNYrl0oo1BhK6hjoIRiGEKpHUUTHQUzHQUzHUUjHUUDEHCQJ6BjoKuGVhW11JBx1RBB6wRqBKiBSilawTWYwHVYGgAwSCNlkAMMhQkBWQTQLFcsQA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>ĖUṙFḢƊƬḢ€⁺JœṖ€$§ṪọɗƇLṪ - Link: list of integers A=[a,b,...,x,y,...] | |
Ė - enumerate -> [[1,a],[2,b],...,[n,x],[m,y],...] | |
U - upend -> [[a,1],[b,2],...,[x,n],[y,m],...] | |
Ƭ - collect until a repeat under: | |
Ɗ - last three links as a monad, f(current=[[x,n],[y,m],...]): | |
F - flatten (current) -> [x,n,y,m,...] | |
ṙ - rotate (current) left by (each of [x,n,y,m,...]) | |
Ḣ - head -> rotation by x | |
Ḣ€ - head each -> leftmost of each, [[a,1],...,[x,n],...] | |
⁺ - repeat Ḣ€ -> visited elements in order, [a,...,x,...,last_of_loop] | |
$ - last two links as a monad, f(V=[a,...,x,...,last_of_loop]): | |
J - range of length -> [1,2,...,length(V)] | |
œṖ€ - partition (V) before each (of those) indices | |
Ƈ - filter (all of these 2-partitions) keeping if: | |
L - use length (of A) on the right of... | |
ɗ - last three links as a dyad, f(partition, length(A)): | |
§ - sums | |
Ṫ - tail -> length of the potential loop | |
ọ - how many times is that divisible by length(A)? | |
(positive (truthy) if an actual loop, else 0 (falsey)) | |
Ṫ - tail | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>24</s> 22 bytes</h1> | |
<pre><code>aŻƤSƇḢßoɓ@ooƑ? | |
Ṭ×)ç@ƒ0 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/x6O5jS4KPtT/csejw/PyTkx3y849NtOd6uHPN4emah5c7HJtk8P9wu7dm5P//0YY6xjqGsTpA2gTE0jGC8AxiAQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>I still have the strangest feeling that something closer to Dennis's answer should beat this, but I haven't had any luck with that so far. I have twisted the first line into something that sounds like some kind of exploding can (from <a href=""https://tio.run/##y0rNyan8/z//8PzEo7uPLQk@1v5wx6JT3SenO@TnH5toz/Vw55rD0zUPLz82yeD/4XZvzcj//6MNdYx1DGN1gLQJiKVjBOEZxAIA"" rel=""nofollow noreferrer"">my original recursive solution</a>; I thought it saved a byte but I didn't look at the output too carefully so it actually ties but it does look funnier).</p> | |
<pre><code>aŻƤSƇḢßoɓ@ooƑ? Helper link: add a pre-positioned guest to the hotel | |
ɓ With reversed arguments (hotel left, guest right): | |
oƑ? Unless both arrays have a nonzero at the same location, | |
o return with the guest placed in its empty room; | |
ɓ if they do: | |
@ (guest left, hotel right) | |
a Overlay the guest's zeroes on the hotel. | |
ŻƤ Prepend another zero to each prefix, | |
SƇḢ and take the first with a nonzero sum. | |
ß Call this link again with that as the new guest | |
o and with the hotel having the previous guest replace the new one. | |
Ṭ×)ç@ƒ0 Main link | |
) For each guest value, | |
Ṭ obtain a list of all zeroes then a one at that index, | |
× and multiply that by the same guest value. | |
ƒ0 Starting with 0, reduce that by | |
ç@ the helper with reversed arguments. | |
</code></pre> | |
<p>Essentially just boots occupants out of their rooms in sequence until there's no collision, considering a new guest as equivalent to someone evicted from the last room they can't start in.</p> | |
<p>Dennis's answer with some simple golfs for fair comparison, and an explanation for those still wondering:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 26 bytes</h1> | |
<pre><code>’⁹ḣ;⁸;ṫ@œṡ0Fɗð0ẋ;@ | |
ç@ƒ0œr0 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw8xHjTsf7lhs/ahxh/XDnasdjk5@uHOhgdvJ6Yc3GDzc1W3twHV4ucOxSQZHJxcZ/D/c7q0Z@f9/tKGOgrGOgmGsjgKIaQLh6SgYwcQMYgE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>’⁹ḣ;⁸;ṫ@œṡ0Fɗð0ẋ;@ Helper link: add a guest on the left to the hotel on the right | |
ð Let the right argument to the rest of the link be | |
0ẋ zero repeated by the value of the guest | |
;@ concatenated to the end of the hotel. | |
⁹ḣ Take elements from that right argument numbering | |
’ one less than the guest, | |
;⁸ concatenate the guest, | |
; ɗ and concatenate: | |
ṫ@ remove elements from that right argument numbering the guest value, | |
œṡ0 split those remaining around the first zero, | |
F and flatten them back together. | |
ç@ƒ0œr0 Main link | |
ç@ƒ0 With the hotel starting as 0, add each guest to the hotel in sequence. | |
œr0 Trim trailing zeroes. | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s> 12 </s> 11 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>BŒṖŒɠṂ’ƊƇµ# | |
</code></pre> | |
<p>A full program that accepts a positive integer, <span class=""math-container"">\$n\$</span>, from STDIN and prints a list of the first <span class=""math-container"">\$n\$</span> emanresu numbers.</p> | |
<p><strong><a href=""https://tio.run/##ASIA3f9qZWxsef//QsWS4bmWxZLJoOG5guKAmcaKxofCtSP//zMz"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>BŒṖŒɠṂ’ƊƇµ# - Main Link: no arguments | |
# - start with k=0 and count up, collecting the first n (from STDIN) k | |
which are truthy under: | |
µ - the monadic chain, f(k): | |
B - convert (k) to binary | |
ŒṖ - all partitions (of the binary representation of k) | |
Ƈ - filter - keep those (partitions) which are truthy under: | |
Ɗ - last three links as a monad, f(partition): | |
Œɠ - run-lengths of equal elements (e.g. 101,101,1,1,1,0 -> 2,3,1) | |
Ṃ - minimum | |
’ - decrement (vectorises) -> 0 is falsey, other numbers are truthy | |
(a result of f(k) which is non-empty is truthy) | |
</code></pre> | |
" | |
"58563","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 17 </s> 15 bytes</h1> | |
<p><em>Saved 2 bytes thanks to @Dudecoinheringaahing</em></p> | |
<p>Takes an integer <span class=""math-container"">\$n\$</span> from STDIN and generates the first <span class=""math-container"">\$n\$</span> terms.</p> | |
<p>This is probably twice as long as it should be...</p> | |
<pre><code>BŒṖ‘ḄŒɠ€ỊẸ€ẠṆø# | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/p6KSHO6c9apjxcEfL0UknFzxqWvNwd9fDXTtAjF0LHu5sO7xD@f9/YwMA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>⁴ḍTị⁵ȯ)Y | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9R45aHO3pDHu7uftS49cR6zcj///8bGvyPNtYx1THXMTTUMTSO/R@t5JZZVaWko@RUCqbc8vNBnMQiMFmlFAsA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Full program that takes <span class=""math-container"">\$n\$</span>, the list of numbers <span class=""math-container"">\$L\$</span> and the list of strings <span class=""math-container"">\$S\$</span> as command line argument, and returns a newline separated string</p> | |
<h2>How it works</h2> | |
<pre><code>⁴ḍTị⁵ȯ)Y - Main link. Takes n on the left, L as ⁴ and S as ⁵ | |
) - Over each integer 1 ≤ i ≤ n: | |
⁴ḍ - Map each element in L to 1 if i is divisible by it, else 0 | |
T - Indices of 1s | |
ị⁵ - Select the elements of S at those indices | |
ȯ - If this is the empty list, replace it with i | |
Y - Join on newlines | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 17 bytes</h1> | |
<pre><code>FAṀŒRṗLƲṁ€ðæ*2iị⁸ | |
</code></pre> | |
<p><a href=""https://tio.run/##ATwAw/9qZWxsef//RkHhuYDFklLhuZdMxrLhuYHigqzDsMOmKjJp4buL4oG4////W1s5LCAtOF0sIFswLCAxXV0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>It's been over a week, so I figured I'd reveal my brute-force Jelly approach. This makes the following assumption, which I haven't managed to prove, but can't find a counter example:</p> | |
<blockquote> | |
<p>Let <span class=""math-container"">\$B\$</span> be the input <span class=""math-container"">\$n \times n\$</span> matrix, and <span class=""math-container"">\$A\$</span> be an <span class=""math-container"">\$n \times n\$</span> matrix such that <span class=""math-container"">\$A^2 = B\$</span></p> | |
<p>Let <span class=""math-container"">\$b = \max\{|B_{ij}|, 1 \le i,j \le n\}\$</span> i.e. the largest absolute element of <span class=""math-container"">\$B\$</span>. This answer assumes that, assuming <span class=""math-container"">\$A\$</span> exists, there is at least one matrix <span class=""math-container"">\$A\$</span> such that all its elements are in the inclusive range <span class=""math-container"">\$[-b, b]\$</span></p> | |
<p>For example, for | |
<span class=""math-container"">$$B = \left[ \begin{matrix} 9 & -8 \\ 0 & 1 \end{matrix} \right]$$</span>, | |
<span class=""math-container"">\$b = 9\$</span> and there exists at least one <span class=""math-container"">\$A\$</span> such that all elements are between <span class=""math-container"">\$-9\$</span> and <span class=""math-container"">\$9\$</span> (the example in the question, for example)</p> | |
</blockquote> | |
<h2>How it works</h2> | |
<pre><code>FAṀŒRṗLƲṁ€ðæ*2iị⁸ - Main link. Takes B on the left | |
F - Flatten B | |
A - Absolute values of each. | |
Ʋ - Last 4 links as a monad f(abs(flat(B)): | |
Ṁ - Maximum | |
ŒR - Bounced range; [-max, +max] | |
L - Length i.e. number of elements of B | |
ṗ - Powerset | |
€ - Over each list: | |
ṁ - Mold it like B | |
Call this list of matrices M | |
ð - Begin a new dyadic chain with M on the left and B on the right | |
æ*2 - Matrix square of each matrix in M | |
i - Index of B in M | |
⁸ - Yield M | |
ị - Index back into M | |
</code></pre> | |
<p>One byte longer is a slightly more conventional way of extracting the root:</p> | |
<pre><code>FAṀŒRṗLƲṁ€æ*2⁼ɗƇ⁸Ḣ | |
</code></pre> | |
<p><a href=""https://tio.run/##AUAAv/9qZWxsef//RkHhuYDFklLhuZdMxrLhuYHigqzDpioy4oG8yZfGh@KBuOG4ov///1tbOSwgLThdLCBbMCwgMV1d"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Here, the dyadic filter <code>æ*2⁼ɗƇ</code> means that it would save a byte over the dyadic chaining with the indexing. However, as we should only output one solution, and the <code>Ḣ</code> would chain to the filter without either <code>⁸</code> or <code>¹</code>, the indexing here actually saves a byte.</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 3 bytes</h1> | |
<pre><code>Rṁ@ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCJS4bmBQCIsIsOnQC/igqzFkuG5mOKCrFkiLCIiLFsiW1s0LCA1LCAxLCAyLCA2LCAxLCA3LCA5LCA2XSwgWzIsIDQsIDNdXSwgW1s0LCAyLCA4LCA3LCAzLCA1LCA5LCAzLCAxLCA5LCAxLCA4LCAxLCA3LCAyLCA4LCAzLCA3LCA2XSwgWzEsIDMsIDEsIDE0XV0sIFtbOCwgNywgNCwgNl0sIFsxLCAzXV0sIFtbN10sIFsxXV0sIFtbNiwgNCwgMywgOCwgOSwgMywgNiwgNSwgNywgOCwgMywgMiwgNSwgMSwgMl0sIFszLCAzLCAzLCAzLCAzXV0iXV0="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>Equivalently, <code>ṁR}</code> but with the arguments the other way around.</p> | |
<pre><code>R Range (vectorizes) | |
ṁ@ Mold the right argument to the shape of the ranges | |
</code></pre> | |
<pre><code>ṁ Mold the left argument to the shape of: | |
R} Range (vectorizes) of the right argument | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 45 </s> 24 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>pŒcạ/S$ÐṂŒPẎ€f€ẠȧQƑʋ@ƇƊL | |
</code></pre> | |
<p>A dyadic Link that accepts the two dimensions and yields the count.</p> | |
<p><strong><a href=""https://tio.run/##ATkAxv9qZWxsef//cMWSY@G6oS9TJMOQ4bmCxZJQ4bqO4oKsZuKCrOG6oMinUcaRyotAxofGikz///8z/zQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Note: It brute forces across the powerset of all possible dominoes so is incredibly inefficient.</p> | |
<h3>How?</h3> | |
<pre><code>pŒcạ/S$ÐṂŒPẎ€f€ẠȧQƑʋ@ƇƊL - Link: integer, n; integer m | |
p - (n) cartesian product (m) -> list of all coordinates | |
Œc - pairs -> all pairs of coordinates, once each | |
ÐṂ - keep those which are minimal under: | |
$ - last two links as a monad, f(pair of coordinates): | |
/ - reduce (the pair of coordinates) by: | |
ạ - absolute difference | |
S - sum | |
-> all possible dominoes, once each, as pairs of coordinates | |
Ɗ - last three links as a monad, f(all dominoes): | |
ŒP - power set -> all sets of dominoes (including overlaps) | |
Ẏ€ - tighten each -> coordinates used by each set of dominoes | |
Ƈ - filter keep those (potential sets) for which: | |
@ - with swapped arguments... | |
ʋ - ...last four links as a dyad, f(all dominos, potential set): | |
€ - for each (domino in all dominoes): | |
f - keep those (coordinates of the domino) which are in (the coordinates used by the potential set) | |
Ạ - all? (i.e only single empties / no touching monominoes?) | |
Ƒ - is (potential set) invariant under: | |
Q - deduplication? -> truthy if no overlaps | |
ȧ - (only single empties) logical AND (no overlaps) | |
L - length | |
</code></pre> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>“:-)”ṁ«\)Y | |
</code></pre> | |
<p><a href=""https://tio.run/##ASUA2v9qZWxsef//4oCcOi0p4oCd4bmBwqtcKVn/w4cpauKBvgoK//81"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> ) Map over (the range from 1 to) the input: | |
“:-)”ṁ Mold ":-)" to the shape of the argument, cycling its contents. | |
«\ Scan by minimum: replace anything to the right of ) with ). | |
Y Join on newlines. | |
</code></pre> | |
<p>Thanks to Jonathan Allan for salvaging my first attempt, <a href=""https://tio.run/##y0rNyan8//9Rw1zNikcb1yU@atxnpfv/cHukZhaQycX1/78pAA"" rel=""nofollow noreferrer""><code>”)xⱮa⁾:-Y</code></a>, for another 10-byter:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 10 bytes</h1> | |
<pre><code>”)xa⁾:-ṁ)Y | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw1zNisRHjfusdB/ubNSM/H@4XTMLyOXi@v/fFAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code> ) Map over (the range from 1 to) the input: | |
”)x Repeat ")" by the argument. | |
a⁾:- Zipwith-vectorize logical AND with ":-": | |
overwrite the first two characters with ":-". | |
ṁ Mold to the shape of the argument, trimming the extra "-" for 1. | |
Y Join on newlines. | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/cairdcoinheringaahing/jellylanguage"" rel=""nofollow noreferrer"">Jelly (fork)</a>, 8 bytes</h1> | |
<pre><code>9Żṗ4Qi$Ƙ | |
</code></pre> | |
<p><a href=""https://tio.run/##AScA2P9qZWxsef//OcW74bmXNFFp4rGuJOKBvMKlxof///9bMSwyLDMsMV0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> (my original Jelly answer)</p> | |
<p>Didn't take long for <a href=""https://codegolf.stackexchange.com/a/233057/66833"">Lynn to outgolf</a> my <a href=""https://tio.run/##AScA2P9qZWxsef//OcW74bmXNFFp4rGuJOKBvMKlxof///9bMSwyLDMsMV0"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">original Jelly answer</a>, so I thought I'd show my approach, using my fork because <code>⁼¥Ƈ</code> annoys me.</p> | |
<h2>How it works</h2> | |
<pre><code>9Żṗ4Qi$Ƙ - Main link. Takes [a,b,c,d] on the left | |
9Ż - Zero-range of 9; Yield [0,1,2,3,4,5,6,7,8,9] | |
ṗ4 - Fourth cartesian power; All length-4 lists with elements from that range | |
$Ƙ - Keep those elements [x,y,z,w] for which the following equals [a,b,c,d]: | |
Q - Unique elements | |
i - Their indices in [x,y,z,w] | |
</code></pre> | |
<p>In this case, <code>i</code> in my fork has been modified so that using it on flat lists is equivalent to <code>iⱮ</code>, as otherwise it outputs <code>0</code> (not found): <a href=""https://tio.run/##y0rNyan8/z/z////0YY6RjrGOoaxYFYsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> Additionally, <code>Ƙ</code> has been added to supplant <code>⁼¥Ƈ</code> as it gets used <a href=""https://github.com/DennisMitchell/jellylanguage/issues/91"" rel=""nofollow noreferrer"">a lot</a>.</p> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>⁵Œ!’³ịⱮQ | |
</code></pre> | |
<p>Times out on TIO, takes about two minutes on my machine:</p> | |
<pre><code>% time python3 -m jelly eu '⁵Œ!’³ịⱮQ' "[1,2,3,1]" | |
[[0, 1, 2, 0], [0, 1, 3, 0], [0, 1, 4, 0], [0, 1, 5, 0], [0, 1, 6, 0], [0, 1, 7, 0], [0, 1, 8, 0], [0, 1, 9, 0], [0, 2, 1, 0], [0, 2, 3, 0], [0, 2, 4, 0], [0, 2, 5, 0], [0, 2, 6, 0], [0, 2, 7, 0], [0, 2, 8, 0], [0, 2, 9, 0], [0, 3, 1, 0], [0, 3, 2, 0], [0, 3, 4, 0], [0, 3, 5, 0], [0, 3, 6, 0], [0, 3, 7, 0], [0, 3, 8, 0], [0, 3, 9, 0], [0, 4, 1, 0], [0, 4, 2, 0], [0, 4, 3, 0], [0, 4, 5, 0], [0, 4, 6, 0], [0, 4, 7, 0], [0, 4, 8, 0], [0, 4, 9, 0], [0, 5, 1, 0], [0, 5, 2, 0], [0, 5, 3, 0], [0, 5, 4, 0], [0, 5, 6, 0], [0, 5, 7, 0], [0, 5, 8, 0], [0, 5, 9, 0], [0, 6, 1, 0], [0, 6, 2, 0], [0, 6, 3, 0], [0, 6, 4, 0], [0, 6, 5, 0], [0, 6, 7, 0], [0, 6, 8, 0], [0, 6, 9, 0], [0, 7, 1, 0], [0, 7, 2, 0], [0, 7, 3, 0], [0, 7, 4, 0], [0, 7, 5, 0], [0, 7, 6, 0], [0, 7, 8, 0], [0, 7, 9, 0], [0, 8, 1, 0], [0, 8, 2, 0], [0, 8, 3, 0], [0, 8, 4, 0], [0, 8, 5, 0], [0, 8, 6, 0], [0, 8, 7, 0], [0, 8, 9, 0], [0, 9, 1, 0], [0, 9, 2, 0], [0, 9, 3, 0], [0, 9, 4, 0], [0, 9, 5, 0], [0, 9, 6, 0], [0, 9, 7, 0], [0, 9, 8, 0], [1, 0, 2, 1], [1, 0, 3, 1], [1, 0, 4, 1], [1, 0, 5, 1], [1, 0, 6, 1], [1, 0, 7, 1], [1, 0, 8, 1], [1, 0, 9, 1], [1, 2, 0, 1], [1, 2, 3, 1], [1, 2, 4, 1], [1, 2, 5, 1], [1, 2, 6, 1], [1, 2, 7, 1], [1, 2, 8, 1], [1, 2, 9, 1], [1, 3, 0, 1], [1, 3, 2, 1], [1, 3, 4, 1], [1, 3, 5, 1], [1, 3, 6, 1], [1, 3, 7, 1], [1, 3, 8, 1], [1, 3, 9, 1], [1, 4, 0, 1], [1, 4, 2, 1], [1, 4, 3, 1], [1, 4, 5, 1], [1, 4, 6, 1], [1, 4, 7, 1], [1, 4, 8, 1], [1, 4, 9, 1], [1, 5, 0, 1], [1, 5, 2, 1], [1, 5, 3, 1], [1, 5, 4, 1], [1, 5, 6, 1], [1, 5, 7, 1], [1, 5, 8, 1], [1, 5, 9, 1], [1, 6, 0, 1], [1, 6, 2, 1], [1, 6, 3, 1], [1, 6, 4, 1], [1, 6, 5, 1], [1, 6, 7, 1], [1, 6, 8, 1], [1, 6, 9, 1], [1, 7, 0, 1], [1, 7, 2, 1], [1, 7, 3, 1], [1, 7, 4, 1], [1, 7, 5, 1], [1, 7, 6, 1], [1, 7, 8, 1], [1, 7, 9, 1], [1, 8, 0, 1], [1, 8, 2, 1], [1, 8, 3, 1], [1, 8, 4, 1], [1, 8, 5, 1], [1, 8, 6, 1], [1, 8, 7, 1], [1, 8, 9, 1], [1, 9, 0, 1], [1, 9, 2, 1], [1, 9, 3, 1], [1, 9, 4, 1], [1, 9, 5, 1], [1, 9, 6, 1], [1, 9, 7, 1], [1, 9, 8, 1], [2, 0, 1, 2], [2, 0, 3, 2], [2, 0, 4, 2], [2, 0, 5, 2], [2, 0, 6, 2], [2, 0, 7, 2], [2, 0, 8, 2], [2, 0, 9, 2], [2, 1, 0, 2], [2, 1, 3, 2], [2, 1, 4, 2], [2, 1, 5, 2], [2, 1, 6, 2], [2, 1, 7, 2], [2, 1, 8, 2], [2, 1, 9, 2], [2, 3, 0, 2], [2, 3, 1, 2], [2, 3, 4, 2], [2, 3, 5, 2], [2, 3, 6, 2], [2, 3, 7, 2], [2, 3, 8, 2], [2, 3, 9, 2], [2, 4, 0, 2], [2, 4, 1, 2], [2, 4, 3, 2], [2, 4, 5, 2], [2, 4, 6, 2], [2, 4, 7, 2], [2, 4, 8, 2], [2, 4, 9, 2], [2, 5, 0, 2], [2, 5, 1, 2], [2, 5, 3, 2], [2, 5, 4, 2], [2, 5, 6, 2], [2, 5, 7, 2], [2, 5, 8, 2], [2, 5, 9, 2], [2, 6, 0, 2], [2, 6, 1, 2], [2, 6, 3, 2], [2, 6, 4, 2], [2, 6, 5, 2], [2, 6, 7, 2], [2, 6, 8, 2], [2, 6, 9, 2], [2, 7, 0, 2], [2, 7, 1, 2], [2, 7, 3, 2], [2, 7, 4, 2], [2, 7, 5, 2], [2, 7, 6, 2], [2, 7, 8, 2], [2, 7, 9, 2], [2, 8, 0, 2], [2, 8, 1, 2], [2, 8, 3, 2], [2, 8, 4, 2], [2, 8, 5, 2], [2, 8, 6, 2], [2, 8, 7, 2], [2, 8, 9, 2], [2, 9, 0, 2], [2, 9, 1, 2], [2, 9, 3, 2], [2, 9, 4, 2], [2, 9, 5, 2], [2, 9, 6, 2], [2, 9, 7, 2], [2, 9, 8, 2], [3, 0, 1, 3], [3, 0, 2, 3], [3, 0, 4, 3], [3, 0, 5, 3], [3, 0, 6, 3], [3, 0, 7, 3], [3, 0, 8, 3], [3, 0, 9, 3], [3, 1, 0, 3], [3, 1, 2, 3], [3, 1, 4, 3], [3, 1, 5, 3], [3, 1, 6, 3], [3, 1, 7, 3], [3, 1, 8, 3], [3, 1, 9, 3], [3, 2, 0, 3], [3, 2, 1, 3], [3, 2, 4, 3], [3, 2, 5, 3], [3, 2, 6, 3], [3, 2, 7, 3], [3, 2, 8, 3], [3, 2, 9, 3], [3, 4, 0, 3], [3, 4, 1, 3], [3, 4, 2, 3], [3, 4, 5, 3], [3, 4, 6, 3], [3, 4, 7, 3], [3, 4, 8, 3], [3, 4, 9, 3], [3, 5, 0, 3], [3, 5, 1, 3], [3, 5, 2, 3], [3, 5, 4, 3], [3, 5, 6, 3], [3, 5, 7, 3], [3, 5, 8, 3], [3, 5, 9, 3], [3, 6, 0, 3], [3, 6, 1, 3], [3, 6, 2, 3], [3, 6, 4, 3], [3, 6, 5, 3], [3, 6, 7, 3], [3, 6, 8, 3], [3, 6, 9, 3], [3, 7, 0, 3], [3, 7, 1, 3], [3, 7, 2, 3], [3, 7, 4, 3], [3, 7, 5, 3], [3, 7, 6, 3], [3, 7, 8, 3], [3, 7, 9, 3], [3, 8, 0, 3], [3, 8, 1, 3], [3, 8, 2, 3], [3, 8, 4, 3], [3, 8, 5, 3], [3, 8, 6, 3], [3, 8, 7, 3], [3, 8, 9, 3], [3, 9, 0, 3], [3, 9, 1, 3], [3, 9, 2, 3], [3, 9, 4, 3], [3, 9, 5, 3], [3, 9, 6, 3], [3, 9, 7, 3], [3, 9, 8, 3], [4, 0, 1, 4], [4, 0, 2, 4], [4, 0, 3, 4], [4, 0, 5, 4], [4, 0, 6, 4], [4, 0, 7, 4], [4, 0, 8, 4], [4, 0, 9, 4], [4, 1, 0, 4], [4, 1, 2, 4], [4, 1, 3, 4], [4, 1, 5, 4], [4, 1, 6, 4], [4, 1, 7, 4], [4, 1, 8, 4], [4, 1, 9, 4], [4, 2, 0, 4], [4, 2, 1, 4], [4, 2, 3, 4], [4, 2, 5, 4], [4, 2, 6, 4], [4, 2, 7, 4], [4, 2, 8, 4], [4, 2, 9, 4], [4, 3, 0, 4], [4, 3, 1, 4], [4, 3, 2, 4], [4, 3, 5, 4], [4, 3, 6, 4], [4, 3, 7, 4], [4, 3, 8, 4], [4, 3, 9, 4], [4, 5, 0, 4], [4, 5, 1, 4], [4, 5, 2, 4], [4, 5, 3, 4], [4, 5, 6, 4], [4, 5, 7, 4], [4, 5, 8, 4], [4, 5, 9, 4], [4, 6, 0, 4], [4, 6, 1, 4], [4, 6, 2, 4], [4, 6, 3, 4], [4, 6, 5, 4], [4, 6, 7, 4], [4, 6, 8, 4], [4, 6, 9, 4], [4, 7, 0, 4], [4, 7, 1, 4], [4, 7, 2, 4], [4, 7, 3, 4], [4, 7, 5, 4], [4, 7, 6, 4], [4, 7, 8, 4], [4, 7, 9, 4], [4, 8, 0, 4], [4, 8, 1, 4], [4, 8, 2, 4], [4, 8, 3, 4], [4, 8, 5, 4], [4, 8, 6, 4], [4, 8, 7, 4], [4, 8, 9, 4], [4, 9, 0, 4], [4, 9, 1, 4], [4, 9, 2, 4], [4, 9, 3, 4], [4, 9, 5, 4], [4, 9, 6, 4], [4, 9, 7, 4], [4, 9, 8, 4], [5, 0, 1, 5], [5, 0, 2, 5], [5, 0, 3, 5], [5, 0, 4, 5], [5, 0, 6, 5], [5, 0, 7, 5], [5, 0, 8, 5], [5, 0, 9, 5], [5, 1, 0, 5], [5, 1, 2, 5], [5, 1, 3, 5], [5, 1, 4, 5], [5, 1, 6, 5], [5, 1, 7, 5], [5, 1, 8, 5], [5, 1, 9, 5], [5, 2, 0, 5], [5, 2, 1, 5], [5, 2, 3, 5], [5, 2, 4, 5], [5, 2, 6, 5], [5, 2, 7, 5], [5, 2, 8, 5], [5, 2, 9, 5], [5, 3, 0, 5], [5, 3, 1, 5], [5, 3, 2, 5], [5, 3, 4, 5], [5, 3, 6, 5], [5, 3, 7, 5], [5, 3, 8, 5], [5, 3, 9, 5], [5, 4, 0, 5], [5, 4, 1, 5], [5, 4, 2, 5], [5, 4, 3, 5], [5, 4, 6, 5], [5, 4, 7, 5], [5, 4, 8, 5], [5, 4, 9, 5], [5, 6, 0, 5], [5, 6, 1, 5], [5, 6, 2, 5], [5, 6, 3, 5], [5, 6, 4, 5], [5, 6, 7, 5], [5, 6, 8, 5], [5, 6, 9, 5], [5, 7, 0, 5], [5, 7, 1, 5], [5, 7, 2, 5], [5, 7, 3, 5], [5, 7, 4, 5], [5, 7, 6, 5], [5, 7, 8, 5], [5, 7, 9, 5], [5, 8, 0, 5], [5, 8, 1, 5], [5, 8, 2, 5], [5, 8, 3, 5], [5, 8, 4, 5], [5, 8, 6, 5], [5, 8, 7, 5], [5, 8, 9, 5], [5, 9, 0, 5], [5, 9, 1, 5], [5, 9, 2, 5], [5, 9, 3, 5], [5, 9, 4, 5], [5, 9, 6, 5], [5, 9, 7, 5], [5, 9, 8, 5], [6, 0, 1, 6], [6, 0, 2, 6], [6, 0, 3, 6], [6, 0, 4, 6], [6, 0, 5, 6], [6, 0, 7, 6], [6, 0, 8, 6], [6, 0, 9, 6], [6, 1, 0, 6], [6, 1, 2, 6], [6, 1, 3, 6], [6, 1, 4, 6], [6, 1, 5, 6], [6, 1, 7, 6], [6, 1, 8, 6], [6, 1, 9, 6], [6, 2, 0, 6], [6, 2, 1, 6], [6, 2, 3, 6], [6, 2, 4, 6], [6, 2, 5, 6], [6, 2, 7, 6], [6, 2, 8, 6], [6, 2, 9, 6], [6, 3, 0, 6], [6, 3, 1, 6], [6, 3, 2, 6], [6, 3, 4, 6], [6, 3, 5, 6], [6, 3, 7, 6], [6, 3, 8, 6], [6, 3, 9, 6], [6, 4, 0, 6], [6, 4, 1, 6], [6, 4, 2, 6], [6, 4, 3, 6], [6, 4, 5, 6], [6, 4, 7, 6], [6, 4, 8, 6], [6, 4, 9, 6], [6, 5, 0, 6], [6, 5, 1, 6], [6, 5, 2, 6], [6, 5, 3, 6], [6, 5, 4, 6], [6, 5, 7, 6], [6, 5, 8, 6], [6, 5, 9, 6], [6, 7, 0, 6], [6, 7, 1, 6], [6, 7, 2, 6], [6, 7, 3, 6], [6, 7, 4, 6], [6, 7, 5, 6], [6, 7, 8, 6], [6, 7, 9, 6], [6, 8, 0, 6], [6, 8, 1, 6], [6, 8, 2, 6], [6, 8, 3, 6], [6, 8, 4, 6], [6, 8, 5, 6], [6, 8, 7, 6], [6, 8, 9, 6], [6, 9, 0, 6], [6, 9, 1, 6], [6, 9, 2, 6], [6, 9, 3, 6], [6, 9, 4, 6], [6, 9, 5, 6], [6, 9, 7, 6], [6, 9, 8, 6], [7, 0, 1, 7], [7, 0, 2, 7], [7, 0, 3, 7], [7, 0, 4, 7], [7, 0, 5, 7], [7, 0, 6, 7], [7, 0, 8, 7], [7, 0, 9, 7], [7, 1, 0, 7], [7, 1, 2, 7], [7, 1, 3, 7], [7, 1, 4, 7], [7, 1, 5, 7], [7, 1, 6, 7], [7, 1, 8, 7], [7, 1, 9, 7], [7, 2, 0, 7], [7, 2, 1, 7], [7, 2, 3, 7], [7, 2, 4, 7], [7, 2, 5, 7], [7, 2, 6, 7], [7, 2, 8, 7], [7, 2, 9, 7], [7, 3, 0, 7], [7, 3, 1, 7], [7, 3, 2, 7], [7, 3, 4, 7], [7, 3, 5, 7], [7, 3, 6, 7], [7, 3, 8, 7], [7, 3, 9, 7], [7, 4, 0, 7], [7, 4, 1, 7], [7, 4, 2, 7], [7, 4, 3, 7], [7, 4, 5, 7], [7, 4, 6, 7], [7, 4, 8, 7], [7, 4, 9, 7], [7, 5, 0, 7], [7, 5, 1, 7], [7, 5, 2, 7], [7, 5, 3, 7], [7, 5, 4, 7], [7, 5, 6, 7], [7, 5, 8, 7], [7, 5, 9, 7], [7, 6, 0, 7], [7, 6, 1, 7], [7, 6, 2, 7], [7, 6, 3, 7], [7, 6, 4, 7], [7, 6, 5, 7], [7, 6, 8, 7], [7, 6, 9, 7], [7, 8, 0, 7], [7, 8, 1, 7], [7, 8, 2, 7], [7, 8, 3, 7], [7, 8, 4, 7], [7, 8, 5, 7], [7, 8, 6, 7], [7, 8, 9, 7], [7, 9, 0, 7], [7, 9, 1, 7], [7, 9, 2, 7], [7, 9, 3, 7], [7, 9, 4, 7], [7, 9, 5, 7], [7, 9, 6, 7], [7, 9, 8, 7], [8, 0, 1, 8], [8, 0, 2, 8], [8, 0, 3, 8], [8, 0, 4, 8], [8, 0, 5, 8], [8, 0, 6, 8], [8, 0, 7, 8], [8, 0, 9, 8], [8, 1, 0, 8], [8, 1, 2, 8], [8, 1, 3, 8], [8, 1, 4, 8], [8, 1, 5, 8], [8, 1, 6, 8], [8, 1, 7, 8], [8, 1, 9, 8], [8, 2, 0, 8], [8, 2, 1, 8], [8, 2, 3, 8], [8, 2, 4, 8], [8, 2, 5, 8], [8, 2, 6, 8], [8, 2, 7, 8], [8, 2, 9, 8], [8, 3, 0, 8], [8, 3, 1, 8], [8, 3, 2, 8], [8, 3, 4, 8], [8, 3, 5, 8], [8, 3, 6, 8], [8, 3, 7, 8], [8, 3, 9, 8], [8, 4, 0, 8], [8, 4, 1, 8], [8, 4, 2, 8], [8, 4, 3, 8], [8, 4, 5, 8], [8, 4, 6, 8], [8, 4, 7, 8], [8, 4, 9, 8], [8, 5, 0, 8], [8, 5, 1, 8], [8, 5, 2, 8], [8, 5, 3, 8], [8, 5, 4, 8], [8, 5, 6, 8], [8, 5, 7, 8], [8, 5, 9, 8], [8, 6, 0, 8], [8, 6, 1, 8], [8, 6, 2, 8], [8, 6, 3, 8], [8, 6, 4, 8], [8, 6, 5, 8], [8, 6, 7, 8], [8, 6, 9, 8], [8, 7, 0, 8], [8, 7, 1, 8], [8, 7, 2, 8], [8, 7, 3, 8], [8, 7, 4, 8], [8, 7, 5, 8], [8, 7, 6, 8], [8, 7, 9, 8], [8, 9, 0, 8], [8, 9, 1, 8], [8, 9, 2, 8], [8, 9, 3, 8], [8, 9, 4, 8], [8, 9, 5, 8], [8, 9, 6, 8], [8, 9, 7, 8], [9, 0, 1, 9], [9, 0, 2, 9], [9, 0, 3, 9], [9, 0, 4, 9], [9, 0, 5, 9], [9, 0, 6, 9], [9, 0, 7, 9], [9, 0, 8, 9], [9, 1, 0, 9], [9, 1, 2, 9], [9, 1, 3, 9], [9, 1, 4, 9], [9, 1, 5, 9], [9, 1, 6, 9], [9, 1, 7, 9], [9, 1, 8, 9], [9, 2, 0, 9], [9, 2, 1, 9], [9, 2, 3, 9], [9, 2, 4, 9], [9, 2, 5, 9], [9, 2, 6, 9], [9, 2, 7, 9], [9, 2, 8, 9], [9, 3, 0, 9], [9, 3, 1, 9], [9, 3, 2, 9], [9, 3, 4, 9], [9, 3, 5, 9], [9, 3, 6, 9], [9, 3, 7, 9], [9, 3, 8, 9], [9, 4, 0, 9], [9, 4, 1, 9], [9, 4, 2, 9], [9, 4, 3, 9], [9, 4, 5, 9], [9, 4, 6, 9], [9, 4, 7, 9], [9, 4, 8, 9], [9, 5, 0, 9], [9, 5, 1, 9], [9, 5, 2, 9], [9, 5, 3, 9], [9, 5, 4, 9], [9, 5, 6, 9], [9, 5, 7, 9], [9, 5, 8, 9], [9, 6, 0, 9], [9, 6, 1, 9], [9, 6, 2, 9], [9, 6, 3, 9], [9, 6, 4, 9], [9, 6, 5, 9], [9, 6, 7, 9], [9, 6, 8, 9], [9, 7, 0, 9], [9, 7, 1, 9], [9, 7, 2, 9], [9, 7, 3, 9], [9, 7, 4, 9], [9, 7, 5, 9], [9, 7, 6, 9], [9, 7, 8, 9], [9, 8, 0, 9], [9, 8, 1, 9], [9, 8, 2, 9], [9, 8, 3, 9], [9, 8, 4, 9], [9, 8, 5, 9], [9, 8, 6, 9], [9, 8, 7, 9]] | |
108.00s user 0.90s system 99% cpu 1:49.73 total | |
</code></pre> | |
<p>Accepts a pattern in the format <code>[1,2,2,3]</code>.</p> | |
<pre><code>⁵Œ!’ All permutations of [0..9]. | |
³ịⱮ For each such permutation, use the input as index vector: | |
e.g. for input [1,2,2,3], turn 3862149075 into 3886. | |
Q Eliminate duplicates. | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>Ġ⁵ṗ4¤ĠṢ⁼ɗƇ’ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///IgkeNWx/unG5yaMmRBQ93LnrUuOfk9GPtjxpm/v//P9pQxwgIDWMB"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Works equally well when given a list of digits (<code>[1, 2, 3, 4]</code>) or a string (<code>"ABCD"</code>).</p> | |
<h3>How it works</h3> | |
<pre class=""lang-none prettyprint-override""><code>Ġ⁵ṗ4¤ĠṢ⁼ɗƇ’ Monadic link. Left arg: PIN pattern | |
Ġ Group indices by identical values | |
(which gives the pattern to filter the combinations for) | |
⁵ṗ4¤ĠṢ⁼ɗƇ Monad-dyad pair: | |
⁵ṗ4¤ Create a list of 4-digit combinations using 1-10 | |
Ƈ Filter from the above list by: | |
ĠṢ⁼ɗ Is the list of sorted groups identical to the input's? | |
’ Decrement to get a list of 0-9 combinations | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 7 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""noreferrer"">bytes</a></h1> | |
<pre><code>R%)Ịoþ/ | |
</code></pre> | |
<p>A monadic Link that accepts the dimensions as a list of positive integers ordered by depth descending (like the examples in the question) and yields the room as a multi-dimensional list of <code>1</code>s and <code>0</code>s.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/z9IVfPh7q78w/v0////H22iY6pjFgsA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##y0rNyan8/z9IVfPh7q78w/v0/x9uf9S05uikhztnAOmsR437uLj@/482jtWJNtIBQyDLRAcIgbSpjhmQNLTUAUkbGsUCAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">test-suite</a></p> | |
<h3>How?</h3> | |
<pre><code>R%)Ịoþ/ - Link: list of positive integers, Sizes | |
) - for each (size in Sizes): | |
R - range (size) -> [1,2,3,...,size] | |
% - modulo (size) -> [1,2,3,...,0] | |
Ị - insignificant? -> [...,[1,0,0,...,1],...] | |
/ - reduce by: | |
þ - make a table using: | |
o - logical OR (vectorises) | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 27 </s> 26 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>3ḍ6_BṙN€ṁ"Ḥ’rƊK€ṭ"Ḷ⁶ẋƊṚŒḄY | |
</code></pre> | |
<p>A full program that accepts a positive integer and prints using <code>0</code> as <code>*</code> and <code>1</code> as <code>-</code>.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/44Y5es3inhztn@j1qWvNwZ6PSwx1LHjXMLDrW5Q0WWAsU2PaocdvDXd3Huh7unHV00sMdLZH/gToB"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see <a href=""https://tio.run/##y0rNyan8/9/44Y5es3inhztn@j1qWvNwZ6PSwx1LHjXMLDrW5Q0WWAsU2PaocdvDXd3Huh7unHV00sMdLZH/D7e7Pdy52CDrUcNcLSDDEMTQ1cx61LiPi@v/f0MDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">a few</a> with <code>*</code> and <code>-</code> in place of <code>0</code> and <code>1</code>.</p> | |
<h3>How?</h3> | |
<pre><code>3ḍ6_BṙN€ṁ"Ḥ’rƊK€ṭ"Ḷ⁶ẋƊṚŒḄY - Main Link: positive integer, n | |
3ḍ - three divides (n)? -> 1 if n is a multiple of three else 0 | |
6 - six | |
_ - subtract -> 5 if n is a multiple of three else 6 | |
B - to binary -> 101 (i.e. "-*-") ...else 110 (i.e. "--*") | |
N€ - negate each (of implicit [1..n]) -> [-1,-2,...,-n] | |
ṙ - rotate (110 or 101) left by (each of those) -> Patterns (one for each row of bottom half of a hexagon) | |
Ɗ - last three links as a monad, f(n): | |
Ḥ - double -> 2n | |
’ - decrement -> 2n-1 | |
r - (2n-1) inclusive range (n) -> [2n-1..n] | |
" - zip (Patterns) and (range) applying, f(Pattern, i): | |
ṁ - mould like -> resized rows using repetition | |
K€ - join each with space characters -> Rows | |
Ɗ - last three links as a monad, f(n): | |
Ḷ - lowered range -> [0..n-1] | |
⁶ - space character | |
ẋ - repeat -> leading spaces for bottom half | |
" - zip (Rows) and (leading spaces) applying, f(row, spaces): | |
ṭ - tack (row) to (spaces) | |
Ṛ - reverse -> top of the hexagon | |
ŒḄ - bounce -> whole hexagon | |
Y - join with newline characters | |
- implicit, smashing print | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 <a href=""https://github.com/DennisMitchell/jelly/iki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<pre><code>Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ | |
</code></pre> | |
<p>A monadic Link accepting <span class=""math-container"">\$i\$</span> which yields a list of the first <span class=""math-container"">\$i\$</span> terms.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjiWH9j7csS3/WNejpjUPd3Qd3X1kWjCY2eQW8nDH4v///xuaAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>Ḥ½ḶoƊ€ḊŻĖS€ḂFTḣ - Link: positive integer, i | |
Ḥ - double -> 2i | |
€ - for each (x in [1..2i]): | |
Ɗ - last three links as a monad, f(x): | |
½ - square root (x) -> r | |
Ḷ - lowered range -> [0,1,2,3,4,...,floor(r)-1] | |
o - logical OR -> [x,1,2,3,4,...,floor(r)-1] | |
Ḋ - dequeue (drops the leading [1] from that list of lists) | |
Ż - prepend a zero | |
Ė - enumerate -> [[1,0],[2,[2]],[3,[3]],[4,[4,1]],...,[9,[9,1,2]],...,[16,[16,1,2,3]],...] | |
S€ - sum each -> [[1,[4],[6],[8,5]...[18,10,11],...[32,17,18,19],...] | |
Ḃ - mod 2 -> [[1,[0],[0],[0,1],...,[0,0,1],...,[0,1,0,1],...] | |
F - flatten | |
T - truthy indices (1-indexed) | |
ḣ - head to index (i) | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <sup><s>45</s></sup> 43 bytes</h1> | |
<pre><code>ṖẎƤṚ+"JpẎ€¥"Ʋṭ@€"J,€¥ɗẎṭḷ | |
Jçƒ0RWW¤Ẏị¹ZPSƊÐṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzmkPd/UdW/Jw5yxtJa8CIPtR05pDS5WObXq4c60DkK3kpQMWOTkdKAcUe7hjO5fX4eXHJhkEhYcfWgIS3N19aGdUQPCxrsMTHu5s@P//f7SxjoKRjoKpjoKJjoKFjoJBLAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Uses a modified <code>f(n)</code>, which is defined as sets of chords containing the vertex <code>n</code>.</p> | |
<hr /> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 45 bytes</h1> | |
<pre><code>ṖṚ+"JpẎ€¥"Ʋṭ@€"J,€¥ɗẎ;ṛ/{ṭḷ | |
Jçƒ0RWW¤Ṫị¹ZPSƊÐṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##TY29SsRAFEb7PMUl1QwzzGbizyaIINilWrRYMKSIkMhKWJYYZcVGLBVELBS0VYRFGxsd7bIQ8DHGF4l3xqBbzTfnfPfe/awojttWqxut7pgbTfTH5ffZc/3oNq9avWxgdiNuydctujWt7nsnaPT7mxPNn5prb2s4rB@0munPi1rtDLab8/mVVqdtmxPpUScnIXUYPh5lPSJZTgJKGZHcSMOl4T7yvuF@x4UQ1gbGhsyMow2ttctgHeI4SeyC/@ybbBED8nvTtIXoStjitrtQtlYU6UFF7FiRVTBdMLuHVSdHYyizIzI1tTId72Umbg5crOPcH5mkoxJ82saSwzKHgEOfg8SPz2GFQ8hhicMqIi/5AQ"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Painfully long, but runs pretty fast.</p> | |
<p>Basic algorithm is to compute all the possible sets of chords (as indices) via memoization. Let's define <code>f(n)</code> as the list of all possible sets of chords using first <code>n</code> nodes, i.e. <code>1..n</code>. <code>f(0)</code> and <code>f(1)</code> contain a single empty set, and <code>f(2)</code> is <code>[[], [[1, 2]]]</code>. Also, let's define <code>f(0..n)</code> to be <code>[f(0), f(1), ..., f(n)]</code>. Then the following recurrence holds:</p> | |
<pre><code>f(n+1) = f(n) ++ | |
cartesian product of f(0) and (1 + f(n-1)), with [1, n+1] added to each set ++ | |
cartesian product of f(1) and (2 + f(n-2)), with [2, n+1] added to each set ++ | |
... ++ | |
cartesian product of f(n-1) and (n + f(0)), with [n, n+1] added to each set | |
</code></pre> | |
<p>where <code>++</code> is list concatenation and <code>+</code> is vectorized addition.</p> | |
<pre class=""lang-none prettyprint-override""><code>ṖṚ+"JpẎ€¥"Ʋṭ@€"J,€¥ɗẎ;ṛ/{ṭḷ Aux. dyadic link: left=f(0..n), right=n+1 | |
Ṗ H = f(0..n-1) | |
AAAAAAAAAAbbbbccccɗ A(H) `b` (H `c` n+1) | |
Ṛ+"J Reverse H and add 1..n (zipped) | |
pẎ€¥" Cartesian product by concatenation with H | |
ṭ@€" Zipped append the following to each set: | |
J,€¥ [1,n+1], ..., [n,n+1] | |
Ẏ Collect lists of sets into one list of sets | |
;ṛ/{ Combine with the sets without n+1 | |
ṭḷ Push into f(0..n) to get f(0..n+1) | |
Jçƒ0RWW¤Ṫị¹ZPSƊÐṀ Main link: arg=a list | |
J Indices of the list | |
çƒ0RWW¤ Reduce over it using the aux link, starting from [[[]]] | |
Ṫị¹ Take the last result; convert the indices to actual values | |
ZPSƊÐṀ Find the set of chords with the highest sum of product | |
</code></pre> | |
<p>Probably I can golf it by <em>not</em> taking the right argument of the aux link (which is simply the length of the left arg), but I don't want to torture myself further...</p> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 29 bytes</h1> | |
<pre><code>JŒcŒPFQƑ$ƇŒcZFṢƑƊƇƊÐḟị¹P€S$ÐṀ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/r6KTko5MC3AKPTVQ51g7kRLk93Lno2MRjXcfaj3UdnvBwx/yHu7sP7Qx41LQmWAXI39nw////aEMjHQULHQUgaWSgo2BopqNgHgsA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>This is a total mess, extremely inefficient, possibly not working correctly and probably very outgolfable.</p> | |
<p><em>-2 bytes thanks to caird</em></p> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ØYxJĠẒỌY | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///wjMgKryMLHu6a9HB3T@T//wA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>ØY The string "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz" | |
xJ Repeat "B" once, "C" twice, "D" thrice... "z" 40 times. | |
Ġ Group indices by values: [[1], [2,3], [4,5,6], …, […820]] | |
↑B ↑C ↑D ↑z | |
Ẓ Is prime? | |
Ọ Translate 0,1 into "\x00","\x01" | |
Y Join lines | |
</code></pre> | |
" | |
"48934","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 13 bytes</h1> | |
<pre><code>ȷRẒṁ40RR¤ịØAY | |
</code></pre> | |
<p><a href=""https://tio.run/##AR8A4P9qZWxsef//yLdS4bqS4bmBNDBSUsKk4buLw5hBWf//"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Uses <code>Z</code> and <code>A</code> instead of <code>-</code> and <code>|</code>.</p> | |
<p>This is basically the same answer as <a href=""https://codegolf.stackexchange.com/users/68942/hyper-neutrino"">@hyper-neutrino</a>'s <a href=""https://codegolf.stackexchange.com/a/231193/48934"">answer</a>, which was published 3 minutes before mine, but our answers arose independently.</p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>40RRȷR¤ṁẒỌY | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCI0MFJSyLdSwqThuYHhupLhu4xZIiwiIiwiIixbXV0="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<blockquote class=""spoiler""> | |
<p> The <code>|</code>s are at prime indexes</p> | |
</blockquote> | |
<p>I figured out the pattern by smash-printing the rows into one flat string and realizing that the distribution looked familiar :P I had another idea to use base conversion but I decided to flatten the string first and then noticed.</p> | |
<p>Leaky Nun has two tricks in <a href=""https://codegolf.stackexchange.com/a/231195/68942"">their answer</a> - firstly, that you can take the range up to <code>1000</code> (which is shorter) since <code>mold</code> will discard extras, and secondly, I didn't notice other characters were allowed, so the digraph nilad <code>ØA</code> is shorter. Jonathan Allan also noticed that we can just use <code>chr</code> and output the unprintables 0x00 and 0x01, so thanks to both of them for the byte saves. Please go upvote Leaky Nun's answer as well.</p> | |
<pre><code>40RRȷR¤ṁẒỌY Main Link (Niladic) | |
40 Start at 40 | |
R Range; [1, 2, ..., 40] | |
R Range; [[1], [1, 2], [1, 2, 3], ...] | |
ṁ Mold; to the shape of [[1], [1, 2], [1, 2, 3], ...], reshape | |
ȷR¤ Range of 1000 ([1, 2, 3, ..., 1000]) - extra elements are discarded | |
Ẓ x => isprime(x) | |
Ọ chr | |
Y Join on newlines | |
</code></pre> | |
<p>There are a couple of ways to go about this idea - you can swap which list you generate first, you can index into a multitude of other strings, you can prime-check before or after molding since it vectorizes and thus doesn't really care what shape it is, etc.</p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 18 17 </s> 8 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-9 using <a href=""https://codegolf.stackexchange.com/a/231187/53748"">xnor's mathematical simplification</a> of the same method as the 17, below.</p> | |
<pre><code>²Ḥ_2ƽ+3 | |
</code></pre> | |
<p>A monadic Link that accepts a positive integer, <span class=""math-container"">\$L\$</span> and yields the maximal squares touched.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///Qpoc7lsQbHW47tFfb@P///6YGAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> Or see the <a href=""https://tio.run/##AR4A4f9qZWxsef//wrLhuKRfMsOGwr0rM//Dh@KCrP//NTA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">test-suite</a>.</p> | |
<h3>How?</h3> | |
<pre><code>²Ḥ_2ƽ+3 - Link: positive integer, L | |
² - square -> L² | |
Ḥ - double -> 2L² | |
_2 - subtract 2 -> 2L²-2 | |
ƽ - integer square-root -> ⌊√(2L²-2)⌋ | |
+3 - add three | |
</code></pre> | |
<hr /> | |
<p>17:</p> | |
<pre><code>²H½Ḟð‘Ḥ‘++²ḤƊ‘½<ʋ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///QJo9Dex/umHd4w6OGGQ93LAGS2tqHNgFZx7qA7EN7bU51////39QAAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<p>First finds the longest <span class=""math-container"">\$(a,a)\$</span> or <span class=""math-container"">\$(a,a+1)\$</span> diagonal that <span class=""math-container"">\$L\$</span> can cover with some to spare, then places the line along this diagonal, poking out at both ends, and shifts it in the <span class=""math-container"">\$x\$</span> direction to cover <span class=""math-container"">\$2a+3+X\$</span> squares where <span class=""math-container"">\$X=1\$</span> if the diagonal is <span class=""math-container"">\$(a,a+1)\$</span>, otherwise <span class=""math-container"">\$X=0\$</span>.</p> | |
<pre><code>²H½Ḟð‘Ḥ‘++²ḤƊ‘½<ʋ - Link: positive integer, L | |
² - square -> L² | |
H - halve -> L²/2 | |
½ - square-root -> side of square with diagonal L | |
Ḟ - floor -> a | |
ð - new dyadic chain, f(a,L)... | |
‘ - increment -> a+1 | |
Ḥ - double -> 2a+2 | |
‘ - increment -> 2a+3 | |
ʋ - last four links as a dyad, f(a, L): | |
Ɗ - last three links as a monad, f(a): | |
² - square -> a² | |
+ - (a) add (that) -> a+a² | |
Ḥ - double -> 2(a+a²) | |
‘ - increment -> 2(a+a²)+1 = a²+(a+1)² | |
½ - square-root -> diagonal length of (a,a+1) | |
< - less than (L)? -> 1 or 0 -> X | |
+ - (2a+3) add (X) | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jellylanguage"" rel=""nofollow noreferrer"">Jelly</a>, 17 bytes</h1> | |
<pre><code>;ṭ@Ṫ,Ṫ{;ʋ¥ØDi¥}?/ | |
</code></pre> | |
<p><a href=""https://jht.hyper-neutrino.xyz/tio#WyIiLCI74bmtQOG5qizhuap7O8qLwqXDmERpwqV9Py8iLCIiLCIiLFsiXCIxMmEzNGJjNTZkNzhlZmdcIiJdXQ=="" rel=""nofollow noreferrer"">Try It Online!</a></p> | |
<p>Since the input is guaranteed to be non-empty (clarified by OP), we do not need to reduce from an initial value and can replace <code>ƒ“”</code> with <code>/</code> (thanks to Leaky Nun for -2 bytes).</p> | |
<p>There's gotta be a better way to get rid of that <code>ṭ@Ṫ,Ṫ{;ʋ¥</code> mess in the middle.</p> | |
<pre><code>;ṭ@Ṫ,Ṫ{;ʋ¥ØDi¥}?/ Main Link | |
/ Reduce | |
? If | |
} - The right argument | |
i - Appears in | |
ØD - "0123456789" | |
; - Append it to the accumulating stack | |
Otherwise | |
--======¥ - Previous two; 2,2-chain x (a b) y = x a (x b y) | |
ṭ@ - Append to the accumulator the result of | |
-=--=ʋ - Previous four; 1,2,2,2-chain x (A b c d) y = (x A) b (x c y) d y | |
Ṫ - Pop the last element off the stack | |
, - And pair it with | |
Ṫ{ - Pop the last element off the left side (the stack) | |
; - Append the incoming character | |
</code></pre> | |
" | |
"48934","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 bytes</h1> | |
<p>Thanks to <a href=""https://codegolf.stackexchange.com/users/64121/ovs"">@ovs</a> for the fix.</p> | |
<pre><code>%Lċ0 | |
*ṗ’ÇƤ€QL | |
</code></pre> | |
<p><a href=""https://tio.run/##ASEA3v9qZWxsef//JUzEizAKKuG5l@KAmcOHxqTigqxRTP///zM"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>The first line computes the shadow transform.</p> | |
<p>The second line looks at the shadow transform of all sequences of length <code>n</code> with elements in <code>{1, 2, ..., n^n}</code>.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>ŻÆĿÆḞḂ?€ | |
</code></pre> | |
<p><a href=""https://tio.run/##AS0A0v9qZWxsef//xbvDhsS/w4bhuJ7huII/4oKs/8OHxZLhuZgpWf//MCwgNSwgMTg"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Close to a literal interpretation of the spec</p> | |
<h2>How it works</h2> | |
<pre><code>ŻÆĿÆḞḂ?€ - Main link. Takes N on the left | |
Ż - Range from 0 to N | |
€ - Over each integer k: | |
? - If: | |
Ḃ - Condition: k mod 2 | |
ÆĿ - Truthy: kth Lucas number | |
ÆḞ - Falsey: kth Fibonacii number | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>Ż^þ`G | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///o7rjD@xLc////bwkA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<pre><code>Ż^þ`G - Main link. Takes N on the left | |
Ż - Range from 0 to N | |
` - Using this range as both arguments: | |
^þ - Create an XOR table | |
G - Format into a padded grid | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 5 bytes</h1> | |
<pre><code>4ṗ>2Ġ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/9/k4c7pdkZHFvw/3O7@/78xAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a> Neil saved a byte. Thanks!</p> | |
<pre><code>4ṗ n-th Cartesian power of [1,2,3,4] | |
>2 Replace 1,2,3,4 with 0,0,1,1 | |
Ġ Group indices by values | |
</code></pre> | |
<p>For n=2, <code>4ṗ>2</code> generates a list of 16 pairs:</p> | |
<pre><code> 1: [0, 0] | |
2: [0, 0] | |
3: [0, 1] | |
4: [0, 1] | |
5: [0, 0] | |
6: [0, 0] | |
7: [0, 1] | |
8: [0, 1] | |
9: [1, 0] | |
10: [1, 0] | |
11: [1, 1] | |
12: [1, 1] | |
13: [1, 0] | |
14: [1, 0] | |
15: [1, 1] | |
16: [1, 1] | |
</code></pre> | |
<p>Then <code>Ġ</code> turns this into a list of lists:</p> | |
<ul> | |
<li>all indices where the value is <code>0 0</code>: namely <code>[ 1, 2, 5, 6]</code>,</li> | |
<li>all indices where the value is <code>0 1</code>: namely <code>[ 3, 4, 7, 8]</code>,</li> | |
<li>all indices where the value is <code>1 0</code>: namely <code>[ 9, 10, 13, 14]</code>,</li> | |
<li>all indices where the value is <code>1 1</code>: namely <code>[11, 12, 15, 16]</code>.</li> | |
</ul> | |
<p>The result is a Z-matrix.</p> | |
<h2>Why does this work?</h2> | |
<p>Suppose we bump the input up to <span class=""math-container"">\$n=3\$</span>. How does our output compare to that for <span class=""math-container"">\$n=2\$</span>?</p> | |
<p>Let's call <code>4ṗ>2</code> a function <span class=""math-container"">\$f\$</span>. The list of 16 pairs above is the output of <span class=""math-container"">\$f(2)\$</span>. By definition of the Cartesian power, <span class=""math-container"">\$f(3) = [0,0,1,1] \times f(2)\$</span> =</p> | |
<pre><code> [[0] + x for x in f(2)] (indices 1..16) | |
+ [[0] + x for x in f(2)] (indices 17..32) | |
+ [[1] + x for x in f(2)] (indices 33..48) | |
+ [[1] + x for x in f(2)] (indices 49..64) | |
</code></pre> | |
<p>There are now 8 values for <code>Ġ</code> to group the indices by, ranging from <code>[0,0,0]</code> to <code>[1,1,1]</code>.</p> | |
<p>All indices in <code>1..32</code> end up in the first four groups, and because we repeated <code>[[0] + x for x in f(2)]</code> twice, <code>a[i+16]</code> is always in the same group as <code>a[i]</code>. Then, all indices in <code>33..64</code> end up in the last four groups, and their relative order is the same as the first half of the list (the only difference is they have <code>1</code> instead of <code>0</code> in front). Within each quadrant, the order is the same as it was in <code>f(2)</code>. So we get:</p> | |
<pre><code>[0, 0, 0]: 1 2 5 6 17 18 21 22 | |
[0, 0, 1]: 3 4 7 8 19 20 23 24 | |
[0, 1, 0]: 9 10 13 14 25 26 29 30 | |
[0, 1, 1]: 11 12 15 16 27 28 31 32 | |
[1, 0, 0]: 33 34 37 38 49 50 53 54 | |
[1, 0, 1]: 35 36 39 40 51 52 55 56 | |
[1, 1, 0]: 41 42 45 46 57 58 61 62 | |
[1, 1, 1]: 43 44 47 48 59 60 63 64 | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>4*Ḷb4:2ḄĠ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/99E6@GObUkmVkYPd7QcWfD/cLv7///GAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Pretty much a port of <a href=""https://codegolf.stackexchange.com/a/231027/68942"">Neil's Charcoal answer</a>, so go upvote them too.</p> | |
<pre><code>4*Ḷb4:2ḄĠ Main Link; take x | |
4* 4 ** x | |
Ḷ [0, 1, 2, ..., 4 ** x - 1] | |
b4 Convert to base 4 | |
:2 Floor-divide by 2 | |
Ḅ Convert from binary | |
Ġ Group the indices by their corresponding values | |
</code></pre> | |
<p>This answer can be ported directly into yuno.</p> | |
<h1><a href=""https://github.com/hyper-neutrino/yuno"" rel=""nofollow noreferrer"">yuno</a>, 9 bytes</h1> | |
<pre><code>4*ʀb4:2ɮG | |
</code></pre> | |
<p><a href=""https://yuno.hyper-neutrino.xyz/#WyIiLCI0KsqAYjQ6MsmuRyIsIiIsIiIsIiIsWyIzIl1d"" rel=""nofollow noreferrer"" title=""yuno online interpreter"">Try it online!</a></p> | |
<hr /> | |
<p>This approach is probably what Bubbler's 6-byter is going for, but a) I need to find how to get <code>0,0,1,1</code> in 3 bytes, and b) I need to figure out how to make the format valid without the <code>s2*$</code> being that long:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>Ø.x2¤ṗỤs2*$ | |
</code></pre> | |
<p><a href=""https://tio.run/##ARwA4/9qZWxsef//w5gueDLCpOG5l@G7pHMyKiT///8z"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 16 bytes</h1> | |
<pre><code>,Uz0$FU | |
2*ḶBçþ`Ḅ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/18ntMpAxS2Uy0jr4Y5tToeXH96X8HBHy////40B"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 14 12 </s> 9 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<h3>9 byter</h3> | |
<pre><code>Ø.ṗḅ4+þḤ$ | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##ARwA4/9qZWxsef//w5gu4bmX4biFNCvDvuG4pCT///8z"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h5>How?</h5> | |
<p>Makes a table under <span class=""math-container"">\$x+2y\$</span> where both <span class=""math-container"">\$x\$</span> and <span class=""math-container"">\$y\$</span> are a prefix of the Moser–De Bruijn sequence.</p> | |
<pre><code>Ø.ṗḅ4+þḤ$ - Link: n | |
Ø. - bits -> [0,1] | |
ṗ - Cartesian power (n) -> binary representations of [0..2^n-1] | |
ḅ4 - convert from base four -> first 2^n terms of the Moser–De Bruijn sequence | |
$ - last two links as a monad, f(S): | |
Ḥ - double -> D=[2x for x in S] | |
þ - (s in S) table with (d in D): | |
+ - (s) add (d) | |
</code></pre> | |
<p>(Still no clue for the 6 byte code though!)</p> | |
<hr /> | |
<h3>12 Byter</h3> | |
<p>-1 thanks to <a href=""https://codegolf.stackexchange.com/users/66833/caird-coinheringaahing"">caird coinheringaahing</a> (we can use 1-based values)</p> | |
<pre><code>Ġ;"FL+ƊZƊ⁸¡⁺ | |
</code></pre> | |
<p>A monadic Link that accepts a non-negative integer and yields the matrix (using the 1-based values option).</p> | |
<p><strong><a href=""https://tio.run/##ASYA2f9qZWxsef//xKA7IkZMK8aKWsaK4oG4wqHigbr/w4fFkuG5mP//Mw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong> (Footer formats as a Python list for clarity.)</p> | |
<h5>How?</h5> | |
<p>Starts with <code>[[1]]</code> and repeatedly applies a function that creates the required new entries to the right (and then below, via the transposed matrix) by adding the number of current elements to each element.</p> | |
<pre><code>Ġ;"FL+ƊZƊ⁸¡⁺ - Link: non-negative integer, n | |
Ġ - group indices (of implicit [n]) by value -> [[1]] (our initial M) | |
¡ - repeat... | |
⁸ - ...number of times: chain's left argument -> n | |
Ɗ - ...what: last three links as a monad, f(M): | |
Ɗ - last three links as a monad, g(M): | |
F - flatten | |
L - length | |
+ - add to elements of M | |
" - zip (rows of M) with (rows of that) and apply: | |
; - concatenation | |
Z - transpose | |
⁺ - repeat last link (i.e. repeat f() n more times) | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 20 bytes</h1> | |
<pre><code>+Ø.÷€AĊc2ḋIɓN;æl¥ƒ-Ḋ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/1/78Ay9w9sfNa1xPNKVbPRwR7fnycl@1oeX5RxaemyS7sMdXf8PL9cHSv//Hx0dbWhkbKKjYGJsZBiroxBtpqNgqaNgaKCjYApGlrGxOlwKQFUGEACSgwKQcmOgotjYWAA"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Port of <a href=""https://codegolf.stackexchange.com/a/230991/78410"">my own APL answer</a>. Trailing <code>ɓ</code> chain trick is indeed strong :P</p> | |
<h3>How it works</h3> | |
<pre><code>+Ø.÷€AĊc2ḋIɓN;æl¥ƒ-Ḋ Dyadic link; left=range, right=divisors | |
xxxxxxxxxxxɓyyyyyyyy x(left, y(right, left)) | |
N;æl¥ƒ-Ḋ y: subset LCMs, negative for even-sized ones | |
N Negate the divisors | |
ƒ- Starting with -1, reduce by | |
;æl¥ current list ++ LCM(current list, next num) | |
Ḋ Remove the leading -1 | |
+Ø.÷€AĊc2ḋI x: range(start, end), subset LCMs -> answer | |
+Ø. Add 1 to the end | |
÷€AĊ Divide each by subset LCMs, abs, ceil | |
c2 nC2 of each | |
ḋ Dot product of each row with subset LCMs | |
I Increments (2nd - 1st) | |
</code></pre> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, <s>9</s> 8 bytes</h1> | |
<p>A port of <a href=""https://codegolf.stackexchange.com/a/230974/64121"">att's answer</a> and -1 byte thanks to them. Takes input as a pair of integers <code>[a, b]</code>.</p> | |
<pre><code>‘:ØpḋṚ+P | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9RwwyrwzMKHu7ofrhzlnbA/6N7Drc/alrjBsTu//9HG@oYxuoASSMwaQokjcAiRjomQNIEzDaBsi2BpDlYxBys3hwsYgkkAQ"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>‘ increment each value [a+1, b+1] | |
:Øp integer divide by phi [(a+1):phi, (b+1):phi] | |
ḋṚ dot product with the reverse (a+1):phi×b + (b+1):phi×a | |
+P add the product of the input (a+1):phi×b + (b+1):phi×a + a×b | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s> 30 </s> 29 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>-1 thanks to <a href=""https://codegolf.stackexchange.com/users/66833/caird-coinheringaahing"">caird coinheringaahing</a>!</p> | |
<pre><code>’1¦:בHIƲḢ×ʋⱮⱮœcⱮJæl/€€Ɗ}§Ṛḅ- | |
</code></pre> | |
<p><strong><a href=""https://tio.run/##y0rNyan8///hjkWPGmZaH@uyOjz9UcMMD89jm4BCh6ef6n60cR0QHZ2cDCS9Di/L0X/UtAaIjnXVHlr@cOeshztadf///x9taKClZa6jAKIsYv9HG@somMYCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>’1¦:בHIƲḢ×ʋⱮⱮœcⱮJæl/€€Ɗ}§Ṛḅ- - Link: [start, stop]; divisors | |
1¦ - apply to index 1 (of [start, stop]): | |
’ - decrement -> [start-1, stop] | |
} - using right (divisors): | |
Ɗ - last three links as a monad - f(divisors): | |
J - range of length -> [1,2,...,#divisors] | |
Ɱ - map with (for n in that): | |
œc - all ways to choose n of the divisors | |
€ - for each (list of choices of length n): | |
€ - for each (way to choose): | |
/ - reduce by: | |
æl - least common multiple | |
Ɱ - map across (for each list of LCMs): | |
Ɱ - map across (for each LCM): | |
ʋ - last four links as a dyad - f([start-1, stop],LCM): | |
: - integer divide -> [(start-1)//LCM, stop//LCM] | |
call this "[A,B]" | |
Ʋ - last four links as a monad - f([A,B]): | |
‘ - increment -> [A+1,B+1] | |
× - multiply -> [A(A+1),B(B+1)] | |
H - halve -> [A(A+1)/2,B(B+1)/2] | |
I - differences -> [B(B+1)/2-A(A+1)/2] | |
Ḣ - head -> B(B+1)/2-A(A+1)/2 | |
× - multiply -> LCM(B(B+1)/2-A(A+1)/2) | |
§ - sums -> [sum of single-choices, sum of two-choices, ...] | |
Ṛ - reverse | |
ḅ- - convert from base -1 -> 1×(sum of single-choices)+-1×(sum of two-choices)+... | |
</code></pre> | |
<hr /> | |
<p>With fewer loops using the same approach, also 30 bytes:</p> | |
<pre><code>Ḣ’;Ɗ:בHIƲḢ×ʋæl/}¥ⱮⱮœcⱮJ$}§Ṛḅ- | |
</code></pre> | |
<hr /> | |
<p>With no constraint on computational complexity, 7 bytes (-1 thanks to caird again!):</p> | |
<pre><code>r/ọẸ¥ƇS | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 25 bytes</h1> | |
<pre><code>¹©R‘U;ṖÆḞS>®Ʋ¡¥ƒ“”)p/§ÆḞS | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///QzkMrgx41zAi1frhz2uG2hzvmBdsdWnds06GFh5Yem/SoYc6jhrmaBfqHlkPk/v//b66jYAkA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-4 bytes thanks to caird coinheringaahing</p> | |
<p>Non-brute force answer that should run in <span class=""math-container"">\$O(N^2)\$</span> time. Still trying to figure out how to remove the register usage.</p> | |
<p>Basically, constructs the Fibonacci coding by starting from an upper bound and counting down, adding in the largest Fibonacci number that can fit each time. Since I am summing the accumulating list each time, and I think the output list is roughly <span class=""math-container"">\$O(\log N)\$</span> in size, I <em>believe</em> this is <span class=""math-container"">\$O(N \log N)\$</span>, but I'm not sure, so I'll just put down <span class=""math-container"">\$O(N^2)\$</span> for now.</p> | |
<pre><code>¹©R‘U;ṖÆḞS>®Ʋ¡¥ƒ“”)p/§ÆḞS Main Link (monadic): accept [x, y] | |
) For each k in [x, y] | |
¹© Save it to the register | |
R Range; [1, 2, ..., k] | |
‘ Increment; [2, 3, ..., k + 1] | |
U Reverse; [k + 1, k, ..., 2] | |
;ṖÆḞS>®Ʋ¡¥ƒ“” Reduce this list starting from []: | |
-========¥ Last two as a dyad: | |
; - append the new value to the list | |
¡ - then, N times (if statement for boolean values) | |
ÆḞS>®Ʋ - if the sum of those Fibonacci numbers exceeds the desired value | |
Ṗ - pop the last addition back off | |
p/ Cartesian product of the results | |
§ Sum of each; get the indexes | |
ÆḞ Convert to Fibonacci numbers | |
S Sum | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 18 bytes</h1> | |
<pre><code>ŒP‘ÆḞS=ɗƇ¹Ḣ)p/§ÆḞS | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIBHDTMOtz3cMS/Y9uT0Y@2Hdj7csUizQP/Qcojg////zXUULAE"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 byte thanks to caird coinheringaahing</p> | |
<hr /> | |
<p>I have posted a video explanation of this answer and how to approach this problem as well as the mathematical observation below to <a href=""https://www.youtube.com/channel/UCjWrRy5b2fntu1-u5EiFNtw"" rel=""nofollow noreferrer"">my YouTube channel</a>. You can see the video <a href=""https://www.youtube.com/watch?v=IRJqGcYsKlc"" rel=""nofollow noreferrer"">here</a>.</p> | |
<hr /> | |
<p>Assume that there is a sequence of Fibonacci numbers where two are consecutive. Select the largest two such terms and them be <span class=""math-container"">\$F_n\$</span> and <span class=""math-container"">\$F_{n+1}\$</span>. Then, <span class=""math-container"">\$F_{n+2}\$</span> cannot be in the sequence because then it would be consecutive with <span class=""math-container"">\$F_{n+1}\$</span> and thus contradict the definition. Therefore, we replace <span class=""math-container"">\$F_n,F_{n+1}\$</span> with <span class=""math-container"">\$F_{n+2}\$</span> in the sequence and we now have a shorter sequence that sums to the same value.</p> | |
<p>Keep repeating this process indefinitely, and we can see that the shortest sequence of Fibonacci numbers that sums to <span class=""math-container"">\$N\$</span> has to be the unique one containing no consecutive terms, otherwise we can reduce it to something shorter, which would be a contradiction.</p> | |
<p>Thus, we only need to find the <em>shortest</em> sequence. Here follows the explanation of the Jelly code itself:</p> | |
<pre><code>ŒP‘ÆḞS=ɗƇ¹Ḣ)p/§ÆḞS Main Link; accept a list [x, y] | |
) For each k of x and y | |
ŒP Take the powerset of [1, 2, ..., k], shortest & lexicographically least first | |
‘ Add one (now we have the powerset of [2, 3, ..., k + 1]) | |
Ƈ Filter; keep terms where | |
ÆḞ Taking the Nth fibonacci number | |
S and summing | |
= is equal to | |
¹ k itself | |
Ḣ And take the first (thus shortest) such subset | |
p/ Take the cartesian product of the two codings | |
§ Sum each pair | |
ÆḞ Get the Nth fibonacci number for each | |
S and sum | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 22 bytes</h1> | |
<pre><code>ŒP‘I’ẠƊƇÆḞS=ɗƇ)p"/§ÆḞ§ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///opIBHDTM8HzXMfLhrwbGuY@2H2x7umBdse3L6sXbNAiX9Q8vBAoeW/3@4Y9PDHYuNwh41rTnc/nDHoqOTHu6cwfVw95bD7UChyP//DRUMFXTtFIy5DBWMQAxTIMMUxDA05jKCyJkCGSZgIQsuE4iQoSGQBRYzMQCyLEEsC3Muc6ishQKQCTbOyBLIAksbmhhyWUKZFpYA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>This feels grossly long.</p> | |
<p>Returns <code>[x]</code> where <code>x</code> is the expected output. This is <a href=""https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/11884#11884"">allowed by default</a></p> | |
<p>-1 byte thanks to <a href=""https://codegolf.stackexchange.com/users/68942/hyper-neutrino"">hyper-neutrino</a></p> | |
<hr /> | |
<h2>How it works</h2> | |
<pre><code>ŒP‘I’ẠƊƇÆḞS=ɗƇ)p"/§ÆḞ§ - Main link. Takes [a, b] on the left | |
) - For each input: | |
ŒP - Cast to range, then powerset | |
‘ - Increment each one | |
ƊƇ - Keep those for which the following is true: | |
I - Forward differences | |
’ - Decrement | |
Ạ Are all non-zero? | |
This removes all lists with any consecutive indices | |
ɗƇ - Keep those for which the following is true: | |
ÆḞ - Convert each index to its Fibonacci number | |
S= - Does the sum equal the input? | |
p"/ - Get the Cartesian product of the indices | |
The " (vectorise) quick allows us to avoid extracting the | |
first element, instead we operate with everything | |
wrapped to an additional depth | |
§ - Sums | |
ÆḞ - Fibonacci number of each | |
§ - Sum | |
</code></pre> | |
" | |
"48934","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 29 bytes</h1> | |
<pre><code>n1‘S> | |
⁵*ḶD“”ṭçÐḟ | |
‘Ç€ŒpF€ḌạÐṂḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/P8FHDjGA7rkeNW7Ue7tjm8qhhzqOGuQ93rj28/PCEhzvmcwGlD7c/alpzdFKBG5B6uKPn4a6FQKmdTQ93LPr//3@0Uex/Q0MDAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 34 bytes</h1> | |
<pre><code>‘ؽṗⱮẎS=¥ƇƲ€ŒpF€ị⁵Ḷṭ1¤Œp€ŒP€€ḌFạÞḢ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9Rw4zDMw7tfbhz@qON6x7u6gu2PbT0WPuxTY@a1hydVOAGpB7u7n7UuPXhjm0Pd641PLQEKAqWCwCSINkdPW4Pdy08PO/hjkX///830jH@bwQEAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-2 bytes thanks to caird coinheringaahing</p> | |
<p>This is absolutely horrible. I won't be surprised if someone can halve my bytecount. I spent a decent bit of time on it; not too much - I'll keep golfing this but I think it's at least close to worth posting.</p> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>ØqḊ€ż“[;,”F,Fyɠ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASwA0/9qZWxsef//w5hx4biK4oKsxbzigJxbOyzigJ1GLEZ5yaD//yA7cDs7b1twWw"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input via STDIN</p> | |
<h2>How it works</h2> | |
<pre><code>ØqḊ€ż“[;,”F,Fyɠ - Main link. Takes no arguments | |
Øq - Set the return value to ['qwertyuiop', 'asdfghjkl', 'zxcvbnm'] | |
Ḋ€ - Dequeue each; ['wertyuiop', 'sdfghjkl', 'xcvbnm'] | |
ż“[;,” - Zip with "[;,"; [['wertyuiop', '['], ['sdfghjkl', ';'], ['xcvbnm', ',']] | |
F - Flatten; "wertyuiop[sdfghjkl;xcvbnm," | |
F - Flatten the return value; "qwertyuiopasdfghjklzxcvbnm" | |
, - Pair; ['wertyuiop[sdfghjkl;xcvbnm,', 'qwertyuiopasdfghjklzxcvbnm'] | |
ɠ - Read a line from STDIN | |
y - Translate. Map w -> q, e -> w, etc. | |
</code></pre> | |
" | |
"101522","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 4 bytes</h1> | |
<pre><code>Æṣ⁺= | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9w28Odix817rL9//@/kZEBAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>My first Jelly answer! Doesn't really make use of any of the quirks of Jelly as a tacit language, but I'm still learning it.</p> | |
<p>Explanation:</p> | |
<pre><code>Æṣ # Sum of proper divisors of input | |
⁺ # Duplicate last link: Æṣ | |
= # Result of previous link = Input? | |
</code></pre> | |
" | |
"78410","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>Æfð_ọḟ>1Ȧ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wW9rhDfEPd/c@3DHfzvDEsv@H2x81rfn/P9pQR8HQVEfByFJHwdhAR8HMTEfB1NhIR8HC1AIoY24EZJoYmRvGAgA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Æfḟð_ọḷ’Ȧ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8//9wW9rDHfMPb4h/uLv34Y7tjxpmnlj2/3D7o6Y1//9HG@ooGJrqKBhZ6igYG@gomJnpKJgaG@koWJhaAGXMjYBMEyNzw1gA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>I already lost, but figured I'd post them since they're somewhat different 9-byters.</p> | |
<h3>How these work</h3> | |
<p>The condition <span class=""math-container"">\$p_i \mid \left( \frac n {p_i} -1 \right)\$</span> can be translated to</p> | |
<p><span class=""math-container"">$$ | |
\frac{n}{p_i}-1 \equiv 0 \quad(\operatorname{mod} \ p_i) \\ | |
\frac{n}{p_i} \equiv 1 \quad(\operatorname{mod} \ p_i) \\ | |
n \equiv p_i \quad(\operatorname{mod} \ p_i^2) | |
$$</span></p> | |
<p>So <span class=""math-container"">\$n-p_i\$</span> (equivalently, <span class=""math-container"">\$p_i-n\$</span>) must be divisible by <span class=""math-container"">\$p_i\$</span> at least twice.</p> | |
<pre class=""lang-none prettyprint-override""><code>Æfð_ọḟ>1Ȧ Monadic link; input = n | |
Æf List of prime factors of n (= L) | |
ð...... Call ... as a dyadic chain, left = L, right = n | |
ọ How many times each of... | |
_ L - n | |
...is divisible by... | |
ḟ Remove any occurrences of n from L | |
(missing positions are treated as 0, so ọ gives 0) | |
>1Ȧ Test if the result is nonempty list of all 2s or above | |
Æfḟð_ọḷ’Ȧ Monadic link; input = n | |
Æfḟ Remove any occurrences of n from prime factors of n (= L) | |
ð..... Call ... as a dyadic chain, left = L, right = n | |
_ọḷ How many times each of L-n is divisible by each of L | |
’Ȧ Test if the result, decremented, is nonempty with all nonzero | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 8 bytes</h1> | |
<pre><code>Æfḟɓ÷’ọȦ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASIA3f9qZWxsef//w4Zm4bifyZPDt@KAmeG7jcim/8i3NMOHxof/"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>This version is mostly caird's, and I merged one of my golfs into it. Posted with their permission.</p> | |
<pre><code>Æfḟɓ÷’ọȦ Main Link | |
Æf Take the prime factors | |
ḟ And filter out the original (if x is prime, this list is empty, otherwise, nothing changes) | |
ɓ---- Call this chain dyadically with reversed arguments: x on the left, factors on the right | |
÷ Divide x by each factor | |
’ Decrement each quotient | |
ọ Count divisibility of each result by the corresponding factor | |
Ȧ Are any and all truthy? That is, the list is all truthy and is not empty | |
</code></pre> | |
<p>This was my original solution:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 9 bytes</h1> | |
<pre><code>:’ọɗÆfȦ>Ẓ | |
</code></pre> | |
<p><a href=""https://tio.run/##ASIA3f9qZWxsef//OuKAmeG7jcmXw4ZmyKY@4bqS/8i3NMOHxof/"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Gives <code>1</code> for Guiga numbers and <code>0</code> otherwise.</p> | |
<pre><code>:’ọɗÆfȦ>Ẓ Main Link (monadic) | |
---ɗ Last three links as a dyad | |
Æf Monad - get array of prime factors | |
:’ọ Since this is a 2,1-chain, this dyadic section is called with `x` on the left and the prime factors on the right | |
: - divide x by each prime factor | |
’ - decrement each | |
ọ - how many times is each result divisible by its matching prime factor? | |
Ȧ Check if all are true | |
>Ẓ 2,1-chain: check if that result is greater than whether or not x is prime (in other words, true if and only the above check was true and it is not a prime) | |
</code></pre> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>7</s> 6 bytes</h1> | |
<pre><code>_ḋ⁵⁶+e | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/z/@4Y7uR41bHzVu0079//9/tKGpjgIIG5voKBiZxgIFQLSOgpkREJsD@QZAeTAyMjY1NDM0if1vaWFuZm5haQwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes four arguments: growths, attacks, hits, heads.</p> | |
<h2>Explanation</h2> | |
<pre><code>_ḋ⁵⁶+e Main dyadic link | |
_ Subtract: growths - attacks | |
ḋ Dot product with | |
⁵ third argument: hits | |
+ Add | |
⁶ fourth argument: heads | |
e Is it an element of the second argument: attacks? | |
</code></pre> | |
" | |
"53748","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 13 <a href=""https://github.com/DennisMitchell/jelly/wiki/Code-page"" rel=""nofollow noreferrer"">bytes</a></h1> | |
<p>Started looking for ways to golf <a href=""https://codegolf.stackexchange.com/a/230772/53748"">xigoi's great Jelly answer</a> but it took a fair bit of effort so thought I'd post instead.</p> | |
<pre><code>8ṗ4+"JḶ$ṬSƲ€ċ | |
</code></pre> | |
<p>A monadic Link that accepts the list (using the no-trailing zeros option) and yields the count.</p> | |
<p><strong><a href=""https://tio.run/##y0rNyan8/9/i4c7pJtpKXg93bFN5uHNN8LFNj5rWHOn@//9/tKEOCBqBoWEsAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></strong></p> | |
<h3>How?</h3> | |
<pre><code>8ṗ4+"JḶ$ṬSƲ€ċ - Link: list of non-negative integers, Totals | |
8 - eight | |
4 - four | |
ṗ - ([1..8]) Cartesian power (4) -> all length 4 lists using [1..8] | |
€ - for each (list of four "start indices", I, in that): | |
Ʋ - last four links as a monad - f(I): | |
$ - last two links as a monad - g(I): | |
J - range of length -> [1,2,3,4] | |
Ḷ - lowered range -> [[0],[0,1],[0,1,2],[0,1,2,3]] | |
" - (I) zip (that) with: | |
+ - addition -> [[0+i1],[0+i2,1+i2],[0+i3,1+i3,2+i3],[0+i4,1+i4,2+i4,3+i4]] | |
Ṭ - un-truth -> [[0...0,1],[0...0,1,1],[0...0,1,1,1],[0...0,1,1,1,1]] | |
(number of zeros being i1-1, i2-1, i3-1, and i4-1 respectively) | |
S - sum (column-wise) | |
ċ - count occurrences (of the input list, Totals) | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 11 bytes</h1> | |
<pre><code>æ*÷!}ɗⱮ⁹Ḷ¤S | |
</code></pre> | |
<p><a href=""https://tio.run/##PVG7TcRAEM2niiFFWsmza3vtCigAiQ5ITtcAAcGRXAEEFAAiOiGBkLkTEoEtAsqwGzHvjQ3SfmZn3mfG3lxvtzfzPDyfDx9ntz8P0@vLtDuNx65/upzHz/fx@DbdHa6wsYb9hXzfj6fHaffVd3037JHcrI95LrQQbjGNkrRkwIyJBCs0ZKk1IY5qNdIZdYSNhgr1pFxZcIYafGnUWo1gt4IgAAekmWScNZD@INoq7JIUj7KyRF3Ikk/gst0Y0FDSIzQM6N1odIlqAYsbuL/3DUlLgghqmVlAMWVImrR1ojEMrBjToOMM8b9TsEpXDbbg2IHLR79ZbL2JFUEr76uQv/nYRumKITvKWNPVp1mIK60RzFfpysBfwI3O2IZyTI6FT0S3Xw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<h2>How it works</h2> | |
<p>Basically, we calculate <span class=""math-container"">$$\sum_{r=0}^{255} \frac {M^r} {r!}$$</span> which is large enough to not have to worry about precision. For one additional byte, we can instead calculate <span class=""math-container"">$$\sum_{r=0}^{10^9} \frac {M^r} {r!}$$</span>, which is, for all intents and purposes, equal to <span class=""math-container"">$$\sum_{r=0}^\infty \frac {M^r} {r!}$$</span></p> | |
<pre><code>æ*÷!}ɗⱮ⁹Ḷ¤S - Main link. Takes M on the left | |
¤ - Group the previous links into a constant: | |
⁹ - 256 | |
Ḷ - Lowered range; [0, 1, ..., 255] | |
ɗ - Group the previous 3 links into a dyad f(M, i): | |
æ* - Raise M to the i'th power | |
} - To i: | |
! - Factorial | |
÷ - Divide each element of Mⁱ by i! | |
Ɱ - Over each i in [0, 1, ..., 255], calculate f(M, i) | |
S - Sum | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 18 bytes</h1> | |
<pre><code>-©‘+³æ*‘ɼ¤÷®!¤¤$ÐL | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/1/30MpHDTO0D20@vEwLyDi559CSw9sPrVM8tOTQEpXDE3z@//8fbWiko2BooaOgaxqroxCta2gM5IKwOYgLYuma6SgYxQIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-5 bytes thanks to caird coinheringaahing</p> | |
<p>This is probably the least Jelly-like Jelly answer ever. Goes for unbounded precision, even though 1/256! (which is what caird coinheringaahing's solution does) is definitely enough in practice.</p> | |
<p>This only terminates due to limited precision. If we had infinite/unbounded precision, this would never stop running. It basically just keeps adding terms until the result stops changing, which means we've hit the precision limit.</p> | |
<p>Or actually, this is more cursed:</p> | |
<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 34 bytes</h1> | |
<pre><code>ŒṘ“çm(<ÇƤMʂƲṬVḅċñ!żŒȥu¢iİẠẈ“œ4»jŒV | |
</code></pre> | |
<p><a href=""https://tio.run/##AVgAp/9qZWxsef//xZLhuZjigJzDp20oPMOHxqRNyoLGsuG5rFbhuIXEi8OxIcW8xZLIpXXComnEsOG6oOG6iOKAnMWTNMK7asWSVv///1sxLCAyXSwgWzMsIDRd"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-3 bytes thanks to Unrelated String.</p> | |
" | |
"64121","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>7</s> 6 bytes</h1> | |
<p>Uses the same formula as Lynn's Haskell answer.</p> | |
<p>-1 byte thanks to <a href=""https://codegolf.stackexchange.com/users/95126/dominic-van-essen"">Dominic van Essen</a>!</p> | |
<pre><code>Ḷ÷⁵CPC | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hjm2Htz9q3Ooc4Pzf0BDEa3/UtCbyPwA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<pre><code>Ḷ lowered range: [0, 1, ..., n-1] | |
÷⁵ divide each value by 10 [0/10, 1/10, ..., (n-1)/10] | |
C complement, subtract each from 1 [10/10, 9/10, ..., (11-n)/10] | |
P take the product of all values (10/10)*(9/10)* ... *(11-n)/10 | |
C complement 1 - (10/10)*(9/10)* ... *(11-n)/10 | |
</code></pre> | |
" | |
"98955","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 15 bytes</h1> | |
<pre><code>żJØ.xⱮS | |
8Ḷṗ4Ç€ċ | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///oHq/DM/QqHm1cF8xl8XDHtoc7p5scbn/UtOZI938w/f9/NFe0iY6xjpGOYawOV7ShDgga6RgAMVzIAAhBgiiqjCAqQFIgIQOoABBCuDBNYG0Io2EWGKFqMkS13giiDt0uNDUQ18QCAA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes input without trailing zeros.</p> | |
<h2>Explanation</h2> | |
<pre><code>żJØ.xⱮS Auxiliary monadic link, taking a list of 4 integers | |
ż Zip with | |
J indices: [1,2,3,4] | |
x Repeat | |
Ø. [0,1] | |
[a,b] times respectively | |
Ɱ for each [a,b] in the list | |
S Sum | |
8Ḷṗ4Ç€ċ Main monadic link, taking a list of integers | |
8 8 | |
Ḷ Lowered range: [0,1,2,3,4,5,6,7] | |
ṗ4 Cartesian 4th power | |
Ç Apply the auxiliary link | |
€ to each | |
ċ Count the occurences of the input | |
</code></pre> | |
" | |
"66833","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>16</s> 15 bytes</h1> | |
<pre><code>“LɓịNH’D+28⁸;ḣS | |
</code></pre> | |
<p><a href=""https://tio.run/##ASgA1/9qZWxsef//4oCcTMmT4buLTkjigJlEKzI44oG4O@G4o1P///8xOf82"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes <span class=""math-container"">\$d\$</span> then <span class=""math-container"">\$m\$</span> on the command line</p> | |
<pre><code>“LɓịNH’D+28⁸;ḣS - Main link. Takes d on the left and m on the right | |
“LɓịNH’ - Compressed integer; 303232332323 | |
D - Convert to digits; [3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3] | |
+28 - Plus 28 to each; [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
⁸; - Prepend d; [d, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
ḣ - Take the first m | |
S - Sum | |
</code></pre> | |
" | |
"3852","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""noreferrer"">Jelly</a>, 12 bytes</h1> | |
<pre><code>p1Ṛ;@pỤɓḊU^1 | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8/7/A8OHOWdYOBQ93Lzk5@eGOrtA4w/@Hl@sfnfRw5wzNyP//ow11FAxjdRSiDQ1gDB0FSxBtqqNgDqJNdBRMYwE"" rel=""noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>Takes (height, width) arguments and returns the sequence.</p> | |
<p>Unrelated String saved two bytes. Thank you!</p> | |
<h2>Explanation for (width, height) = (7, 5)</h2> | |
<p><code>ḊU^1</code> is <code>[width..2]</code> each XORed with <code>1</code>: <code>[6,7,4,5,2,3]</code>.</p> | |
<p>We take the Cartesian <code>p</code>roduct of <code>[1..height]</code> and that. The result is a list of <code>6×5</code> pairs:</p> | |
<pre><code>[[1,6], [1,7], [1,4], [1,5], [1,2], [1,3], | |
[2,6], [2,7], [2,4], [2,5], [2,2], [2,3], | |
[3,6], [3,7], [3,4], [3,5], [3,2], [3,3], | |
[4,6], [4,7], [4,4], [4,5], [4,2], [4,3], | |
[5,6], [5,7], [5,4], [5,5], [5,2], [5,3]] | |
</code></pre> | |
<p>Then, <code>p1Ṛ;@</code> appends <code>[[5,1],[4,1],[3,1],[2,1],[1,1]]</code> to this list, for a total of <code>7×5</code> pairs.</p> | |
<pre><code>[[1,6], [1,7], [1,4], [1,5], [1,2], [1,3], | |
[2,6], [2,7], [2,4], [2,5], [2,2], [2,3], | |
[3,6], [3,7], [3,4], [3,5], [3,2], [3,3], | |
[4,6], [4,7], [4,4], [4,5], [4,2], [4,3], | |
[5,6], [5,7], [5,4], [5,5], [5,2], [5,3], [5,1], [4,1], [3,1], [2,1], [1,1]] | |
</code></pre> | |
<p>Wow, this all seems like it's getting us nowhere! But:</p> | |
<ul> | |
<li>The lexicographically smallest element <code>[1,1]</code> is found at index <code>35</code>,</li> | |
<li>and the second smallest element <code>[1,2]</code> is at index <code>5</code>,</li> | |
<li>and the third smallest element <code>[1,3]</code> is at index <code>6</code>,</li> | |
<li>...</li> | |
<li>and the largest element <code>[5,7]</code> is at index <code>26</code>.</li> | |
</ul> | |
<p>so in other words, the "grade" <code>Ụ</code> is an elevator sequence, and we're done.</p> | |
" | |
"85334","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, <s>18</s> 17 bytes</h1> | |
<pre><code>×µð_ḶœsḂ_$Þ€ż@_ⱮF | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///w9ENbD2@If7hj29HJxQ93NMWrHJ73qGnN0T0O8Y82rnP7f3i5/qOGGd6akf//RxvqKBjG6iiAaQMQwxIqYK6jYAqiTXUUTGIB"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p><em>-1 byte trading one dyad-identity-dyad chain for another</em></p> | |
<p>Width on the left, height on the right. 0-indexed. Still feels a bit golfable. Ties the similar, arguments-reversed <code>_ḶœsḂ_$Þ€ż@_ⱮFð@×</code>. (Speaking of tying, take a peek at the edit history for a good laugh.)</p> | |
<pre><code>× Let the product of the arguments | |
µð be the left argument to the following dyadic chain: | |
_Ḷ [0 .. product-height-1] | |
œs split into as many slices as the height. | |
Þ€ Sort the elements of each ascending by | |
Ḃ_$ (x % 2) - x. | |
ż@ Interleave the slices after each | |
_Ɱ product - each [1 .. height], | |
F and flatten to obtain the sequence. | |
</code></pre> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 34 bytes</h1> | |
<pre><code>R}Uð×RœṖ@’בɗœsL}¹;"U}¥ʋ/s€2Ṛ€FðỊ? | |
</code></pre> | |
<p><a href=""https://tio.run/##AUcAuP9qZWxsef//Un1Vw7DDl1LFk@G5lkDigJnDl@KAmMmXxZNzTH3CuTsiVX3CpcqLL3Pigqwy4bma4oKsRsOw4buKP////zX/Nw"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
" | |
"68942","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 19 bytes</h1> | |
<pre><code>ṡ€ZL$}¹ṡL}Z€Ẏa€¬Ȧ€S | |
</code></pre> | |
<p><a href=""https://tio.run/##y0rNyan8///hzoWPmtZE@ajUHtoJZPvURgG5D3f1JQKpQ2tOLANSwf8PL9cH0v//R3NxAhFndLShjoIBGBliolgdBag8RABdIVQeUxLCNkCRN8S0BSGP136EgUgIrzw296EhsPtidcBhYICkFkSD@bFcnCD2IAokQ3oFkgG2QDJEcivWQDKA60W1EqoYw7sQA@CGYxhmgGKYAVbDkLTjNMEAh2aCwkipAy1YUNxkiOJUbKoJOAvdIWixZUjAoYTksXkUM0EYkqQf3WZ09xPyH1Z5Q4L2IyVF1JwzGsQ0CWJDXEGMtxwiVLzh8KchFufB7dZBilnkIgHJv7gdiFHEESGAXjBxxQIA"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>-1 byte thanks to Nick Kennedy</p> | |
<pre><code>ṡ€ZL$}¹ṡL}Z€Ẏa€¬Ȧ€S Main Link; accept piece 2 on the left and piece 1 on the right | |
ṡ€ Get all overlapping slices of piece 2 of length | |
ZL$} Width of piece 1 | |
¹ (Identity) | |
ṡ Slice this into overlapping pieces of length | |
L} Height of piece 1 | |
Z€ Transform each to get it to the correct orientation | |
Ẏ Flatten once; we now have a list of 2D blocks in piece 2 | |
a€ Logical AND with piece 1 (vectorizing); gives intersection areas | |
¬ Logical NOT (vectorize) | |
Ȧ€ For each chunk, check if all are truthy (i.e. none were truthy initially; 1 if it fits, 0 otherwise) | |
S Sum; count number of positions that fit | |
</code></pre> | |
" | |
"42248","<h1><a href=""https://github.com/DennisMitchell/jelly"" rel=""nofollow noreferrer"">Jelly</a>, 168 bytes</h1> | |
<pre><code>ṫ-;Ṛ×+ƭ/⁸; | |
%@’п/:ƝṖṚçƒØ.ṫ-××%P{ | |
’ÆfQ$€m2Ṛż$©f/ÐḟFḢWḟ"Ṛ¥€FḊ$ÐḟZ;FQɗ"ʋ@ƬƲṪF®ḟ€ƑƇẈ⁼Ø1ƊƇƲF€fƇFQɗⱮ`ÐLQƲ,@$ŒPżṚ$F€€;"€ʋ@/;"Ɱ®f"Ẹ¥ÐḟFQɗḟF}ɗŒPżṚ$Ʋ$€Ẏf"ⱮẸ€ẠɗƇ®P€ḤżUƊ$€ẎNÞ祀⁸FṂ | |
</code></pre> | |
<p><a href=""https://tio.run/##PVBPi9NAFL/3U4SSPe3sJpmZTlMD0lNOIu1BRE9ejLCsF28iQncRI12Qugezin8WsRR1LWxPaS0uZOxA/RaTLxLfbxShffn9m/fmzcH9w8PHzaNg3/44eaB/mnE9elPN7Oq8sctve4ldvtXFrvke1Edl0trpk6sn1VVwzby3y9dwZ@ZUn@0jrAtd7AyetJB5ng39@vjiIafIZu1XX7JAT2z5MbXlp9v0bZNeTSlBwth31t0kHW6L9u@TvrkwC7v8mlZzkiljXpncrl7UR2t9Fpmxyc0iJTkzOU7Ul/N7enJjaBas729OB5s19fYRoF/SpkItAwKX82qete2qrKZ/70KH8Xm6Lf4fMwtc265eZshT1rHzbWHyaj4AKT9v1rfM@F/spv6gZ24ReqDULo@bROcJ241@XW2Lauof1KN33t51rx7Rez1r6ZySd5omUoxzJiQTiknFOoopyZRi3ZB1qcYsViyOWY8zryfpr5gXhSEKUMRRHIqpcBicYpEAEkASEekQch0gBVfBiKH1QNGZh@TyKEQBRVOOppzu6HHhCjS04hKoA7cDiqYcTbmC0YUWQ4sdgoYtuBvUIyqwhwg5CmkCcwXmCowU2ENwRxHGRkKASiCsJXANgeFCoXShdRGOgfBeAtMkBknsJkNHKSIjUEyTGCS5QzBE@Ac"" rel=""nofollow noreferrer"" title=""Jelly – Try It Online"">Try it online!</a></p> | |
<p>A full program taking an integer argument and returning an integer. Works on TIO to solve a for all values of n between 16 and 118 inclusive within 60 seconds. Individually it manages every n up to 130 within 60 seconds.</p> | |
<p>I’ll post a full explanation later, but crudely it works like this:</p> | |
<ol> | |
<li>Partition primes <n such that all <span class=""math-container"">\$i\$</span> or <span class=""math-container"">\$n-i\$</span> for <span class=""math-container"">\$i\$</span> from <span class=""math-container"">\$1\$</span> to <span class=""math-container"">\$n-1\$</span> have gcd > 1 for one of the two partitions. This is done initially y working out which primes must go together and then trying all combinations of the rest.</li> | |
<li>Solve the Diophantine equation of the form <span class=""math-container"">\$Ax - By = c\$</span> to work out the final end points.</li> | |
<li>Find the minimal such solution.</li> | |
</ol> | |
<p><a href=""https://tio.run/##dVTdcqJKEL7nKebs1m4xZtyFGYLEqjlPce4oL1BGxSggghs8Oc@e01@DMbF2U5W2//vrnm7qvt1WpUnq5u1t3VQHUbSuaatqfxLF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment