View rallycoding.201.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.rallycoding.com/problems/201 | |
const solve = (intArray) => | |
{ | |
let a = [], l; | |
let b = [], m = 0; | |
let i, j; | |
for (i = 0; i < intArray.length - 1; i++) | |
{ |
View number2words.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HUNDRED = 100; | |
const THOUSAND = HUNDRED * 10; | |
const LAKH = THOUSAND * 100; | |
const CRORE = LAKH * 100; | |
const TN = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']; | |
const TY = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'sixteen', 'eighty', 'ninety']; | |
const O = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; | |
function number2words(num) |
View contiguous-subarray.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#$nums = [-2,1,-3,4,-1,2,1,-5,4]; | |
$nums = [84,38,65,52,-9,70,81,58,-33,87,-47,48,23,-53,86,-2,45,56,35,5,90,47,-84,-21,55,-8,37,0,-3,-60,-11,-42,54,-68,-89,-54,-98,68,80,-31,55,-67,93,-45,-21,79,52,-75,12,-12,29,-21,-88,21,57,67,-87,-6,-33,-14,10,32,44,-35,63,54,-13,65,22,-33,-66,-46,0,-73,8,78,82,-62,79,-6,2,-15,72,13,83,30,-20,72,-99,46,-41,11,-21,-97,52,-81,33,-61,83,-45,-18,-83,-15,81,-80,69,37,-98,-93,-7,-28,8,55,-55,-78,38,51,-22,-13,51,-75,45,-61,-20,24,90,-2,-43,-94,-41,-12,-12,-25,72,-54,-28,42,59,-27,25,-70,22,-89,84,66,-91,-1,-6,-14,85,-78,-13,8,-39,66,-68,-72,-58,-11,-89,0,53,-25,51,26,20,-77,-55,-43,-27,46,-14,94,33,-53,37,41,45,-69,-72,7,-48,14,-85,-11,-42,-76,-6,-1,-11,4,98,-58,78,49,44,-25,49,65,31,-78,12,93,-84,-55,-83,52,86,61,59,90,-54,-89,-19,-63,-23,38,-40,47,-86,48,-49,-88,67,-94,38,11,-43,-36,-23,65,-15,65,58,-23,-90,75,-94,72,13,64,62,35,51,-79,72,-72,58,-91,74,72,34,-98,60,1,83,-25,-88,-59,38,-35,-94,99,-70,40,-47,-83,15,-42,88,-94,-78,28,40,73,48,-11,77,-17,-2,29,-68,-68,7,69,9 |
View brackets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Usage : | |
node brackets.js | |
((a+b*d)*(x/2))*(1+(y+(x-2)/10)) | |
[ '(a+b*d)', | |
'(x/2)', | |
'((a+b*d)*(x/2))', | |
'(x-2)', | |
'(y+(x-2)/10)', |
View brackets.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$s = "((a+b*d)*(x/2))*(1+(y+(x-2)/10))"; | |
$b = []; | |
$j = 0; | |
$stack = []; | |
for ($i = 0; $i < strlen($s); $i++) | |
{ | |
if ($s[$i] == '(') | |
{ |
View commas.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" dir="ltr"> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> | |
</head> | |
<body> | |
<div id="container"> | |
<form id="frm" class="form" action="" method="post"> | |
<div> | |
<div> |
View getter-setter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A | |
{ | |
protected $_data; | |
public function __get($name) | |
{ | |
if (in_array($name, ['Firstname', 'Lastname'])) | |
return $this->_data[$name]; | |
} |
View csv-json.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, csv, json | |
if len(sys.argv) == 1: | |
print "1 argument for filename required" | |
sys.exit() | |
gdoc = csv.reader(open(sys.argv[1])) | |
# Get the 1st line, assuming it contains the column titles | |
fieldnames = gdoc.next() |
View find-intersection-among-arrays.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ar : can be an array of arrays or an asssociative array | |
Examples: | |
================ | |
intersect([[76,80,11,31,34,82,100], [13,31,66,43,73,100,73,10]]) | |
will give [31,100] | |
intersect( |
NewerOlder