Skip to main content

New answers tagged

1 vote

Count repetitions of an array

Nekomata -n, 3 bytes Ţ~Ƶ Attempt This Online! Explanation: ...
hakr14's user avatar
  • 5,522
0 votes

Count repetitions of an array

Japt, 5 bytes üÍÕÅÊ Try it here
Shaggy's user avatar
  • 45k
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!
sergiol's user avatar
  • 4,155
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 ...
Rosario's user avatar
  • 1,712
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 &...
ojdo's user avatar
  • 835
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 ...
Rosario's user avatar
  • 1,712
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!
Galen Ivanov's user avatar
  • 21.5k
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!
sergiol's user avatar
  • 4,155
1 vote

In what order will the downloads complete?

Japt, 13 bytes Æ0 VñÍñ@=Ív+X Try it ...
Shaggy's user avatar
  • 45k
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 ...
Rosario's user avatar
  • 1,712
0 votes

Create an array with repeated numbers

TacO, 8 bytes i# @%*i Try it online!
ATaco's user avatar
  • 11.7k
0 votes

Find the "unwrapped size" of a list

Tcl, 28 bytes proc C c {regexp -all \{ $c} Try it online!
sergiol's user avatar
  • 4,155
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: ...
Rosario's user avatar
  • 1,712
0 votes

Create an array with repeated numbers

Gema, 46 characters *=@set{n;*}@repeat{$n;@repeat{$n;$n }@decr{n}} Sample run: ...
manatwork's user avatar
  • 20.9k
1 vote

Create an array with repeated numbers

Nekomata, 5 * 0.5 = 2.5 bytes Rsa↔V Attempt This Online! Explanation: ...
hakr14's user avatar
  • 5,522
1 vote

Swap Two Values in a List

Japt -h, 9 bytes gV £hVo X Try it
Shaggy's user avatar
  • 45k
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 ...
Xcali's user avatar
  • 17k
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. ...
alephalpha's user avatar
  • 51.9k
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.
dharr's user avatar
  • 1,116
0 votes

Print a Block-Diagonal Matrix

Tcl, 139 153 155 bytes Requires Tcl >= 8.7 to allow use of lseq ...
sergiol's user avatar
  • 4,155
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 ...
Wheat Wizard's user avatar
  • 103k
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!
sergiol's user avatar
  • 4,155
0 votes

Repeat Values In Array

Perl 5 + -p, 26 bytes $/=$";s/\d+/@{[($&)x<>]}/g Try it online!
Dom Hastings's user avatar
  • 24.7k
1 vote

Repeat Values In Array

Vyxal 3, 3 bytes ẄYf -2 bytes by pacman256 Vyxal It Online! ...
Themoonisacheese's user avatar
0 votes

Repeat Values In Array

Zsh, 32 bytes repeat $# repeat $R[++i]<<<$@[i] Try it online!  36b Input via arrays $R and ...
roblogic's user avatar
  • 4,629
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 ...
Rosario's user avatar
  • 1,712
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 ...
Graham's user avatar
  • 7,806
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 ...
Robin Ryder's user avatar
  • 15.8k
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....
Sandra's user avatar
  • 462
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 ...
Neil's user avatar
  • 184k
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 ...
Sandra's user avatar
  • 462
3 votes

Order a list by the difference of its elements

Husk, 7 bytes ḟoËaẊ-P Try it online! ...
Dominic van Essen's user avatar
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: ...
hakr14's user avatar
  • 5,522
0 votes

Repeat Values In Array

Perl 5, 36 bytes sub{map{(shift@{$_[0]})x$_}@{$_[1]}} Try it online!
Xcali's user avatar
  • 17k
4 votes

Order a list by the difference of its elements

Vyxal 3, 7 bytes ⧖ʎδ⦷1≊⎋ Vyxal It Online! ...
Themoonisacheese's user avatar
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 ...
ShadowRanger's user avatar
6 votes

Order a list by the difference of its elements

Jelly, 8 bytes Œ!ạƝE$ƇḢ Try It Online! ...
hyperneutrino's user avatar
  • 42.8k
7 votes

Order a list by the difference of its elements

R, 117 116 111 bytes Edit: -1 byte thanks to Glory2Ukraine. ...
Dominic van Essen's user avatar
4 votes

Order a list by the difference of its elements

Japt -g, 9 bytes á kÈäa dÉ Try it ...
Shaggy's user avatar
  • 45k
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 ...
Luke Sharkey's user avatar
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!
sergiol's user avatar
  • 4,155
4 votes

Order a list by the difference of its elements

Google Sheets, 152 bytes ...
doubleunary's user avatar
  • 4,652
0 votes

Diagonalize a vector

Tcl, 94 95 124 bytes Requires Tcl >= 8.7 to allow use of lseq ...
sergiol's user avatar
  • 4,155
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 ...
Kevin Cruijssen's user avatar
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 ...
Ajax1234's user avatar
  • 8,939
11 votes

Order a list by the difference of its elements

Nekomata + -1, 6 bytes ↕:∆Zƶ¿ Attempt This Online! ...
alephalpha's user avatar
  • 51.9k
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 ...
Arnauld's user avatar
  • 206k
1 vote

In what order will the downloads complete?

Tcl, 331 bytes Requires Tcl >= 8.7 to allow use of lpop ...
sergiol's user avatar
  • 4,155

Top 50 recent answers are included