New answers tagged

2

APL (Dyalog Unicode), 46 bytes {∧/0<⍵:⊃⊃⍸A⍷↑{⍵((+/↑),⊢)⍣{</+/¨A⍵}⍵⍴1}¨⍳⊃A←⌽⍵} Try it online! Anonymous prefix function, taking a vector of integers. How? ∧/0<⍵: ⍝ If the given sequence contains any non-positive integers, then return nothing. Otherwise... A←⌽⍵ ⍝ Set A to be the reverse of the given sequence {...}¨⍳⊃ ⍝ For each n in 1 to last ...


2

Perl 5 -p, 20 bytes /,/;$_=$`*$'&&$'**$` Try it online!


1

Javascript, 24 bytes - recursive version, 33 bytes - usage of Binet's formula, 46 bytes - continuous approximation with the "phi" itself Usage of "Binet's formula" and a bitwise "OR" operator to round the result. Originally in the "Binet's formula" you have to subtract the so-called "smaller phi to the n-th power&...


1

///, 196 bytes /h/ 3//g/ 2//f/ 1//e/aa//d/ a//c/ //b/ea//a/c /bc1bc b1gfbdac1hhfecdaf 4 6 4fe dc1 5f0f0 5facdac15g0f5e d 7g1h5h5g1 7a d8g8 56 70 56g8 8c 9h6 84f26f26 84h6 9 bg52b dac462 462ec b 924b daf716f716e Try it online!


0

Brachylog, 28 bytes ^₂g{∧{Ċ≥₁>ᵛ1&≜↔;?^ᵐ+}}ᶠ⁽o∋↙? Try it online! How it works ^₂g{∧{Ċ≥₁>ᵛ1&≜↔;?^ᵐ+}}ᶠ⁽o∋↙? ^₂g 7 -> [49] {∧{ }}ᶠ⁽ find first 49 outputs whose … Ċ≥₁>ᵛ1 inputs are of form [X,Y], ≥₁ are ordered >ᵛ1 ...


3

Charcoal, 57 bytes F³⊞υ﹪ι²F”)⧴→↨w﹪f”«UMυ⁺κ§υ⊖λ⊞υ⁰F›ⅉ⁰≔⪫✂υIι±Iι¹ ι⟦⁺× ⊘⁻²⁴Lιι Try it online! Link is to verbose version of code. Explanation: F³⊞υ﹪ι² Start by preparing a list 0 1 0. (Charcoal's indexing is cyclic, so rather than letting it wrap I need to provide a safety margin.) F”)⧴→↨w﹪f”« Loop over the compressed string 111113222667 which represents ...


3

APL (Dyalog Unicode), 81 75 bytes ⌊{⌽q⊃⍨⊃⍋|-/¨q←⊃,/2,/¨p/⍨B∊¨p←2(+/⍤↑,⊢,¯2-/⍤↑⊢)⍣{∧/B≤|¯2↑1⌽⍵}¨⍺,¨(-,⊢)⍳B←⍵}⌈ -6 bytes thanks to @Adám Try it online! Explanation This performs a similar algorithm as @notjagan's answer. For each C between -B and B inclusive, it produces the Lucas sequence containing A,C (where A and B are the minimum and maximum of the two ...


4

05AB1E, 26 bytes 13LεDÝc•6hö¢ðU•RNèF¦¨]»¦.c Try it online. Explanation: 13L # Push a list in the range [1,13] ε # Map each value `y` to: D # Duplicate the value `y` Ý # Pop and push a list in the range [0,`y`] c # Take the binomial coefficient of `y` with each value in this list ...


2

Ruby, 91 bytes 66551112000090.digits.map{|i|n=0;$*.map!{|j|n+n=j}<<1;puts ($*[i..~i]*' ').center 23if i<9} Try it online! Iterates over the digits of 66551112000090 (from the right), one digit for each row of the tree. Each digit, with the exception of the 9, specifies the number of elements to be omitted from the beginning and end of the ...


6

Python 2, 118 bytes n=1 exec"a=n/6+n/10*4+(n==6);print' '.join(str(((2**n+1)**n>>n*k)%2**n)for k in range(a,n+1%n-a)).center(23);n+=1;"*13 Try it online! Expresses binomial coefficients inline like in my tip here with binom(n,k)=((2**n+1)**n>>n*k)%2**n. The number of entries cut off on each side for the n'th row (one-indexed) is ...


6

