Skip to content

Instantly share code, notes, and snippets.

View wei2912's full-sized avatar

Ng Wei En wei2912

View GitHub Profile
import unittest
def zigzag(cs, num_rows):
"""
Authored by Dhruv - TA will be Dhruv.
In order to encode text messages in a format that is unreadable to other,
Alice decides to create a cipher and wants a program to test it out on her
messages. The cipher (which is essentially an algorithm) rewrites a text
message, taken in as a string of contiguous characters, with the use of a
import unittest
def compress_numbers_helper(ts):
"""
This helper function takes in a list of tuples indicating the ranges of
numbers and outputs the compressed numbers as an iterator of strings.
"""
for start, end in ts:
# handle singleton ranges
if start == end:
import unittest
def checksum_helper(plate):
"""
This helper function converts a license plate comprising an alphabetical
prefix (which can have one to three letters) and a numeral suffix num (which
can have one to four digits) into a tuple of six numbers.
"""
def split_plate(plate):
i = 0
@wei2912
wei2912 / plotgraph.py
Last active January 3, 2017 10:44 — forked from fishnsotong/plotgraph.py
Making a scatter plot in python by importing data from a csv file.
import numpy as np
import matplotlib.pyplot as plt
# importing data from csv file
xs, ys, zs = np.loadtxt("data.txt", unpack=True, delimiter=",", dtype=float, skiprows=0)
# labels
plt.xlabel("No. of PT-CT Pairs per Distinguisher")
plt.ylabel("lg2(T(N))")
plt.title("Lower Bound on Time Complexity of Single and Double Distinguisher Attack")
%{
#include <stdio.h>
#include <string.h>
enum yytokentype {
COMMA = 258,
SEMICOLON,
LBRACKET,
RBRACKET,
LBRACE,
%{
#include <stdio.h>
enum yytokentype {
COMMA = 258,
SEMICOLON = 259
};
char *yylval;
%}
@wei2912
wei2912 / intro.lhs
Last active August 29, 2015 14:09
Update with link to my blog.
# Shifted this file to my blog
The new link is on my blog: https://wei2912.github.io/index.html#introduction_to_haskell
I'll update the post on my blog from now on.
---
Introduction to Haskell
---
"""
https://www.reddit.com/r/lpmc/comments/2eblaq/challenge_list_of_numbers_0_valid_triangles/
author: wei2912
This solution assumes that the values can be taken from the list with
replacement and the order of the side lengths matter.
To determine if a triangle is valid, the sum of each 2 sides must be greater
than the other side.
@wei2912
wei2912 / document.md
Last active August 29, 2015 14:02
A Metric for Calculating the Complexity of a Webpage.
@wei2912
wei2912 / tutorials.md
Last active December 17, 2015 18:19
List of tutorials that NixTuts members have guided users through :)

C Basics Tutorial by Subsentient #