Skip to main content
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
Results tagged with
Search options not deleted user 31625

A competition to solve a particular problem through the usage and manipulation of arrays.

16 votes

Mode (most common element) of a list

Pyth - 6 eo/QNQ Try it online. Expects input on stdin like [4,3,1,0,6,1,6,4,4,0,3,1,7,7,3,4,1,1,2,8]. Ties are resolved by last occurrence because Python performs stable sorts. Sorts the list by coun …
FryAmTheEggman's user avatar
29 votes

Mode (most common element) of a list

Python 2 - 18 max(d,key=d.count) Since your python answer doesn't seem to print, I expect this is what you want. Add 6 bytes for print normally.
FryAmTheEggman's user avatar
1 vote

Print a Block-Diagonal Matrix

Pyth, 31 30 FbQVbjd++*]0Z*b]b*]0--sQbZ)~Zb A pretty naive program, takes the input on stdin. This can probably be golfed more ;) Thanks @Jakube for pointing out a wasted char Try it here
FryAmTheEggman's user avatar
3 votes

Hollow out an array

Retina, 31 24 22 (?<=¶.+ )\S+(?= .*¶) 0 Saved 2 bytes thanks to randomra Try it online! There is probably a better way to do it, as this is just a pretty basic multi-line replacement. Essentially …
FryAmTheEggman's user avatar
5 votes
Accepted

Leaving the Nest

Pyth, 17 us-GeaYsI#GQ)S#Y The leading space is important. This filters the list on whether the values are invariant on the s function, then removes these values from the list and flatten it one le …
FryAmTheEggman's user avatar
0 votes

How many steps did I walk?

Retina, 34 -1* ^(1*)((?>.*?\1.*? \D))*.* $#2 Try it online! or try it with decimal input. Takes input in unary, negative unary numbers are treated as -111... and zero is the empty string. Counts …
FryAmTheEggman's user avatar
4 votes

Reverse positive runs

Retina, 25 24 O^$#`[^0](?=(.*?0)*) $#1 Try it online Saved 1 byte thanks to Martin! Sort the nonzero digits by the number of zeros that follow the digit, in reverse order. See Martin's solution …
FryAmTheEggman's user avatar
6 votes

Falsify brief truths

Retina, 47 43 36 0 ! T`p`0`\b(1+)\b(?<=(?=.*1\1).*)|! Try it online! or try all the test cases Thanks to msh210 for golfing 4 bytes! Also big thanks to Martin for 7 bytes! Explanation: 0 ! Re …
FryAmTheEggman's user avatar
9 votes

Same length sub arrays

Python 2, 31 lambda l:l and l==zip(*zip(*l)) This requires the lists to be lists of tuples. zip Drops extra elements if the input was ragged, so double zipping is only a noop if the lists all have …
FryAmTheEggman's user avatar
1 vote

Trim the array!

Pyth, 5 bytes >E<QE Try it here Takes the arguments in the opposite order. < and > in Pyth trim based on argument order. For example, <Q5 will trim off all values in the input after the fifth one. …
FryAmTheEggman's user avatar
4 votes

Collapse Adjacent Duplicates

Retina, 17 15 bytes +m`^(.+)¶\1$¶? Try it online! Saved 2 bytes thanks to Neil and Martin! Replaces each pair of numbers with nothing. This process loops until no changes are made.
FryAmTheEggman's user avatar
1 vote

An expanding array

\d+ $*1; We change the input array of numbers into a semicolon separated unary array, so we'd have: 1; 111111111111111111111; ^ 11@ Put d into our code at the beginning, giving us: 11@1; 111111111111111111111 … We also add a leading a to these numbers, to indicate that something was kept, along with the ; to indicate it should be permanently part of the array. …
FryAmTheEggman's user avatar
3 votes

Bucket and Minimize

Pyth, 8 bytes smLhSdcF Try it online! This answer is mostly straightforward in that c provides the appropriate splitting behaviour. After that, we map twice to each element of the inner list the e …
FryAmTheEggman's user avatar
8 votes
Accepted

Magnetic pull in an array

Then the final "sorting values" array will be [0, 1, 4, 3, 4, 5, 8, 7, 8]. … Thanks to the stable sort, the ties are broken by the order that the values originally appeared, so we get the final array we want. …
FryAmTheEggman's user avatar
12 votes

Reverse positive runs

Pyth, 8 j0_Mcz\0 Split on zeros, reverse and join back on zeros. Test Suite
FryAmTheEggman's user avatar

15 30 50 per page