Skip to content

Instantly share code, notes, and snippets.

public class MockTest {
public static int bigDiff(int[] nums) {
int max = nums[0];
int min = nums[0];
for (int i = 1; i < nums.length; i++) {
int n = nums[i];
public class LabAssessmentQ1 {
public static int[] withoutTen(int[] nums){
int j = 0;
for (int i = 0; i < nums.length; i++) {
int n = nums[i];
nums[i] = 0;
package hk.edu.cityu.ast10106.gp12.inventory.ui;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
/**
class BottleShop {
private String answer = "a secret";
public int changeEmptyBottlesToDrinks(int emptyBottles) {
int drinks;
if (emptyBottles == 10) {
drinks = 1;
} else {
// Write a C++ program to simulate Mark Six lottery game.
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
using namespace std;
int main()
@phparkle
phparkle / sto.h
Last active May 3, 2017 01:24
Converts string of decimal digits to numeric type.
#include <string>
// Converts string of decimal digits to numeric type.
template <class T>
T sto(const std::string & s)
{
T t = 0;
for (const char c : s)
t = t * 10 + c - '0';
return t;
// Hi! I'm going to show you how to write a Java program that outputs the sum
// of two given numbers. I will assume that this is your first time programming
// and try to explain as much as possible.
// Before we get started, any text that follows two consecutive backslashes is
// called a "comment". You are reading a comment right now. Comments are for
// documenting code and will be completely ignored by the computer.
// Ok, let's get into it. In order to read values from input, we must import
// Scanner:
public static void main(String[] args) {
In in = new In(args[0]);
int n = in.readInt();
int[][] blocks = new int[n][n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
blocks[i][j] = in.readInt();
Board initial = new Board(blocks);
Solver solver = new Solver(initial);
if (solver.isSolvable()) {
@phparkle
phparkle / main.cpp
Created October 13, 2017 15:48
compareDoubleEqual Test
#include <limits>
#include <iostream>
using namespace std;
// The double comparison function, exactly as provided in the tutorial
bool compareDoubleEqual(double val1, double val2) {
if(abs(val1 - val2)<2.0*std::numeric_limits<double>::epsilon())
return true;
else
public class UpperBound {
public static int upperBound(String[] words, int lo, int hi, String word) {
while (lo < hi) {
int mid = lo + (hi - lo >> 1);
String other = words[mid];
int toffset = word.length() - 2;
int ooffset = other.length() - 2;
if (word.regionMatches(toffset, other, ooffset, 2))
lo = mid + 1;