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
(reduce + | |
(filter (fn[x] (or (zero? (rem x 5)) | |
(zero? (rem x 3)))) | |
(range 0 1000) | |
) | |
) | |
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
(defn fib-step [[a b]] | |
[b (+' a b)]) | |
(defn fib-seq [] | |
(map first (iterate fib-step [0 1])) | |
) | |
(defn -main [& args] | |
(reduce +' (filter even? (take 4000000 (fib-seq))))) |
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
(defn fib-step [[a b]] | |
[b (+' a b)]) | |
(defn fib-seq [] | |
(map first (iterate fib-step [0 1])) | |
) | |
(defn -main [& args] | |
(reduce +' (filter even? (take-while (partial > 4e6) (fib-seq))))) |
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 'RMagick' | |
if !ARGV[0] || !ARGV[1] | |
puts "Usage: ruby pixels.rb path-to-image" | |
exit | |
end | |
image = Magick::Image::read(ARGV[0])[0] | |
image.each_pixel do |pixel, col, row| |
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 put_sticker(sticker, x, y) | |
photo_path = photo.file_path | |
loot_image = Magick::Image::read(photo_path)[0] | |
sticker_image = Magick::Image::read(sticker)[0] | |
loot_image = loot_image.composite(sticker_image, x, y, Magick::AtopCompositeOp) | |
out = photo_path.sub(/\./, "-sticker.") | |
loot_image.format = "PNG" | |
loot_image.write(out) | |
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
@image_generator.put_campaign_sticker "public/images/stickers/campaign.png" | |
new_photo = @image_generator.photo.file_path.sub(/\./, "-sticker.") | |
expected_photo = File.join(Rails.root, 'spec', 'assets', 'test-result-campaign.png') | |
new_image = Magick::Image.read(new_photo)[0] | |
expected_image = Magick::Image.read(expected_photo)[0] | |
new_image.signature.should eql expected_image.signature |
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
recursive_function(argument1) { | |
return recursive_function(argument1) | |
} |
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
recursive_function(argument1) { | |
if (argument1 == 10) { return argument1 } | |
return recursive_function(argument1 + 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
O | |
S O | |
S (S O) | |
S (S (S O)) | |
S (S (S (S O))) | |
... |
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
cO | |
cS cO | |
cS (cS cO) | |
cS (cS (cS cO)) | |
... | |
cS (cS (cS (...)))... |