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 Entry { | |
public final long base; | |
public final long exponent; | |
public Entry(long base, long exponent) { | |
// 2⁷ > 100 so we start from the sixth power | |
for (int e = 6; e > 1; --e) { | |
final double pow = Math.pow(base, 1.0 / e); | |
final long roundedPow = Math.round(pow); | |
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
public class Solution { | |
// The sum of each square is: | |
// `1`; n == 1 | |
// `4n² + n²-(n-1) + n²-2(n-1) + n²-3(n-1)`; n > 1 | |
// or `4n² - 6(n-1)` | |
// | |
// Substituting `n = 2k+1`: | |
// `Σ(k ≤ K)(4(2k+1)² - 6(2k+1-1))` | |
// `Σ(k ≤ K)(4(4k²+4k+1) - 12k)` | |
// `4Σ(k ≤ K)(4k²+4k+1 - 3k)` |
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
import java.io.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import org.junit.*; | |
import org.junit.runner.*; | |
public class LatticePaths { | |
private final Map<RectangleDimensions, Integer> numberOfPathsMemo = new ConcurrentHashMap<RectangleDimensions, Integer>(); | |
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 Solution { | |
/** Immutable closed range of array indices */ | |
private static class IndexRange { | |
/** Inclusive start of range */ | |
public final int start; | |
/** Inclusive end of range */ | |
public final int end; | |
public IndexRange(final int start, final int 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
// `-Prelease.auto-scope=true` for parameterless build jobs that publish (eg build PR jobs) | |
if (project.hasProperty('release.auto-scope') && project.properties['release.auto-scope'] == 'true') { | |
project.ext['release.scope'] = releaseScope(file('CHANGELOG.md') as String[]) | |
} | |
def releaseScope(String[] changelog) { | |
final unreleased = (changelog | |
.dropWhile { | |
!(it =~ /^#+ +\[Unreleased\]/) | |
}.takeWhile { |
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
// Copied from https://github.com/Mahoney/slf4j-test/issues/3 and slightly modified. | |
import org.hamcrest.BaseMatcher; | |
import org.hamcrest.Description; | |
import org.hamcrest.Matcher; | |
import org.slf4j.event.Level; | |
import org.slf4j.event.LoggingEvent; | |
import org.slf4j.helpers.MessageFormatter; | |
public class LoggerMatcher { |
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
#!/bin/bash | |
exec /opt/scala-2.10/bin/scala -feature "$0" "$@" | |
!# | |
import scala.annotation.tailrec | |
import scala.language.postfixOps | |
/** | |
* From https://stackoverflow.com/questions/25129721/scala-memoization-how-does-this-scala-memo-work. | |
* |
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
#!/bin/bash | |
exec /opt/scala-2.10/bin/scala -feature "$0" "$@" | |
!# | |
class CartesianProduct(product: Traversable[Traversable[_ <: Any]]) { | |
override def toString(): String = { | |
product.toString | |
} | |
def *(rhs: Traversable[_ <: Any]): CartesianProduct = { |
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
#!/bin/bash | |
exec /opt/scala-2.10/bin/scala -feature "$0" "$@" | |
!# | |
import scala.annotation.tailrec | |
object Primes { | |
private lazy val notDivisibleBy2: Stream[Long] = 3L #:: notDivisibleBy2.map(_ + 2) | |
private lazy val notDivisibleBy2Or3: Stream[Long] = notDivisibleBy2 | |
.grouped(3) |
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
#!/bin/bash | |
exec /opt/scala-2.10/bin/scala -feature "$0" "$@" | |
!# | |
object Primes { | |
private lazy val notDivisibleBy2: Stream[Long] = 3L #:: notDivisibleBy2.map(_ + 2) | |
private lazy val notDivisibleBy2Or3: Stream[Long] = notDivisibleBy2 | |
.grouped(3) | |
.map(_.slice(1, 3)) | |
.flatten |