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 "fmt" | |
| import "strings" | |
| import "strconv" | |
| func isbn10(s string) string { | |
| ss := strings.Split(s, "") | |
| sum := 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
| require_relative 'product' | |
| class Checkout | |
| attr_reader :checkout_items, :products | |
| def initialize | |
| @products = Hash.new | |
| @checkout_items = [] | |
| load_products |
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 is_happy(n): | |
| while (n != 1): | |
| digits = str(n) | |
| sum = 0 | |
| i = 0 | |
| print n | |
| while (i < len(digits)): | |
| sum += int(digits[i]) ** 2 | |
| i += 1 | |
| n = sum |
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
| # Longest distance between identical numbers in a list ignoring identical numbers in between | |
| # e.g. input number of numbers 5, then each number followed by a return | |
| # use gets.chomp to get console input | |
| n = gets.chomp.to_i | |
| h = Hash.new | |
| (1..n).each do |i| | |
| n = gets.chomp.to_i | |
| if h[n] | |
| h[n] << i |
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 "fmt" | |
| func for_loop() { | |
| sum := 0 | |
| for i := 0; i < 10; i++ { | |
| sum += i | |
| } | |
| fmt.Println(sum) |