Skip to content

Instantly share code, notes, and snippets.

@Winwardo
Winwardo / problem.py
Created August 28, 2011 16:30
Sum of all multiples of 3 and 5 below 1000
sum1 = 0;
for i in range(3,1000):
if( ((i % 3) == 0) or ((i % 5) == 0) ):
sum1 += i
print "The sum is",sum1
print sum(x for x in range(3,100))
print sum(y for y in range(3,1000) if not(y%3) or not(y%5))
@Winwardo
Winwardo / QuickSort.pas
Created October 5, 2011 14:35
Quicksort algorithm in Pascal
program quicksort;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, windows;
// Telescoping constructor
var employee = Immutable(new Employee("John", "01234 56432", "07922344500", "53 Oakland Road", "Devon", "UK"));
// With builder
var employee = new EmployeeBuilder()
.name("John")
.phone("01234 56432")
.mobile("07922344500")
.addresslineone("53 Oakland Road")
.county("Devon")
var StudentClass = function(){
this.name = "Some default name";
this.age = undefined;
this.address = {};
};
var StudentClassBuilder = new BuilderDecorator(StudentClass);
var student = new StudentClassBuilder()
.name("John")
.age(17)
@Winwardo
Winwardo / angles.csv
Last active April 4, 2018 12:47
Angles and colours produced by incrementing by 137 degrees
Count Generated angle Angle modulo 360 (hue) Output colour
0 0 0 red
1 137 137 green
2 274 274 purple
3 411 51 yellow
4 548 188 cyan
const exampleFunction1 = (n) => {
if (predicate1) {
if (predicate2) {
sideEffect1(n)
const value1 = transformer1(arg1, arg2, n)
return transformer2(value1, arg1)
} else {
let value2 = 0
while (somePredicate()) {
const exampleFunction1 = (n) => {
if (!predicate1) {
return 7
}
if (predicate2) {
sideEffect1(n)
return transformer2(transformer1(arg1, arg2, n), arg1)
} else {
return transformer2(transformer5(n), arg2)
class MyClass {
public:
MyClass() {
value = 7;
}
int value;
};
struct MyStruct {
value: u8
}
impl MyStruct {
pub fn Create() -> MyStruct {
MyStruct {
value: 7u8
}
}
@Winwardo
Winwardo / machine.js
Last active March 4, 2020 21:32
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions