This file contains 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
-- problem 28 | |
compareLength::(Int, [a]) ->(Int, [a]) -> Ordering | |
compareLength a1 a2 = if (fst a1 > fst a2) then GT else LT | |
lsort :: [[a]] -> [[a]] | |
lsort l = map (\x -> (snd x) ) $ sortBy compareLength $ map (\x -> (length x, x)) l |
This file contains 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
-- problem 16 | |
myDropEveryNElements :: [a] -> Int -> [a] | |
myDropEveryNElements l n = if length l > n then | |
let (first, second) = splitAt n l | |
in (init first) ++ (myDropEveryNElements second n) else l | |
myDropEveryNElementsBis :: [a] -> Int -> [a] | |
myDropEveryNElementsBis l n = helper l n 1 [] | |
where |
This file contains 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
import Data.List | |
-- problem 11 | |
data Element a = Multiple a Int | Single a deriving (Show, Eq) | |
encodeModified :: Eq a => [a] -> [Element a] | |
encodeModified [] = [] | |
encodeModified l = map (\x -> if (length x > 1) then Multiple (head x) (length x) else Single (head x)) $ group l | |
This file contains 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
{-# LANGUAGE TemplateHaskell #-} | |
import Data.List | |
import Test.QuickCheck | |
import Test.QuickCheck.All | |
-- problem 1 | |
myLast :: [a] -> a | |
myLast (x:[]) = x |
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Data.Text as T | |
import Data.Char (isDigit) | |
import System.IO | |
import Data.List (partition, intersperse) | |
import System.Environment (getArgs) | |
main = do | |
args <- getArgs | |
content <- readFile(args !! 0) |
This file contains 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
// http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html | |
switch(a) { | |
case 0: | |
doSomething(); | |
break; | |
case 1: | |
doSomethingElse(); | |
break; |
This file contains 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
import javax.swing.*; | |
import java.awt.*; | |
import java.lang.*; | |
class main | |
{ | |
public static void main (String Args []) | |
{ | |
GUIwindow guiW = new GUIwindow(); | |
} |
This file contains 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
-- problem 1 | |
myLast :: [a] -> a | |
myLast (x:[]) = x | |
myLast (x:xs) = myLast xs | |
myLast [] = error "Empty list" | |
myOneLineLast :: [a] -> a | |
myOneLineLast x = x !! (length x - 1) | |
-- problem 2 |
This file contains 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
@app.route('/') | |
def show_home(): | |
file_to_read = url_for('static', filename='posts/post1.txt') | |
with open(filename, 'r') as f: | |
return f.readlines() | |
return show_home_page() |
This file contains 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
-> post = Post(form.title.data, form.content.data, datetime.now(), form.category.data, form.author.data) | |
(Pdb) form.content.data | |
u"<pre class=prettify>\r\n@app.route('/delete/<model_name>/<int:_id>', methods=['POST'])\r\n@requires_auth\r\ndef delete_resource(model_name, _id):\r\n</pre>" | |
(Pdb) c | |
result = | |
@app.route('/delete//', methods=['POST']) |