This file contains hidden or 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
| package roman_to_decimal | |
| func RomanToDecimal(roman string) int { | |
| table := map[uint8] int { | |
| 'I': 1, | |
| 'V': 5, | |
| 'X': 10, | |
| 'L': 50, | |
| 'C': 100, | |
| 'D': 500, |
This file contains hidden or 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
| def insertion_sort(a) | |
| for i in 1..a.length-1 do | |
| n = a[i] | |
| pos = i | |
| while pos > 0 and a[pos-1] > n do | |
| a[pos] = a[pos-1] | |
| pos -= 1 | |
| end | |
| a[pos] = n | |
| end |
This file contains hidden or 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
| def insertion_sort(a): | |
| for i in xrange(1, len(a)): | |
| n = a[i] | |
| pos = i | |
| while pos > 0 and a[pos-1] > n: | |
| a[pos] = a[pos-1] | |
| pos -= 1 | |
| a[pos] = n | |
| return a |
This file contains hidden or 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
| package quicksort | |
| func Quicksort(a []int) []int { | |
| if (len(a) <= 1) { | |
| return a | |
| } | |
| p := partition(a) | |
| Quicksort(a[0:p]) | |
| Quicksort(a[p+1:]) | |
| return a |
This file contains hidden or 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
| #!/usr/bin/perl | |
| sub factorial { | |
| my $n = $_[0]; | |
| if ($n <= 0) { | |
| return 1; | |
| } | |
| return $n * factorial($n-1) | |
| } |
This file contains hidden or 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
| package randomselect | |
| import ( | |
| "math/rand" | |
| ) | |
| func RSelect(a []int, i int) int { | |
| n := len(a) | |
| if n == 1 { | |
| return a[0] |
This file contains hidden or 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
| package com.feliperibeiro; | |
| import java.util.Arrays; | |
| public class MaximumSubarray { | |
| public int[] max(int[] a) { | |
| int maxSum = 0, | |
| currentSum = 0, | |
| maxSumStart = 0, |
This file contains hidden or 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
| package main | |
| import ( | |
| "container/heap" | |
| "fmt" | |
| ) | |
| type Node struct { | |
| value uint8 | |
| priority int |
This file contains hidden or 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
| //bowling.go | |
| package bowling | |
| type Game struct { | |
| rolls []int | |
| currentRoll int | |
| } | |
| func NewGame() *Game { | |
| return &Game{make([]int, 21), 0} |
This file contains hidden or 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
| //O(n) in time, O(1) in space | |
| int fib(int n) { | |
| int a, b, i, temp; | |
| a = 0; | |
| b = 1; | |
| for (i = 0; i < n; i++) { | |
| temp = a; | |
| a = a + b; | |
| b = temp; | |
| } |