Skip to content

Instantly share code, notes, and snippets.

@jareks
jareks / gist:1035322
Created June 20, 2011 08:53
Ruby 1.9.2 patch
# Copyright (C) 2011 Lunar Logic Polska http://www.lunarlogicpolska.com
# Author: Jaroslaw Skrzypek jaroslaw.skrzypek(at)llp.pl
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@jareks
jareks / fb.rb
Last active July 5, 2022 15:13
FizzBuzz
MSG = 'FizzBuzz Fizz BuzzFizz FizzBuzz Fizz '.scan(/(?:(?<!.)[a-z]{4})?[a-z]{4}|/i)
def fb2(n)
1.upto(n).map { |x| (MSG[x%15] + x.to_s)[/^([a-z]+|\d+)/i] }
end
# fb2(100)
# => ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz",
# "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz",
# "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz",
# "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz",