Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
A competition to solve a particular problem through the usage and manipulation of arrays.
4
votes
Get multi-dimensional indices in a list
Python, 91 85 83 bytes
-6 bytes thanks to @Steffan
-2 bytes thanks to @movatica
f=lambda a,b,c:c and[(i,*j)for i,d in enumerate(a)for j in f(d,b,c-1)]or[[]]*(a==b)
Attempt This Online!
2
votes
Count the changes in an array
Rust, 68 bytes
|u:Vec<_>|u.iter().fold((0,0,0),|(u,v,w),&x|(u+w*(v!=x)as i8,x,1)).0
Attempt This Online!
Non-Competing Rust, 63 bytes
This version crashes on 0-length inputs so doesn't technically co …
2
votes
Count the changes in an array
><> (Fish), 30 bytes
i0\ ;n$\.13$\
1+>i:0(?/:{=?^$
Try it
2
votes
Add in the blanks
Rust, 135 130 bytes
-5 bytes thanks to @alpehalpha
|v:Vec<i8>|v.iter().scan(0,|c,&a|Some((match a-*c{1=>vec![a],2=>vec![a-1,a],_=>vec![-1,a]},*c=a).0)).flatten().collect::<Vec<_>>()
Attempt This Onlin …
1
vote
Find the capacity of 2D printed objects
Rust, 112 bytes
|l:&[u8]|{(0..).zip(l).scan(0,|a,(b,c)|{*a=(*a).max(*c);Some((*a).min(*l[b..].iter().max()?)-c)}).sum::<u8>()};
Playground Link
Basically min(max(..index),max(index..)-value
0
votes
Is it an OVSF code?
Rust, 150 bytes
|m|f(m,1);fn f(k:&[i8],u:i8)->bool{let m=k.len()/2;k!=&[]&&(k==&[u]||f(&k[..m],u)&&(&k[..m]==&k[m..]||(f(&k[m..],-u)&&(0..m).all(|i|k[i]==-k[i+m]))))}
Attempt This Online!
5
votes
CGAC2022 Day 7: Fen The Wicked
Rust, 64 bytes
|x:&[_]|(0..x.len()).map(|i|x[i&i+1..=i].iter().sum()).collect()
Attempt This Online!
Uses XNOR's trick. Also uses blatant abuse of type annotations outside the code.
4
votes
Find the largest sum of any contiguous subarray of the array
Python, 69 bytes
lambda x:max(sum(x[a:b])for a in range(len(x))for b in range(len(x)))
Attempt This Online!
Python, 74 bytes
Outputs the list
lambda x:max((x[a:b]for a in range(len(x))for b in range( …
17
votes
16
answers
740
views
Form a subset that is a continuous range
Given a list of lists of positive integers, output a subset of them so their union forms a continuous non-empty range with no numbers missing. For example, consider this input:
[
[1, 2, 3, 5],
[ …
5
votes
Is it traversable?
Rust, 90 bytes
fn f(a:&[i32],b:i32)->bool{a.len()<2||a[1]-a[0]<=b&&f(&a[1..],b-(a[0]-a[1]>b&&b>0)as i32)}
Attempt This Online!
Recursive approach
3
votes
"Signpost" puzzle from Tatham's collection
Python, 154 bytes
lambda x:(z:=len(x))and next(i for i in permutations(range(z))if all(x[j]==i[j]or("RL"[j>i.index(i[j]+1)]==x[j])for j in range(z)))
from itertools import*
Attempt This Online!
0-ind …
6
votes
Pairs at every distance
Rust, 63 bytes
|k:&[u8]|(0..k.len()).all(|z|(z..k.len()).any(|q|k[q-z]==k[q]))
Attempt This Online!
13
votes
10
answers
1k
views
Adjacent Items Sorting
Given a list, L, of sets of numbers like this:
[[1], [0,2,3], [3,1], [1,2,3]]
Output a single list of numbers such that 2 numbers A and B appear next to each other at least once if and only if B in L …
3
votes
Complement an infinite list
Python, 79 bytes
lambda x,j=0:(i for i in count()if i-j or(j:=next(x))*0)
from itertools import*
Attempt This Online!
5
votes
Is it an OVSF code?
><> (Fish), 431 385 bytes
-46 bytes by creating a new stack with l-2 elements so I can remove the 2- from many places.
l[bb01.
>rl2=?vl3=?vl2%?vl2-2,[r0501.
0v=1:< 0
< < < << /
1 …