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 := 9.0 | |
| for i := 0; i < 10; 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" | |
| "strconv" | |
| ) | |
| type IPAddr [4]byte | |
| func (ip IPAddr) String() 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
| def fib | |
| a, b = 0, 1 | |
| Proc.new() { | |
| a, b, c = b, b + a, a | |
| c | |
| } | |
| end | |
| f = fib | |
| 10.times { |
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
| // Execise: Fibonacci closure | |
| package main | |
| import "fmt" | |
| // fibonacci is a function that returns | |
| // a function that returns an int. | |
| func fibonacci() func() int { | |
| a, b := 0, 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
| // Exercise: Maps | |
| package main | |
| import ( | |
| "golang.org/x/tour/wc" | |
| "strings" | |
| ) | |
| func WordCount(s string) map[string]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
| // Exercise Slices | |
| package main | |
| import "golang.org/x/tour/pic" | |
| func Pic(dx, dy int) [][]uint8 { | |
| pic := make([][]uint8, dy) | |
| for i, _ := range pic { | |
| pic[i] = make([]uint8, dx) | |
| for j, _ := range pic[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
| require 'curses' | |
| include Curses | |
| init_screen | |
| start_color | |
| (Curses.constants.grep(/\AA_/) - [:A_ATTRIBUTES]).each.with_index do |e, i| | |
| setpos(i, 0) | |
| addstr(e.to_s) | |
| setpos(i, 15) |
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
| # http://pam-ya.com/blog/archives/2006/04/post-238.html | |
| $code = <<-EOS | |
| require 'openssl' | |
| require 'base64' | |
| class Clone | |
| def generate | |
| file_name = 'sample_' + Time.now.strftime('%F-%H%M%S%L') + '.rb' | |
| File.open(file_name, 'w') do |f| | |
| header = '$code = <<-EOS' | |
| footer = 'EOS' |
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
| ## refs | |
| http://macotox.hateblo.jp/entry/2014/08/16/231842 |
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
| STDIN.read.split("\n").map {|i| i.chomp.to_i}.each do |n| | |
| x = n | |
| # lst = (3..x).to_a.select(&:odd?).unshift(2) | |
| lst = (2..x).to_a | |
| result = [] | |
| sqrt = Math.sqrt(x) | |
| loop do | |
| elem = lst.shift | |
| result << elem |