Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Busy being amazing

Chris Neve ChrisLeNeve

💭
Busy being amazing
View GitHub Profile
@ChrisLeNeve
ChrisLeNeve / Codility semi primes - take 2
Created Oct 9, 2020
Commenting the streams and lambdas increased the score from 44% to 55%, as time complexity decreased. Morale: don't use streams in Codility exercises
View Codility semi primes - take 2
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
//codility semi primes
@ChrisLeNeve
ChrisLeNeve / Codility: semi primes
Created Oct 9, 2020
Scores 44% - 100% correctness, 0% performance. Optimisations were done concerning boundaries and time complexity, not sure how to improve now
View Codility: semi primes
// you can also use imports, for example:
import java.util.*;
import java.util.stream.Collectors;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
//codility semi primes
@ChrisLeNeve
ChrisLeNeve / WIP - Hackerrank - abbreviation
Created Oct 4, 2020
Fails 9 out of 16 test cases (explicitly returning the wrong answer every time fails 15 / 16)
View WIP - Hackerrank - abbreviation
class Scratch {
public static void main(String[] args) {
// System.out.println(abbreviation("daBcd", "ABC")); // should be YES
// System.out.println(abbreviation("AbCdE", "AFE")); // should be NO
// System.out.println(abbreviation("beFgH", "EFG")); // should be NO
// System.out.println(abbreviation("beFgH", "EFH")); // should be YES
// System.out.println(abbreviation("Pi", "P")); // should be YES
// System.out.println(abbreviation("UMKFW", "UMKFW")); // should be YES
@ChrisLeNeve
ChrisLeNeve / scratch_23.java
Created Oct 3, 2020
Max Array Sum from HackerRank (passes all test cases)
View scratch_23.java
class Scratch {
public static void main(String[] args) {
System.out.println(maxSubsetSum(new int[] {-2, 1, 3, -4, 5}));
}
static int maxSubsetSum (int[] arr){
if (arr.length == 0) {
return 0;
View scratch_22.java
import java.util.*;
/**
* Implements a simple depth-first search for a graph.
* Limitations: does not handle a disconnected graph; does not handle cases where a vertix has multiple edges towards
* another given vertix; each vertix is defined by its index rather than by its value.
*/
class Scratch {
public static void main(String[] args) {
Scratch app = new Scratch();
View Level first traversal for a tree
class Scratch {
public static void main(String[] args) {
Scratch app = new Scratch();
Node root = app.setup();
app.printBreadthFirst(root);
}
public void printBreadthFirst(Node node) {
int height = getHeight(node);
View gist:c486760f4c292e532ef517fb7add8d3e
//@RunWith(SpringJUnit4ClassRunner.class) // for JUnit 4
//@ExtendWith(MockitoExtension.class) // for running with a Mockito runner. No Spring features
@ExtendWith(SpringExtension.class) // for running with a Spring runner. Loads Spring features (bean loading, etc)
@DisplayName("My test class name (JUnit 5)")
//@SpringBootTest // will load application context
public class MyTest {
// Strategy for loading one specific bean
// If not in a static inner class: needs to be imported on class with @Import
@ChrisLeNeve
ChrisLeNeve / Sudoku
Created Mar 25, 2020
Very basic sudoku solver (will not succeed beyond basic sudokus)
View Sudoku
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class Solution {
static final int BOARD_LENGTH = 9;
public static void main(String[] args) {
@ChrisLeNeve
ChrisLeNeve / pre-commit
Last active Mar 17, 2020
git pre commit hook - blocking added accents and bad characters
View pre-commit
#!/bin/bash
echo "Checking your changes..."
#Whatever characters you want here, in the grep
if git diff --cached origin/stage *.html | grep -c 'é\|è\|ô'
then
echo "Impending doom shall be thy fate, o vilainous junior dev! Banish from thy work these monstrosities, or live to see thy kin demolished"
exit 1
@ChrisLeNeve
ChrisLeNeve / scratch_13.java
Created Nov 13, 2019
Project Euler, problem 11 finalised
View scratch_13.java
class Scratch {
static long CURRENT_MAX = Long.MIN_VALUE;
public static void main(String[] args) {
int[][] grid = setupGrid();
computeMaxProduct(grid);
System.out.println(CURRENT_MAX);
}
private static void computeMaxProduct(int[][] grid) {
You can’t perform that action at this time.