A tutorial for the UPL Video Lecture Series
by Leo Rudberg
All of the commands below are prefixed by git and are run inside your (Unix-like) terminal (bash, zsh, etc.).
| # implemented for all real rational numbers | |
| class Float | |
| # determine if a real rational number is zero | |
| # we know a number is zero if one cannot divide another by it | |
| def _is_zero_? | |
| begin | |
| # need to check for any non-zero number | |
| # we might as well put pi in the cache | |
| x = Math::PI.ceil |
| /* | |
| I used this tutorial below to get some nice looking bars to start out with: | |
| http://css-tricks.com/html5-progress-element | |
| Some page-specific code has been redacted, only the meat remains | |
| Don't blame me if this doesn't compile! This meant for education! | |
| */ | |
| const IS_WEBKIT = 'WebkitAppearance' in document.documentElement.style; | |
| const RGB_STR_REGEX = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/; |
| # A while back, Major League Hacking (mlh.io) wanted to make a video | |
| # similar to the "I Believe That We Will Win" videos. | |
| # In the video, hackers will say the line, showing off our passion and diversity. | |
| # Being a hacker first, an a normal human second, I took the request as a challenge. | |
| # When I remembered that `say` was a thing in Terminal, I knew what I had to do... | |
| # In this gist (and hopefully a video), I'll explain what my one liner means. | |
| # Hopefully, you'll learn some awesome Ruby tricks along the way. | |
| # If you are new to Ruby, http://feministy.github.io/ruby_basics/#/ is a great start. | |
| # Here's my one-liner: |
All of the commands below are prefixed by git and are run inside your (Unix-like) terminal (bash, zsh, etc.).
| -- the middle integer item from a list | |
| middle :: [Integer] -> Integer | |
| middle list = list !! (fromIntegral midInd) | |
| where midInd = length list `div` 2 | |
| -- the median of three integer values | |
| -- thanks to Tony Jiang from HH Coding for the improved algo! | |
| qMed3 :: Integer -> Integer -> Integer -> Integer | |
| qMed3 a b c = min firstMax (max firstMin c) | |
| where firstMax = max a b |
| import Data.List (nub, unfoldr) | |
| -- FIXME | |
| primeItr :: Integer -> Integer -> Bool | |
| primeItr n i | |
| | (i * i) > n = True | |
| | otherwise = if (n `mod` i) == 0 | |
| then False | |
| else primeItr n (i + 1) | |
| isPrime :: Integer -> Bool | |
| isPrime n = primeItr n 2 -- 2-7 primes do not count (n > 10) |
| import java.awt.Color; | |
| import java.awt.Graphics; | |
| import java.awt.image.BufferedImage; | |
| import java.io.*; | |
| import javax.imageio.ImageIO; | |
| import java.lang.Math; | |
| import java.lang.Number; | |
| public class Grid | |
| { |
| import qualified Data.Set as Set | |
| phi :: Set.Set a | |
| phi = Set.empty | |
| pset :: (Ord a) => Set.Set a -> Set.Set (Set.Set a) | |
| pset set = if (Set.null set) | |
| then Set.singleton phi | |
| else | |
| let head = Set.elemAt 0 set |
First, let's make sure that you have ghc and ghci installed:
$ ghc --version && ghci
# ghci should boot up...