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 'set' | |
| swedish_consonants = "bcdfghjklmnpqrstvwxz".chars.to_set | |
| code = "vovatottotenonkokokokarore".chars | |
| result = [code.first] | |
| i = 1 | |
| while (i < code.length) | |
| if code[i] == "o" && code[i-1] == code[i+1] && swedish_consonants.include?(code[i-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
| for line in 0...32 { | |
| println("".join((0...78).map { (col: Int) -> String in | |
| var x = 0.0, y = x, i = 0 | |
| do { | |
| x = x * x - y * y + Double(col) / 20.0 - 2.3 | |
| y = 2 * x * y + Double(line) / 10.0 - 1.5 | |
| i++ | |
| } while (x * x + y * y) < 4 && i < 78 | |
| return "\(UnicodeScalar(0x1f35b + 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
| class Numeric | |
| def ≫(n) | |
| n.replace self.to_s | |
| end | |
| end | |
| class String | |
| def ≫(s) | |
| s.replace self | |
| end | |
| def +(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
| /* \u002a\u002f\u0063\u006c\u0061\u0073\u0073\u0020\u0048\u007b\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0076\u0029\u007b\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u0028\u0022\u0048\u0065\u006a\u0020\u0076\u00e4\u0072\u006c\u0064\u0065\u006e\u0021\u0022\u0029\u003b\u007d\u007d\u002f\u002a */ |
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
| c = ('a'..'z').to_a | |
| srand(1792579 * 1800) | |
| f = (0..3).map { c[rand(26)] } | |
| b = (0..3).map { c[rand(26)] } | |
| a = [f, b].map {|s| s.join.capitalize } | |
| srand(s = 93113 * 19243) | |
| puts (0..99).map{|i| [a[0], a[0] + a[(srand(s) if i%15 < 1) || 1].to_s, a[1], i+1][rand(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
| def e(k,t);s=*((j=q=w=0)..l=256);k*=l;(0..l).map{|i|j+=s[i]+k[i];s[i],s[j%=l]=s[j%=l],s[i]};(0...t.size).map{|i|q+=1;w=(w+s[q%=l])%l;s[q],s[w]=s[w],s[q];t[i]=t[i]^s[(s[q]+s[w])%l]};t;end | |
| key = "test".chars.map(&:ord) | |
| text = "test".chars.map(&:ord) | |
| e(key, text) == [218, 234, 84, 101] | |
| # e=->k,t{k*=l=256;j=q=w=0;s=*0..l;l.times{|i|j+=s[i]+k[i];s[i],s[j]=s[j%=l],s[i]};t.map{|c|w+=s[q+=1];s[q],s[w]=s[w%=l],s[q];c^s[(s[q]+s[w])%l]}} | |
| e=->k,t{j=q=w=0;s=*0..l=256;l.times{|i|j+=s[i]+k[i];s[i],s[j]=s[j%=l],s[i]};t.map{|c|w+=s[q+=1];s[q],s[w]=s[w%=l],s[q];c^s[(s[q]+s[w])%l]}} |
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
| // Week numbers are hard. Here's a bug I found earlier today. | |
| // If you want to construct a string like this | |
| String yearWeekKey = year + week; | |
| // then you can't use | |
| String year = new SimpleDateFormat("yyyy").format(date); | |
| String week = String.format("%02d", new LocalDate(date).getWeekOfWeekyear()); | |
| // when date is 2016-01-01 because the key will be "201653" and that week does not exist. | |
| // Instead you have to use .weekyear() because that correctly returns 2015 for 2016-01-01. | |
| String year = new DateTime(ets).weekyear().getAsString(); |
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 'ipaddr' | |
| sum = 0 | |
| File.open("us-military-dod.csv").each_line do |line| | |
| ip1, ip2 = line.split(/;/) | |
| sum += IPAddr.new(ip2).to_i - IPAddr.new(ip1).to_i | |
| end | |
| puts 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
| prng = Random.new | |
| Trials = 37000 | |
| lost = 0 | |
| Trials.times do | |
| bad_results = 0 | |
| 250.times do | |
| result = prng.rand(1..37) | |
| if result <= 19 | |
| bad_results += 1 | |
| 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
| "[email protected]".replaceAll("(.*)([+].*)(@.*)","$1$2"); |