# Tag Info

0

ErrLess, 47 bytes q@1=1-[{3+}2xY@;>1-[{@;%0=1-[{0#.};1+xy}2]y1_#. Could probably get golfed a lot more... Prints 0 if the input is not prime, -1 if it is, no trailing newline. It uses -1 as a truthy value, since that is used for if-constructs, and what you get if a comparison is true. Explanation q { Input a number: (p) } @1= 1-[{ { If p == ...

0

TypeScript Compiler, 427 bytes type R="l"|"r"|"m"|"n" type U="p"|"t"|"k"|"f"|"c"|"s"|"x" type V="b"|"d"|"g"|"v"|"j"|"z" type S="c"|"s"|"j"|"z" type G&...

1

Japt, 12 bytes cUy)¸¸fÅe!øV Try it

1

Kotlin, 159 129 bytes {d,b->(b+b.indices.map{c->b.indices.joinToString(""){"${b[it][c]}"}}).all{r->r.split(" ").filter{it.length>1}.all{w->w in d}}} -30 bytes thanks to using lambda and type inference (Parlor Trick) Try it online! Explanation: First, merge the original and transposed board. In each row, find ... 3 Gaia, 8 bytes Basically the same as my Jelly answer, but Gaia has a superset builtin. :t+ṡṡḥ⁇⊃ Try it online! :t+ṡṡḥ⁇⊃ -- function that expects a 2d-list character above the dictionary as a list of strings :t -- duplicate the grid on the stack and transpose the copy + -- append transpose to original grid ṡ -- join list by ... 3 JavaScript (ES6), 112 bytes Expects a matrix of 0's and 2's, for 'X' and 'O' respectively. Returns 0 or 2. f=(m,x=0,y=0,i=1,r=m[y]||0)=>(r[x]--&&[1,2,4,5,8].some(d=>r[x+1]+1||m[y+1]?f(m,x+i*d%4,y+i*(d>>2),-i):1))*++r[x] Try it online! Commented f = ( // f is a recursive function taking: m, // ... 3 Charcoal, 88 bytes ⊞υ⊖⟦⁰ＬθＬ§θ⁰⟧ＦθＦ²⊞ι⁰Ｆ²⊞θＥ§θ⁰¦⁰ＦυＦ³Ｆ³«≔Ｅι⎇ν⁺μ×§ι⁰⎇⊖νλκ±μη¿∧∨κλ∧›³⁺κλ›§§θ§η¹§η²№υη«⊞υη¬⌈Φην Try it online! Link is to verbose version of code. Outputs - if a solution exists, nothing if not. Explanation: ⊞υ⊖⟦⁰ＬθＬ§θ⁰⟧ Start a breadth-first search with the initial position of the next move from the bottom right corner being a "forward&... 6 Wolfram Language (Mathematica), 97 bytes Saved 6 bytes thanks to @att. FindPath[Pick[e@@#<->#2,0<=Min[d=#2-#]<Tr@d<3]&@@@#~Tuples~2,1~e~1,Last@#]~FreeQ~{}&@*Position Try it online! 2 05AB1E (legacy), 12 bytes Dø«ðý#ʒ¦Ā}åP First input is the board as a list of string lines; second is a list of words. Uses the legacy version of 05AB1E, because it can zip/transpose lists of strings, where in the new version zip/transpose can only be done on character-matrices. Try it online. Explanation: D # Duplicate the first (implicit) input-... 4 Python 3, 138 $\cdots$ 86 79 bytes lambda b,d:all(i in d+[*s]for s in[*map(''.join,zip(*b))]+b for i in s.split()) Try it online! Saved a whopping 27 33 bytes thanks to Bubbler!!! Saved 7 bytes thanks to Jonathan Allan!!! TIO testing now works thanks to ovs and Bubbler!!! Inputs the boards as a list of strings (space padded so they're all the same length)... 7 Ruby, 60 57 bytes ->b,d{(b+b.transpose).all?{|c|d==d|c.join.scan(/\w\w+/)}} Try it online! Takes the board as a list of lists of characters. Returns true for valid boards, false otherwise. The board is valid if for every word on the board, the union of that word with the dictionary is equal to the dictionary. 2 K (ngn/k), 42 bytes {(|/8 9=#x)&t&~11!t:+/(|-1,2+!8)*-9#0,.'x} Try it online! Takes the input as a list of characters. .'x convert each digit to its integer (e.g. convert "123" to 1 2 3) -9#0, prepend a 0, then take the last nine values (handles padding 8-digit codes, and avoids errors on input that is not 9 digits long) (|-1,2+!8)* ... 12 Jelly, 12 9 bytes -3 bytes thanks to Jonathan Allan A dyadic function taking a list of lines on the left and a list of words on the right. Z;⁸KḲḊƇfƑ Try it online! 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) Ḋ ... 3 05AB1E, 9 bytes Œε∍OyO@}P Input as a list of 0s/1s. Try it online or verify all test cases. Explanation: Œ # Get all sublists of the (implicit) input-list ε # Map over each sublist: ∍ # Shorten the (implicit) input-list to a length equal to this sublist-length O # Sum this prefix yO # Sum the sublist as well @ # ... 1 Python 3.8, 96 bytes lambda i:7<len(i)<10*((S:=sum(a*b for a,b in zip([-1,*range(2,10)],map(int,i[::-1]))))%11<1)*S>0 Try it online! Similar to @TFeld's Python 2 answer, but uses Python 3.8 assignment expressions and a few other tricks to get it down to 96 bytes. 1 Ly, 58 bytes iy9L[r'0r!]ppry9=[pp8[f'0-srlrpsrl*r,]p'0-N&+[92+%!u;]]u; Try it online! I thought this would be shorter... There's probably room for improvement? First part, input digits, pad with leading 0 if necessary i - input all digits (as codepoints) y - push the stack size onto the stack 9L[ !]p - if/then block, ... 1 Core Maude, 186 bytes mod P is pr NAT-LIST . var L P F X Y Z :[Nat]. ops n c : Nat ~> Nat . ceq n(L)= F if P X 2 Y F Z := L 2 L /\ size(P)= size(F)/\ c(F)> c(P). eq c(X 1 Y)= s c(X Y). eq c(L)= 0[owise]. endm The answer is obtained by reducing the n function with the input bitstring as a Maude NatList of 0s and 1s. If the term is irreducible (result ... 1 Python 3.8 (pre-release), 111 110 104 bytes -1 byte thanks to @Kevin-cruijssen -6 bytes by reading the rules (yay) lambda s:len(s)in(8,9)and not(x:=sum(a:=[*map(lambda n,m:int(n)*m,s[::-1],range(1,10))])-2*a)%11and x Try it online! There's probably more golfing to do, but this is what I have for now. 2 Scala, 74 bytes s=>1 to s.size forall(l=>s.sliding(l).map(_.sum).forall(_<=s.take(l).sum)) Try it online! Strategy is as follows: for all possible prefix lengths (1 to s.size forall{...}) check the following compute the number of 1's within each sliding window of current prefix length (s.sliding(l).map(_.sum)) check whether all these sliding ... 2 Ruby, 70 60 bytes ->s,r=0..s.size{r.any?{|i|r.any?{|j|s[j,i].sum>s[0,i].sum}}} Try it online! Saved 9 Bytes thanks to @Dingus suggestions ! any? replaces first map We reuse entire range L=0..s.size instead of just the length Saved another 1 again by @Dingus Compares directly the sums of prefix and current range being checked Takes an array s of 0/... 1 Python 3, 91 79 bytes lambda s:any(sum(s[:i-j])<sum(s[j:i])for i in range(len(s)+1)for j in range(i)) Take as input a list of integers. Return False for prefix normal and True for prefix not normal Thanks @UnrelatedString for -12 bytes using list of integers instead of strings Try it online! 5 JavaScript (ES6), 57 bytes Expects an array of binary digits. Returns false for prefix normal, or true for not prefix normal. a=>a.map(v=>a=v-~a).some((p,i,a)=>a.some(q=>q-a[~i--]>p)) Try it online! How? We first compute the cumulative sums of the incremented input values: a.map(v => a = v - ~a) (Using a = v - ~a allows us to re-use a[] ... 2 APL (Dyalog Unicode), 14 bytes ∧/∘∊+\≥⍳∘≢+/¨⊂ Try it online! A tacit function taking a vector of 0's and 1's ⊂ The input vector enclosed in a singleton list. ⍳∘≢ indices of the input (1 .. length input) ¨ For each of the numbers on the left and the input vector on the right: +/ sums of all sublists of the right argument of the length given by the left ... 1 R, 92 bytes Or R>=4.1, 78 bytes by replacing two function appearances with \s. function(s,n=sum(s|1)){for(i in 1:n)F=F|which.max(sapply(0:n,function(j)sum(s[1:i+j])))-1;F} Try it online! Takes a vector of integers. Outputs FALSE for prefix normal and TRUE for non-prefix normal word. Solution shorter in R>=4.1: R, 98 bytes Or R>=4.1, 77 bytes by ... 5 Haskell, 57 bytes g x=x!x p!s=p==[]||sum p>=sum s&&init p!tail s&&g(init p) Try it online! Haskell, 66 bytes A bit longer, but actually runs in reasonable time. g x|k<-[1..length x]=and[h x>=h(drop n x)|h<-(sum.).take<$>k,n<-k] Try it online!

1

Charcoal, 19 18 bytes ⊙θΦκ‹Σ…θ⁻⊕κλΣ✂θλ⊕κ Try it online! Link is to verbose version of code. Outputs - for not normal, nothing for prefix normal. Explanation: θ Input string ⊙ Φκ Any substring satisfies …θ⁻⊕κλ Leading prefix Σ Sum of digits ‹ Less than ✂θλ⊕κ ...

3

Retina 0.8.2, 49 bytes ((1)|0)+(?<=(?!(?>(?<-1>(?<-2>1)|0)*)(?(2)^))^.*) Try it online! Outputs 0 for prefix normal, 1 for not normal. Explanation: ((1)|0)+ Match some 1s and 0s, keeping count of the 1s and the total number of digits (very slightly golfier as we need a group for the +), ... (?<=...^.*) ... then, at the beginning of ...

4

Risky, 31 bytes *00_{?*_1_+!?{_?+0_{?*_1_+_?*_1__[___{_0*__1*_1:____{_0{__1*_1 Input is a single argument which is a list of 0's and 1's; output is 1 if prefix normal, 0 if not. Try it online! Explanation This is a bit long, so I'll explain it in two halves. 00_{?*_1_+!?{_?+0_{?*_1_+_?*_1 ? Input list { ...

7

Jelly, 9 7 bytes ṡJ§Ṁ€⁼Ä Try It Online! -2 bytes thanks to Unrelated String ṡ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?

5

Wolfram Language (Mathematica), 54...44 41 bytes (l=Most@l+#-(t={##2})&@@t)&/@(t=l=#)0& Try it online!  is VectorGreaterEqual. (l=Most@l+#-(t={##2})&@@t)&/@(t=l=#) get all prefix differences by: (t=l=#) l: difference list, t: input list /@ over ...

4

Jelly, 9 8 bytes ẆẈṀƙ§Ɗ⁼Ä Try it online! It feels like something less naive should be shorter yet, but I haven't had any luck. Ẇ 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. ⁼Ä ...

0

Haskell, 65 bytes Based on wasif's 05AB1E answer. import Data.List f x=isPrefixOf(x\\nub x)x&&[1..maximum x]==nub x Try it online!

1

05AB1E, 18 bytes Ù0.;0KÅ?IηεÙZLQ}P* Try it online! -5 thanks to @ovs

1

Jelly, 12 bytes ṀRḟṣṪṪƊƲƤ⁼W€ A monadic Link that accepts a list of positive integers and yields 1 if a prefix of some infinite fractal sequence, or 0 if not. Try it online! Or see the test-suite. How? Checks that every non-empty prefix contains all integers up to and including its maximum after the penultimate* occurrence of its ultimate value. * If a ...

4

Python 3, 91 65 bytes f=lambda s:s and{*s[-max(s):]}=={*range(1,max(s)+1)}and f(s[:-1]) Try it online! uses the empty list [] as truthy value and False for falsey How it works : s and : if the list is empty, return it (truthy value) {*s[:-max(s)]}=={*range(1,max(s)+1)} verify that all numbers are present once in the last chunk of the list; and f(s[:-1]) ...

4

JavaScript (ES6), 52 bytes Returns false for valid or true for invalid. a=>a.some(v=>v^=a[~v]^=a[~v]?v-a[j++]&&-1:++i,i=j=0) Try it online! Commented a => // a[] = input array, re-used as an object to store // a 1-indexed ID for each unique value in a[] a.some(v => // for each value v in a[]:...

1

jq, 50 bytes .++(now|gmtime[3:8])|mktime|strftime("%w")=="1" Try it online! Not that short, but it's different enough that I thought it might be interesting enough to post... It expects a year and a 0-indexed month as a list, meaning [2021,3] for April, 2021. .++( ) - append "day 1"...

1

Charcoal, 45 bytes ⬤θ⬤…¹ι∧№…θκλ›⁼№…θκλ⁺№…θ⌕θιλ№…θκι›№θλ⁺№…θκλ№θι Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - for a fractal sequence, nothing if not. Explanation: θ Input array q ⬤ All values i match …¹ι ...

5

BQN, 22 19 17 bytes -3 thanks to Bubbler -2 by further rearrangement ×∘⊒⊸(/≡∨⊸/)∧⊢≡1+⊐ Try it here. Explanation: ×∘⊒⊸(/≡∨⊸/)∧⊢≡1+⊐ # ×∘⊒⊸( ) # Between the sign of the running occurrence count and the input: / # filter (removing first occurrences) ≡ # and match against ∨⊸/ # the equal length prefix of ...

2

TI-Basic, 15 bytes 2=dayOfWk(Ans(1),Ans(2),1 Input is taken from Ans as a list. Output is stored in Ans and is displayed. Assumes that the time and date are set correctly before the program is run. Outputs 1 if the month starts on a Monday and 0 if it does not. Only works on TI-84+/SE.

4

BQN, 124 114 bytes ∨´{0=𝔽⥊𝕩?1;W←(<4⌽⥊)⎉2 3‿3↕⊢↑˝·≍⟜¬2+≢⋄𝕩≡◶𝕊‿0𝕩∧´¬(𝔽<≡¨(𝕩(𝔽¨0=1↓¨W)∘≥⚇1𝔾{𝕩𝕊⍟≢(⌈´×·×⊑)¨W𝕩}+⊸×⌾⥊0=𝕩)∧¨<)¨⊸/𝔾𝕩}(⍷∘⥊=¨<) Try it here. Fairly unsophisticated method: it flood fills the solved cells to find disconnected regions, then marks as solved cells where all cells of the same number border the edge or a single ...

4

Python 3, 331 bytes def T(p): w=len(p)+2;p='..'.join(p).join(['.'*(w+1)]*2);d={};N={} for i,c in enumerate(p):d[c]=d.get(c,set())|{i};N[i]={i-w-1,i-w,i-w+1,i-1,i+1,i+w-1,i+w,i+w+1} u=d.pop('.') while d: for k,v in d.items(): if not any(abs(a-b)in(1,w)and not(N[a]&N[b]&u)for a in v for b in v):u|=v;d.pop(k);break else:return 0 return 1 ...

1

///, 145 bytes /~/\/\///$/\\\\~%/+**~I/*~>**/^=$=^=$%|$+$I^^%|$%^%|$+^^%|$+^+|^^=$+^=$=^^+$*^-$**^^-$*^+$*^>~^/\~/>*~/>~>I/||/1~=\=1~/=\=|=/1~=~/*~/|~/11/1/==|= Try it online! Outputs 1 for composite numbers (not prime), and nothing for prime numbers. I am very happy I was able to post the first answer in my favorite language on a popular ...

1

Python 3, 57 56 bytes lambda y,m:date(y,m,1).weekday()<1 from datetime import* Try it online!

2

Python 3.8 (pre-release), 71 68 bytes lambda l:[*map(math.comb,(a:=len(l))*[a-1],range(a))]==l import math Try it online! Using some list expansion shenanigans, it can be slightly shorter. Old answer: lambda l:list(map(math.comb,(a:=len(l))*[a-1],range(a)))==l import math Try it online! Happily, Python has a built-in combination function. This just uses a ...

4

Lean, 187 176 143 131 bytes def q:list ℕ→bool:=λx,by{induction x,exact[],apply(::)1,induction x_ih with h t i,exact[],cases t,exact[h],exact(h+t_hd)::i}=x Try it online! A simpler version of this can be found below: Lean, 190 185 169 bytes def f:ℕ→list ℕ:=λn,by{induction n,exact[],apply(::)1,induction n_ih with h t i,exact[],cases t,exact[h],exact(h+t_hd)::...

1

Python 3, 76 68 bytes Creates a new datetime object with given year and month (as a list) and the first day of the month and then checks if the day name starts with a M for Monday. lambda l:date(*l,1).strftime("%A")=="M" from datetime import date Try it online!

2

Factor, 20 bytes [ 1 <date> monday? ] Try it online! 1 <date> Create a timestamp object from the given year, month, and using 1 as the day. monday? Is it Monday? A builtin from the calendar vocabulary.

0

jq, 20 bytes [range(max)+1]==sort Try it online! Explanation max # Get the maximum of the input range( ) # Generate the non-negative integers below that +1 # Add 1 to each of them [ ] # Collect as list sort # Sort the input list == # Compare the two lists

0

RAD, 5 bytes <≡⍳∘⍴ Try it online! ≡ - Check equality between ... < - ... the input vector ... ⍳∘ - ... and 1 through ... ⍴ - ... the length of the input vector.

Top 50 recent answers are included