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.util.Arrays; | |
| import java.util.LinkedList; | |
| import java.util.Queue; | |
| public class PaintBucket { | |
| public static void main(String[] args) { | |
| int[][] colors = new int[][] {{2,2,0,1}, | |
| {1,0,0,0}, | |
| {0,0,0,1}, | |
| {1,1,1,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
| object Magicka { | |
| def invokeElements(spells: String, combines: List[String], oppositions: List[String]) = { | |
| val oppositionSets = oppositions.map(_.toSet) | |
| val combineMap = combines.map(c => (Set(c.charAt(0),c.charAt(1)), c.charAt(2))).toMap | |
| spells.map(List(_)).foldLeft(List[Char]())((acc,spell) => { | |
| acc.size match { | |
| case 0 => spell | |
| case _ => { | |
| // Lazily compute the set which represents spells in the accumulator that clash with the current spell. | |
| lazy val clashes = oppositionSets.filter(_.contains(spell.head)).map(_.diff(Set(spell.head))).flatten |
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.util.Arrays; | |
| import java.util.HashSet; | |
| import java.util.Set; | |
| public class TheNumbersWithLuckyLastDigit { | |
| private static int INF = 9999; | |
| public int find(int n) { | |
| int[][] edges = new int[10][10]; | |
| for (int i = 0; i < edges.length; i++) |
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.util.ArrayList; | |
| import java.util.List; | |
| public class CubeAnts { | |
| public int getMinimumSteps(int[] pos) { | |
| List<Integer> l = new ArrayList<Integer>(); | |
| for (int i : pos) l.add(i); | |
| if (l.contains(6)) return 3; | |
| else if (l.contains(2) || l.contains(5) || l.contains(7)) return 2; | |
| else if (l.contains(3) || l.contains(1) || l.contains(4)) return 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
| import java.util.HashMap; | |
| import java.util.HashSet; | |
| import java.util.Map; | |
| import java.util.Set; | |
| public class CubeStickers { | |
| public String isPossible(String[] sticker) { | |
| Set<String> uniqueStickers = new HashSet<String>(); | |
| for (String s : sticker) uniqueStickers.add(s); | |
| if (uniqueStickers.size() >= 5) return "YES"; |
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.util.HashSet; | |
| import java.util.Set; | |
| public class CandyShop { | |
| public int countProbablePlaces(int[] X, int[] Y, int[] R) { | |
| Set<Position> pos = new HashSet<Position>(); | |
| pos.add(new Position(X[0], Y[0])); | |
| pos = locationsFor(R[0], pos); | |
| for (int i = 1; i < X.length; i++) { |
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 itsOverNineThousand(n: Int)(f: () => Boolean) = { | |
| if (n > 9000) { | |
| f() | |
| } | |
| } |
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
| itsOverNineThousand(15000) { | |
| println("I think this is over nine thousand, yeah! So.. I guess I'll return true.") | |
| true | |
| } |
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 itsOverNineThousand(n: Int)(body: => Boolean) = { | |
| if (n > 9000) { | |
| body | |
| } | |
| } |
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
| itsOverNineThousand(15000) { () => | |
| println("I think this is over nine thousand, yeah! So.. I guess I'll return true.") | |
| true | |
| } |