Skip to content

Instantly share code, notes, and snippets.

View kgthegreat's full-sized avatar

Kumar Gaurav kgthegreat

View GitHub Profile
package main
import "fmt"
func main() {
// Assuming you have access to distinct elements. If not this needs to be done
distinct := map[string]int{"a": 0, "b": 0, "c": 0, "d": 0}
// Homework: Read input from desired
given := []string{"a", "a", "a", "b", "b", "c", "c", "c", "d", "d"}
// expected := []string{"a", "b", "c", "d", "a", "b", "c", "d", "a", "c"}
<?xml version="1.0" encoding="UTF-8"?>
<content>
<item>
<source>SingSaver</source>
<headline>**EXCLUSIVE FOR HWZ Members** Apply for a card & get ADDITIONAL $40 NTUC or Uber voucher upon card approval!</headline>
<thumbnail>https://s3-ap-northeast-1.amazonaws.com/cgblogassets/wp-content/uploads/sites/2/2016/11/18095443/Airmiles1.png</thumbnail>
<link>https://www.singsaver.com.sg/blog/singsaverxhwz?utm_source=hardwarezone&utm_content=airmilesexclusive</link>
</item>
<item>
<source>SingSaver</source>
@kgthegreat
kgthegreat / greatest_prime_factor.rb
Created August 22, 2012 07:45
Finds the greatest prime factor of a number. Answer to http://projecteuler.net/problem=3
def greatest_prime_factor(n)
divider = 2
finder = n
factors = []
while divider < finder
if n%divider == 0
factors << divider
finder = finder/divider
factors << finder
end
# ignore all the log files while commiting
log/*.log
#ignore the local db config
config/database.yml
#ignore db files
db/*.sqlite3
#if you are using emacs - this is for ignoring emacs backups and file locks
.#*
#this is for other editors
*~
def binary_search(sorted_array, number_to_be_searched)
size = sorted_array.size
if number_to_be_searched < sorted_array[0] || number_to_be_searched > sorted_array[size-1]
puts "Number not found"
return
end
middle_index = size/2
middle_element = sorted_array[middle_index]
if middle_element === number_to_be_searched
middle_index = middle_index/2