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" | |
| "strings" | |
| "strconv" | |
| ) | |
| type IPAddr [4]byte |
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" | |
| // fibonacci is a function that returns | |
| // a function that returns an int. | |
| func fibonacci() func() int { | |
| n, a, b := 0, 0, 1 | |
| return func() int { | |
| n, a, b = a, b, a + b |
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 ( | |
| "golang.org/x/tour/wc" | |
| "strings" | |
| ) | |
| func WordCount(s string) map[string]int { | |
| m := map[string]int{} | |
| for _, v := range strings.Fields(s) { |
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 "golang.org/x/tour/pic" | |
| func Pic(dx, dy int) [][]uint8 { | |
| s := make([][]uint8, dy) | |
| for i := range s { | |
| s[i] = make([]uint8, dx) | |
| } | |
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" | |
| "math" | |
| ) | |
| func Sqrt(x float64) float64 { | |
| z := 1.0 | |
| for { |
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
| class Thunder { } | |
| class Fire { } | |
| protocol Pokemon { | |
| typealias PokemonType | |
| func attack(move: PokemonType) | |
| } | |
| struct Pikachu: Pokemon { | |
| typealias PokemonType = Thunder |
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
| z, d = zd = ['γΊγ³', 'γγ³'] | |
| loop.lazy.map { zd.sample }.each_cons(5) do |output| | |
| p output.join('γ»') | |
| break p('γγ»γ¨γ»γ·οΌ') if output == [z, z, z, z, d] | |
| 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
| public func <(a: NSDate, b: NSDate) -> Bool { | |
| return a.compare(b) == .OrderedAscending | |
| } | |
| public func >(a: NSDate, b: NSDate) -> Bool { | |
| return a.compare(b) == .OrderedDescending | |
| } | |
| public func ==(a: NSDate, b: NSDate) -> Bool { | |
| return a.compare(b) == .OrderedSame |
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 check_sum val | |
| sum = val.to_s.each_char.with_index.inject([]) do |memo, (char, i)| | |
| next memo << double_digit_value(char.to_i) if i.odd? | |
| memo << char.to_i | |
| memo | |
| end.inject :+ | |
| if (sum % 10).zero? | |
| p "#{sum} is divisible by 10. Valid!" | |
| else |
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
| #include <stdio.h> | |
| int main() { | |
| int a = 10; | |
| int *pa = &a; | |
| int **ppa = &pa; | |
| printf("%p\n", pa); | |
| printf("%d\n", *pa); | |
| printf("%p\n", ppa); |