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
fs = require 'fs' | |
readFile = (filename, enc) -> | |
new Promise (fulfill, reject) -> | |
fs.readFile filename, enc, (err, res) -> # readFile()は非同期関数 | |
if err | |
reject err | |
else | |
fulfill res |
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
# | |
# https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions | |
# | |
def power(len, sels, arr=[], &block) | |
if len == 0 then | |
yield arr | |
else | |
sels.to_a.each { |sel| | |
power len-1, sels, arr + [sel], &block | |
} |
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.upto(1000) do |c| | |
1.upto(c-1) do |b| | |
1.upto(b-1) do |a| | |
next if a + b + c != 1000 | |
next if a * a + b * b != c * c | |
puts "#{a}^2 == #{b}^2 + #{c}^2" | |
end | |
end | |
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
# | |
# https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions | |
# | |
def power(n, alts, &block) | |
_power(n, 0, [], alts, &block) | |
end | |
def _power(total, level, res, alts, &block) | |
if level < total then | |
alts.each { |op| |
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
# | |
# https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions | |
# | |
def power(level, a, &block) | |
if level > 0 then | |
['+', '-', ''].each { |op| | |
a[level-1] = op | |
power level-1, a, &block | |
} | |
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
(1..1000).each { |i| | |
(1..1000).each { |j| | |
(1..1000).each { |k| | |
next if j <= i | |
next if k <= j | |
next if i+j+k != 1000 | |
puts "#{i}, #{j}, #{k}" if i*i + j*j == k*k | |
} | |
} | |
} |
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..1000).each { |i| | |
(1..1000).each { |j| | |
k = 1000 - i - j | |
next if j <= i || k <= j | |
puts "#{i}, #{j}, #{k}" if i*i + j*j == k*k | |
} | |
} | |
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
puts "abc" |
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
File.open("/dev/input/event0","rb"){ |f| | |
while true do | |
s = f.read 16 | |
(time, type, code, value) = s.unpack "qssi" | |
if type == 2 and code == 8 then | |
puts value | |
end | |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <linux/input.h> // struct input_event とか | |
main() | |
{ | |
int mouse_fd = open("/dev/input/event0", O_RDONLY); | |
if (mouse_fd < 0) { | |
fprintf(stderr,"can't open mouse device\n"); |