J, 67 bytes (1785951#:~13#7)(0(,~' '#~12-<.@-:@#)@":-@[}.}.)&>1;2}.<@(!{:)\i.14 The pascal's triangle part is adapted from @ephemient's answer here. Try it online! How it works <@(!{:)\i.14 The first 14 rows of the triangle. 1;2}. Drop the first two rows, prepend 1. (1785951#:~13#7) 0 0 0 0 0 2 1 1 1 5 5 6 6 stored in base 7. ":-...


3

JavaScript (ES8), 137 bytes _=>[a=[1],..."000021115566"].map((v,n)=>(s=(a=[i=1,...a.map(v=>v+~~a[i++])]).slice(v,n+2+!n-v).join` `).padStart(23+s.length>>1)).join` ` Try it online!


1

GAS x86-64 for Linux (Machine code), 76 68 bytes Loop-free, because I thought it would be a fun idea. GCC 10.1. Note/warning: for this to work, you have to turn off DEP and PIE (ASLR). See compilation instructions below. Look, ma! No loops! Byte count is for the assembled opcodes of func + e + f. Works on 32 bit input. Sure, you'll eventually run out of ...


1

Actually, 16 bytes "1,"◙01W;a+;◙',◙ Try it online!


0

Python 2, 59 51 55 33 bytes a=0 b=1 while 1:a,b=b,a+b;print a Try it online! Thanks for @pppery for saving a whole 22 bytes!


0

Perl 5 -alp, 148 bytes $_=9;while(!$o||--$F[0]){$o=0;if(++$_ ne reverse){for$i(0..(@a=/./g)){map{@b=@a;@b[$i,$_]=@b[$_,$i];$o+=($t=1*join'',@b)eq reverse$t}$i..$#a}}}say$o Try it online! Output is on two lines. First line is the order; second line is the number.


1

Raku, 45 bytes {|$_,{|keys abs([-] @_[++$,$++])∖@_}...^!*} Try it online! Explanation { } # Anonymous codeblock ... # Generating a sequence |$_, # Starting with the input { } # Where we ...


1

Wolfram Language (Mathematica), 50 bytes #//.l:_[___,b_,a_,___]:>l<>d/;FreeQ[l,d=Abs[b-a]]& Try it online! Takes a sequence with any head. If the sequence is already complete, returns it unchanged. Otherwise, returns the completed sequence in a StringJoin. <> (StringJoin) is short, flattens Lists, does not operate on integer (non-string) ...


2

Python 3.8, 109 bytes f=lambda l,n,a=0,b=0:f(l[1:],m,a+1-j,b+j)if l and(m:=n-((j:='i|'.index(l[0]))+1)*2)>=0 else[l!=''and m<0,a,b] Try it online!


2

Jelly, 14 bytes I'm assuming, for now, that the "boolean" part of the output may be given as a Truthy/Falsey value. Og©2ḤÄ’<a®‘ċⱮ3 A dyadic Link accepting the trees (a list of characters) on the left and the axe durability (an integer) on the right which yields a list of three integers, [is_broken, small_trees, big_trees] (Note that non-zero ...


1

Retina 0.8.2, 55 bytes \d+ $* (11)+1?(?<-1>(i)|(?<-1>(\|)))*($)?.* $#4 $#3 $#2 Try it online! Takes input as [durability][trees] without a separator and outputs [complete] [big] [small]. Explanation: \d+ $* Convert the durability to unary. (11)+1? Capture half the durability as $#1. (?<-1>(i)|(?<-1>(\|)))* Count the trees as they ...


4

Python 2, 103 \$\cdots\$ 82 80 bytes Saved 4 6 9 11 bytes thanks to ovs!!! f=lambda s,n:n<sum(6&ord(t)%6for t in s)and f('<'+s[:-1],n)or map(s.count,"<i|") Try it online! Inputs a string of trees \$s\$ (as is and |s) and an axe durability \$n\$. Outputs a list of [axe broken, small trees, large trees] where axe broken is truthy if ...


4

R, 63 bytes using characters exactly as described in challenge (or only 54 bytes using 0,1 to represent small & big trees, and outputting 0,1 to represent FALSE/TRUE axe breaking). function(a,t)list(sum(c<-2+2*(t<"i"))>a,table(t[cumsum(c)<=a])) Try it online!


4

J, 37 34 33 bytes (](-:;+/@#:@])(>:2*+/\)#])' i'i.] Try it online! -1 byte thanks to Bubbler Converts small to 1, big to 2. Now create a filter by doubling and scan summing, and apply filter to find entries less than or equal to the left input. Take just those entries, convert to binary, and sum to get the <num big>, <num small> part of the ...


3

Keg, 32 bytes 0:&®s?⑷¦i2⑹|\|4©s⑨®s±™⑸¿⅀0=⑻©s(. Try it online! Takes input as trees, durability and outputs big, small and whether or not the axe breaks. Somehow, Keg beat pyth.


7

JavaScript (Node.js), 52 bytes Takes input as (b)(n), where b is a Buffer (using the characters described in the challenge) and n is the durability of the axe. Returns a Boolean value and 2 integers as [ broken, [ small, big ]]. b=>n=>[b.some(c=>(n-=6&c+1)<0||!++a[c%3],a=[0,0]),a] Try it online! How? Given an ASCII code c, we use 6 & (c +...


1

Python 3, 56 55 bytes Saved a byte thanks to Surculose Sputum!!! lambda l:l.sort()!=len({b/a for a,b in zip(l,l[1:])})<2 Try it online!


1

R, 38 bytes function(x)!sd(diff(y<-sort(x))/y[-1]) Try it online! sort x calculate difference between successive elements divide by value of each element (except first) = fold-difference check if results are all the same (standard deviation = zero) Fails for negative fold-differences between elements (which seems to be a true geometric sequence, ...


Top 50 recent answers are included