Tournament bracket placement algorithm

This JavaScript returns an array where each even index plays the next odd index function seeding(numPlayers){ var rounds = Math.log(numPlayers)/Math.log(2)-1; var pls = [1,2]; for(var i=0;i<rounds;i++){ pls = nextLayer(pls); } return pls; function nextLayer(pls){ var out=[]; var length = pls.length*2+1; pls.forEach(function(d){ out.push(d); out.push(length-d); }); return out; } } > seeding(2) [1, 2] > seeding(4) [1, … Read more

Python – Regular expressions get numbers between parenthesis

You can use re.findall() to find all numbers within the parenthesis: >>> import re >>> l = [ … “PIC S9(02)V9(05).”, … “PIC S9(04).”, … “PIC S9(03).”, … “PIC S9(03)V9(03).”, … “PIC S9(02)V9(03).”, … “PIC S9(04).”, … “PIC S9(13)V9(03).” … ] >>> pattern = re.compile(r”\((\d+)\)”) >>> for item in l: … print(pattern.findall(item)) … [’02’, ’05’] … Read more

Automatic closing brackets for Vim [closed]

For those of us, who want a vanilla vim: inoremap ” “”<left> inoremap ‘ ”<left> inoremap ( ()<left> inoremap [ []<left> inoremap { {}<left> inoremap {<CR> {<CR>}<ESC>O inoremap {;<CR> {<CR>};<ESC>O This autocomplete in insert mode, provided set paste is not set. Keep it in the vimrc to avoid typing it every time and when we … Read more

PHP conditionals, brackets needed?

you can do if else statements like this: <?php if ($something) { echo ‘one conditional line of code’; echo ‘another conditional line of code’; } if ($something) echo ‘one conditional line of code’; if ($something) echo ‘one conditional line of code’; echo ‘a NON-conditional line of code’; // this line gets executed regardless of the … Read more