New answers tagged array
1
vote
0
votes
0
votes
Count repetitions of an array
Tcl, 96 bytes
proc C L {llength [lsort -u [lmap e $L {expr {[llength [lsearch -al $L $e]]>1?$e:[continue]}}]]}
Try it online!
0
votes
Diagonalize a vector
APL(NARS), 28 chars
{0=≢⍵:⍵⋄1=≢⍵:⊂⍵⋄⍵,.×∘.=⍨⍳≢⍵}
Interpreter: NARS2000 (Win32) Version # 0.5.5.1
Input one numeric array, output one void numeric array
or one ...
2
votes
Remove leading and trailing zeroes
Uiua, 11 bytes
⍣⍥₂(⇌↘⊢⊸⊚)⊚
"Straightforward" repetition solution. Feels like a single-digit bytecount is in reach, but I didn't see a shorter way to &...
0
votes
Remove leading and trailing zeroes
APL(NARS),30 chars,
{f←{0=≢⍵:⍵⋄0≠↑⍵:⍵⋄∇1↓⍵}⋄f⌽f⌽⍵}
Interpreter: NARS2000 (Win32) Version # 0.5.5.1
Input one list of integers output one list of integers
The only ...
0
votes
Remove leading and trailing zeroes
Red, 54 51 bytes
func[b][parse b[2[(reverse b)remove any quote 0]]b]
Try it online!
0
votes
Remove leading and trailing zeroes
Tcl, 110 bytes
proc S L {while {[set s [llength $L]]&&![lindex $L 0]} {lpop L 0}
while {$s&&![lindex $L end]} {lpop L}
set L}
Attempt This Online!
1
vote
1
vote
In what order will the downloads complete?
APL(NARS), 68 chars
{⍺{0=≢⍵:⍬⋄c←a/⍨0<↑¨a-←⊂0,⍨⌊/↑¨a←⍵[⍳⍺⌊≢⍵]⋄(↑¨⌽¨a∼c),⍺∇c,⍺↓⍵},¨⍨⍵[⍒⍵]}
Interpreter: NARS2000 (Win32) Version # 0.5.14.11
Input in ⍵ one array ...
0
votes
0
votes
0
votes
Create an array with repeated numbers
APL(NARS), 18 chars, 18x0.5=9 points
{∊⌽(k-1)↓¨⍵/⊂k←⍳⍵}
Interpreter: NARS2000 (Win32) Version # 0.5.5.1
I copy algo other used.
test:
...
0
votes
Create an array with repeated numbers
Gema, 46 characters
*=@set{n;*}@repeat{$n;@repeat{$n;$n }@decr{n}}
Sample run:
...
1
vote
Create an array with repeated numbers
Nekomata, 5 * 0.5 = 2.5 bytes
Rsa↔V
Attempt This Online!
Explanation:
...
1
vote
1
vote
Swap Two Values in a List
Perl 5 -a, 29 bytes
@F[@a[1,0]]=@F[@a=<>];say"@F"
Try it online!
First line of input is the list, space ...
2
votes
Output the symmetric inverse semigroup
Nekomata, 5 bytes
ᵃS↕ÐŤ
Attempt This Online!
Outputs the mapping as a list of pairs [input, output]. 0-indexed.
...
3
votes
Order a list by the difference of its elements
Maple, 67 bytes
s->select(q->{abs~(q[..-2]-q[2..])[]}={1},combinat:-permute(s))[1];
Checks all permutations for absolute differences = 1.
0
votes
Print a Block-Diagonal Matrix
Tcl, 139 153 155 bytes
Requires Tcl >= 8.7 to allow use of lseq
...
4
votes
Order a list by the difference of its elements
Haskell + hgl, 17 bytes
g1(mF eq1<δ')<pm
Explanation
pm get all permutations
g1 get ...
0
votes
Counting Letters in a String
Tcl, 106 bytes
proc C s {lmap c [split $s ""] {dict inc D [string tol $c]}
dict ma k\ v $D {if {$k!=" "} {puts $k:\ $v}}}
Try it online!
0
votes
1
vote
0
votes
Repeat Values In Array
Zsh, 32 bytes
repeat $# repeat $R[++i]<<<$@[i]
Try it online!
36b
Input via arrays $R and ...
3
votes
Order a list by the difference of its elements
APL(NARS), 64 chars
f←{(a b)←⍵⋄a≡⍬:b⋄{(b≡⍬)∨1=∣⍵-↑b:f(a∼⍦⍵)(⍵,b)⋄⍬}¨a}⋄h←{(≢⍵)↑∊f⍵⍬}
Interpreter: NARS2000 (Win32) Version # 0.5.14.11
That would be a try to port ...
4
votes
Order a list by the difference of its elements
APL+WIN, 47 bytes
Prompts for vector of integers. Times out for last test case.
s←⎕⋄:while (¯1+⍴s)≠+/1=|-2-/s←s[(⍴s)?⍴s]⋄:end⋄s
Try it online! Thanks to Dyalog ...
7
votes
Order a list by the difference of its elements
R, 42 bytes
\(a){while(any(diff(a)^2-1))a=sample(a);a}
Attempt This Online!
Randomized. Shuffles the vector randomly until the condition is met. Will usually time ...
0
votes
Find the first duplicated element
Brev, 67 bytes
(c(fn(cond((x(car y))(car y))(#t(x(car y)1)(f x(cdr y)))))(ct 0 0))
Straightforwardly just looking at one element at a time seeing if it's been seen....
4
votes
Order a list by the difference of its elements
Charcoal, 37 bytes
⊞υ⟦⟧FυFθF∧¬∧ι⊖↔⁻↨ι⁰κ›№θκ№ικ⊞υ⁺ι⟦κ⟧I⊟υ
Try it online! Link is to verbose version of code. Explanation: Finds all paths in the undirected graph ...
0
votes
Repeat Values In Array
Brev, 34 bytes
(as-list flatten(c map make-list))
That only works if the amount list can come first. If the elements list needs to be the first arg, it's a few ...
3
votes
1
vote
Repeat Values In Array
Nekomata, 3 1 byte
y
Attempt This Online!
Test suite.
-2 bytes thanks to alephalpha!
Takes input as two lists in format: \$R,A\$.
Explanation:
...
0
votes
4
votes
9
votes
Order a list by the difference of its elements
Python, 102 101 100 98 bytes
lambda l:min(permutations(l),key=lambda x:{-1,1,*map(int.__sub__,x,x[1:])})
from itertools import*
Attempt This Online!
Intentionally ...
6
votes
7
votes
Order a list by the difference of its elements
R, 117 116 111 bytes
Edit: -1 byte thanks to Glory2Ukraine.
...
4
votes
6
votes
Order a list by the difference of its elements
Haskell, 117 bytes
a%(b:s)|a==b=s|1<2=b:a%s;_%b=b;p[]=[[]];p x=[y:z|y<-x,z<-p$y%x];f=head.filter((all((1==).abs)).(zipWith(-)<*>tail)).p
Try it ...
0
votes
Repeat Values In Array
Tcl, 60 bytes
proc M A\ B {join [lmap a $A b $B {string repe $a\ $b}] ""}
Try it online!
4
votes
0
votes
4
votes
Order a list by the difference of its elements
05AB1E, 6 bytes
œ.Δ¥ÄP
Try it online or verify (almost) all test cases. (Test suit omits the last test case, which times out.)
Alternatively, outputting all valid ...
4
votes
Order a list by the difference of its elements
Python3, 135 bytes
def f(l):
q=[([],l)]
for a,l in q:
if[]==l:return a
for i,j in enumerate(l):q+=[(a+[j],l[:i]+l[i+1:])]*([]==a or abs(a[-1]-j)==1)
Try it ...
11
votes
Order a list by the difference of its elements
Nekomata + -1, 6 bytes
↕:∆Zƶ¿
Attempt This Online!
...
4
votes
Order a list by the difference of its elements
JavaScript (ES7), 77 bytes
f=o=(a,...b)=>a.map((v,i)=>(v-b[0])**2-1||f(a.filter(_=>i--),v,...b))+a?o:o=b
Try it online!
Commented
...
1
vote
In what order will the downloads complete?
Tcl, 331 bytes
Requires Tcl >= 8.7 to allow use of lpop
...
Top 50 recent answers are included
Related Tags
array × 839code-golf × 805
number × 90
math × 77
matrix × 71
decision-problem × 70
string × 56
sorting × 56
integer × 49
arithmetic × 40
sequence × 25
permutations × 21
ragged-list × 20
grid × 19
subsequence × 17
code-challenge × 16
random × 16
combinatorics × 14
optimization × 12
geometry × 11
counting × 11
binary-matrix × 11
game × 10
tips × 9
data-structures × 9