This file contains 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
package com.rocketpush.puzzle; | |
public class FizzBuzz { | |
public static String fizzBuzz(boolean isFizzy, boolean isBuzzy, int i) { | |
String value = String.valueOf(i); | |
if (isFizzy && isBuzzy) { | |
value = "FizzBuzz"; | |
} else if (isFizzy) { | |
value = "Fizz"; |
This file contains 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 fibs | |
(map first | |
(iterate (fn [[a b]] [b (+ a b)]) [0 1]))) | |
(reduce + | |
(take-while | |
(partial > 4000000) (filter even? fibs))) |
This file contains 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 whole-numbers (iterate inc 1)) | |
(defn square [n] (* n n)) | |
(defn sum-of-squares [n] | |
(reduce + | |
(take n | |
(map square whole-numbers)))) | |
(defn square-of-sum [n] |
This file contains 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 + | |
(distinct | |
(concat (range 3 1000 3)(range 5 1000 5)))) |
This file contains 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..100).inject 0, { total, base -> | |
(1..100).each { power -> | |
String number = base ** power | |
if (power == number.size()) { total += 1 } | |
} | |
total | |
} |
This file contains 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 appendIsSo (adjective, names) { | |
names?.to*.plus " is so ${adjective}." | |
} | |
appendIsSo 'awesome', [to: ['Aby', 'Brooke', 'Claire']] | |
This file contains 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 candidate = 3 | |
def listOfPrimes = [2] | |
while (listOfPrimes.size() < 10001) { | |
max = Math.sqrt(candidate) | |
for (prime in listOfPrimes) { | |
if (prime > max) { | |
listOfPrimes << candidate | |
break | |
} |
This file contains 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
// brute force | |
100.upto 300, { a -> | |
a.upto 400, { b -> | |
b.upto 500, { c -> | |
if (a + b + c == 1000 && a * a + b * b == c * c) | |
println "$a * $b * $c = " + a * b * c | |
} | |
} | |
} |
This file contains 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
String sumOfPowers = (1..1000).inject(0) { sum, it -> | |
sum += it ** it | |
} | |
sumOfPowers[-10..-1] |
This file contains 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 reallyBigNumbers = | |
'''37107287533902102798797998220837590246510135740250 | |
46376937677490009712648124896970078050417018260538 | |
74324986199524741059474233309513058123726617309629 | |
91942213363574161572522430563301811072406154908250 | |
23067588207539346171171980310421047513778063246676 | |
89261670696623633820136378418383684178734361726757 | |
28112879812849979408065481931592621691275889832738 | |
44274228917432520321923589422876796487670272189318 | |
47451445736001306439091167216856844588711603153276 |
OlderNewer