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
| # -*- coding: utf-8 -*- | |
| require 'prime' | |
| def Ring(size) | |
| Ring.new(size) | |
| end | |
| class Ring | |
| attr_reader :size |
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 int_palindrome | |
| func isPalindrome(n int) bool { | |
| reverse := 0 | |
| for t := n; t > 0; t /= 10 { | |
| reverse *= 10 | |
| reverse += t % 10 | |
| } |
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 combinations(s) | |
| return [s] if s.length == 1 | |
| chars = s.chars.to_a | |
| chars.each_with_object([]) do |ch, cs| | |
| rest = chars.drop(chars.find_index(ch) + 1).join | |
| cs << ch | |
| combinations(rest).each do |comb| | |
| cs << (ch + comb) |
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 permutations(s) | |
| return [s] if s.length == 1 | |
| chars = s.chars.to_a | |
| chars.each_with_object([]) do |ch, ps| | |
| rest = chars.reject { |c| c.equal? ch }.join | |
| permutations(rest).each do |perm| | |
| ps << (ch + perm) | |
| 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
| package atoi_itoa | |
| import ( | |
| "fmt" | |
| "regexp" | |
| ) | |
| func atoi(s string) (int, error) { | |
| re := regexp.MustCompile(`^-?\d+$`) |
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 sorted_linked_list | |
| import ( | |
| "bytes" | |
| "fmt" | |
| ) | |
| type list struct { | |
| head *node | |
| } |
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 hash_table | |
| import "fmt" | |
| type bucket struct { | |
| head *entry | |
| } | |
| type entry struct { | |
| key string |
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 stack | |
| import ( | |
| "bytes" | |
| "errors" | |
| "fmt" | |
| "sync" | |
| ) | |
| type node struct { |
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 queue | |
| import ( | |
| "bytes" | |
| "errors" | |
| "fmt" | |
| "sync" | |
| ) | |
| type node struct { |
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 bag | |
| import ( | |
| "bytes" | |
| "errors" | |
| "fmt" | |
| ) | |
| type bag struct { | |
| m map[interface{}]int |