Skip to content

Instantly share code, notes, and snippets.

View tobloef's full-sized avatar

Tobias Løfgren tobloef

View GitHub Profile
@tobloef
tobloef / wordsplitter.cs
Created August 25, 2017 19:59
Inspired by a classic programming interview question, this C# program will take an input string and split it into a string of space-seperated words from a dictionary. "Applepieplate" will for example split into "apple pie plate". I've implemented two versions of this program, one that uses a string array as a dictionary and one that uses a trie.…
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass {
// The dictionary to check the words against. Normally this would be loaded from a file.
// If the dictionary is too big, loading it directly from the file into a trie would be better.
private static HashSet<string> dictSet = new HashSet<string>() {
"all",
"base",
@tobloef
tobloef / koch_snowflake.py
Created August 25, 2017 20:03
Generates a Koch snowflake
from turtle import Turtle
def drawLine(turtle, size, depth, cur = 1):
if (cur < depth):
drawLine(turtle, size, depth, cur + 1)
turtle.left(60)
drawLine(turtle, size, depth, cur + 1)
turtle.right(120)
drawLine(turtle, size, depth, cur + 1)
turtle.left(60)
@tobloef
tobloef / IsPalindromeAndSquare.js
Last active August 25, 2017 20:04
Finds numbers that are both palindromes and squares
'use strict';
function findPalinSquare(n) {
let nextRoot = Math.ceil(Math.sqrt(n + 1));
while (true) {
const nextSquare = nextRoot * nextRoot;
if (isPalin(nextSquare)) {
return nextSquare;
}
nextRoot++;
}
@tobloef
tobloef / main.js
Last active August 25, 2017 20:05
Solver for the Riddler's Legacy 2 challenge
const { Socket } = require("net");
const { StringDecoder } = require("string_decoder");
const solve = require("./solve.js");
const ip = "192.168.200.234";
const port = 2224;
const client = new Socket();
client.on("connect", connectHandler);
client.on("data", dataHandler);
const CryptoJS = require("crypto-js");
const emojis = ["🀄","🃏","🅰","🅱","🅾","🅿","🆎","🆑","🆒","🆓","🆔","🆕","🆖","🆗","🆘","🆙","🆚","🇦🇨","🇦🇩","🇦🇪","🇦🇫","🇦🇬","🇦🇮","🇦🇱","🇦🇲","🇦🇴","🇦🇶","🇦🇷","🇦🇸","🇦🇹","🇦🇺","🇦🇼","🇦🇽","🇦🇿","🇦","🇧🇦","🇧🇧","🇧🇩","🇧🇪","🇧🇫","🇧🇬","🇧🇭","🇧🇮","🇧🇯","🇧🇱","🇧🇲","🇧🇳","🇧🇴","🇧🇶","🇧🇷","🇧🇸","🇧🇹","🇧🇻","🇧🇼","🇧🇾","🇧🇿","🇧","🇨🇦","🇨🇨","🇨🇩","🇨🇫","🇨🇬","🇨🇭","🇨🇮","🇨🇰","🇨🇱","🇨🇲","🇨🇳","🇨🇴","🇨🇵","🇨🇷","🇨🇺","🇨🇻","🇨🇼","🇨🇽","🇨🇾","🇨🇿","🇨","🇩🇪","🇩🇬","🇩🇯","🇩🇰","🇩🇲","🇩🇴","🇩🇿","🇩","🇪🇦","🇪🇨","🇪🇪","🇪🇬","🇪🇭","🇪🇷","🇪🇸","🇪🇹","🇪🇺","🇪","🇫🇮","🇫🇯","🇫🇰","🇫🇲","🇫🇴","🇫🇷","🇫","🇬🇦","🇬🇧","🇬🇩","🇬🇪","🇬🇫","🇬🇬","🇬🇭","🇬🇮","🇬🇱","🇬🇲","🇬🇳","🇬🇵","🇬🇶","🇬🇷","🇬🇸","🇬🇹","🇬🇺","🇬🇼","🇬🇾","🇬","🇭🇰","🇭🇲","🇭🇳","🇭🇷","🇭🇹","🇭🇺","🇭","🇮🇨","🇮🇩","🇮🇪","🇮🇱","🇮🇲","🇮🇳","🇮🇴","🇮🇶","🇮🇷","🇮🇸","🇮🇹","🇮","🇯🇪","🇯🇲","🇯🇴","🇯🇵","🇯","🇰🇪","🇰🇬","🇰🇭","🇰🇮","🇰🇲","🇰🇳","🇰🇵","🇰🇷","🇰🇼","🇰🇾","🇰🇿","🇰","🇱🇦","🇱🇧","🇱🇨","🇱🇮","🇱🇰","🇱🇷","🇱🇸","🇱🇹","🇱🇺","🇱🇻","🇱🇾","🇱","🇲🇦","🇲🇨","🇲🇩","🇲🇪","🇲🇫","🇲🇬","🇲🇭","🇲🇰","🇲🇱","🇲🇲","🇲🇳","🇲🇴","🇲🇵","🇲🇶","🇲🇷","🇲🇸","🇲🇹","🇲🇺","🇲🇻","🇲🇼","🇲🇽","🇲🇾","🇲🇿","🇲","🇳🇦","🇳🇨","🇳🇪","🇳🇫","🇳🇬
@tobloef
tobloef / deep-omit.ts
Created June 20, 2023 07:16
DeepOmit<T, K> utility type. Like Omit<T, K>, but allows you to omit nested props with dot notation.
// Examples
type ExampleType = {
string: string,
interface: ExampleInterface,
class: ExampleClass,
array: Array<ExampleInterface>,
tuple: [ExampleClass, ExampleInterface],
function: () => void,
nested1: {
@tobloef
tobloef / main.js
Last active July 25, 2023 14:10
Trustpilot Backend Challenge Solution
/**
* Code for the Trustpilot backend challenge.
*
* This program will perform a type of dictionary attack against a list of MD5 hashes. An anagram of the hashed strings are know, which reduces the search space greatly.
*
* After the program has run, the following secret phrases will have been found:
* Easy secret phrase: printout stout yawls
* Medium secret phrase: ty outlaws printouts
* Hard secret phrase: wu lisp not statutory
*/