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/env ruby | |
| def concat(n0) | |
| s = String.new | |
| n = 0 | |
| i = 1 | |
| while n < n0 | |
| ds = i.to_s | |
| s += ds | |
| n += ds.length |
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/ruby | |
| # cuberots.rb | |
| class Permutation | |
| attr_accessor :s | |
| attr_accessor :h | |
| def initialize(s = '12345678') | |
| @s = 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
| rots = [ | |
| k = 1: e=12345678 [] | |
| k = 2: x=56218734 [] | |
| k = 3: y=41238567 [] | |
| k = 4: z=26731584 [] | |
| ] | |
| k = 1: 0 e -> e=12345678 | |
| k = 2: 1 x -> x=56218734 | |
| k = 3: 2 y -> y=41238567 | |
| k = 4: 3 z -> z=26731584 |
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/ruby | |
| # gravnet.rb | |
| require "matrix" | |
| # simplified gravitational force (G=m=M=1.0) | |
| # from (i,j) to r | |
| def fij(i, j, r) | |
| # difference vector | |
| rij = Vector[i,j] - r |
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
| n = 98: r = Vector[0.5, 0.5], F = Vector[-0.014357405607155703, -0.01435740560715777] | |
| n = 99: r = Vector[0.5, 0.5], F = Vector[-0.014213111904535183, -0.014213111904536712] | |
| n = 100: r = Vector[0.5, 0.5], F = Vector[-0.014071689664539606, -0.01407168966453928] | |
| n = 98: r = Vector[0.25, 0.25], F = Vector[-4.6817100348218865, -4.6817100348219425] | |
| n = 99: r = Vector[0.25, 0.25], F = Vector[-4.681637888660634, -4.681637888660691] | |
| n = 100: r = Vector[0.25, 0.25], F = Vector[-4.681567178203503, -4.681567178203558] | |
| n = 98: r = Vector[0.25, 0.0], F = Vector[-14.708761955833403, -1.0966027348333074e-16] | |
| n = 99: r = Vector[0.25, 0.0], F = Vector[-14.7086898091545, 1.0235546134620965e-16] |
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/env ruby | |
| # http://stackoverflow.com/q/32568996/2579220 | |
| # examples | |
| $m = 1234567890 | |
| $n = 2345678901 | |
| $z = 987654304 | |
| $m2 = 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
| m = 42, n = 314 | |
| brute force: 57 | |
| recursive : 57 | |
| success | |
| m = 532, n = 7561 | |
| brute force: 2103 | |
| recursive : 2103 | |
| success |
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/env ruby | |
| require 'time' | |
| def to_dna(i) | |
| s = sprintf("%012d", i.to_s(4)) | |
| s.gsub!('0', 'A') | |
| s.gsub!('1', 'C') | |
| s.gsub!('2', 'G') | |
| s.gsub!('3', 'T') |
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
| 1: AAAAACGTATAC [4] | |
| 2: AAAACGTATACA [4] | |
| 3: AAAACGTATACC [4] | |
| 4: AAAACGTATACG [4] | |
| 5: AAAACGTATACT [4] | |
| 6: AAACACGTATAC [4] | |
| 7: AAACGTATACAA [4] | |
| 8: AAACGTATACAC [4] | |
| 9: AAACGTATACAG [4] | |
| 10: AAACGTATACAT [4] |
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/env ruby | |
| n = 10 | |
| def test(u, re, goal) | |
| r = (u =~ re).is_a? Integer | |
| err = (r != goal) | |
| w = err ? " ERROR" : "" | |
| d_e = err ? 1 : 0 | |
| return r, w, d_e |