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 SwitchFlipping { | |
public static void main (String[] args) { | |
doSlowWay(); | |
doFastWay(); | |
} | |
private static boolean isSquare (int i) { | |
int s = (int)Math.sqrt(i); | |
return (s*s) == 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
static boolean contains (int[] h, int n) { | |
int low = 0; | |
int high = h.length; | |
int d; | |
do { | |
d = (high - low) / 2; | |
int mid = low + d; | |
if (h[mid] == n) { | |
return true; | |
} else if (h[mid] < n) { |
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
# Quotient and Remainder without using division | |
def divide (num, div): | |
low, high = 0, num | |
d = high - low | |
# Keep going until there's no more midpoints between high and low | |
# Need to find the value for x such that x*div ~ num | |
while d > 1: | |
# Calculate d here or there's one iteration too few |
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
#include "Application.h" | |
#include "BaseWindow.h" | |
Application::Application(BaseWindow* window) | |
: _window(window) | |
{ | |
} | |
Application::~Application() |
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
#pragma once | |
#include <Windows.h> | |
#define DECLARE_APP(WinType) \ | |
int CALLBACK wWinMain( \ | |
HINSTANCE hInst, \ | |
HINSTANCE hPrevInst, \ | |
LPWSTR lpCmdLine, \ | |
int nCmdShow \ |
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 IcosahedronBuilder extends PolygonBuilder { | |
@Override | |
protected void buildVertices() { | |
// create 12 vertices of a icosahedron | |
float t = (float)((1.0 + Math.sqrt(5.0)) / 2.0); | |
addVertex(new Vec3d(-1, t, 0)); | |
addVertex(new Vec3d( 1, t, 0)); | |
addVertex(new Vec3d(-1, -t, 0)); | |
addVertex(new Vec3d( 1, -t, 0)); |
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
// | |
// main.c | |
// rotate | |
// | |
// Created by Dave Kennedy on 30/11/2016. | |
// Copyright © 2016 Dave Kennedy. All rights reserved. | |
// | |
#include <stdio.h> | |
#include <string.h> |
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
// | |
// main.cpp | |
// anagrammer | |
// | |
// Created by Dave Kennedy on 29/11/2016. | |
// Copyright © 2016 Dave Kennedy. All rights reserved. | |
// | |
#include <string> | |
#include <vector> |
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
package io.github.davepkennedy | |
/** | |
* Created by dakennedy on 29/11/2016. | |
*/ | |
object Anagrammer { | |
def insertAt[T](element: T, position: Int, collection: List[T]): List[T] = { | |
val (left,right) = collection.splitAt(position) | |
left ++ List(element) ++ right | |
} |
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
package io.github.davepkennedy; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by dakennedy on 29/11/2016. | |
*/ | |
public class Rotator { | |
public static List<Integer> simpleRotate (List<Integer> numbers, int amount) { |
NewerOlder