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
digits :: Int -> [Int] | |
digits x = reverse $ revDigits x | |
revDigits :: Int -> [Int] | |
revDigits 0 = [] | |
revDigits x = x `mod` 10 : revDigits (x `div` 10) |
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
-- check the multiplicative persistence of a given number | |
-- https://www.youtube.com/watch?v=Wim9WJeDTHQ&list=PLt5AfwLFPxWKuRpivZd_ivR2EvEzKrDUu&index=2 | |
-- https://oeis.org/A003001 | |
import System.Environment(getArgs) | |
import Data.List(intercalate) | |
main = do | |
args <- getArgs | |
let n = read (head args) :: Integer |
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
split :: Eq a => a -> [a] -> [[a]] | |
split _ [] = [[]] | |
split delim str = | |
let (before, remainder) = span (/= delim) str | |
in before:case remainder of | |
[] -> [] | |
x -> split delim $ tail 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
#include <stdbool.h> | |
#include <SDL2/SDL.h> | |
#define WINDOW_TITLE "Title" | |
#define WINDOW_X 20 | |
#define WINDOW_Y 20 | |
static void update(GState *state); | |
static void event_handler(GState *state); | |
static void destroy_state(GState *state); |
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
#include "sdl_boilerplate.h" | |
int main(void) | |
{ | |
GState *gstate = graphics_init(400, 400); | |
graphics_run(gstate); | |
graphics_quit(gstate); | |
return 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
NAME = name | |
CC = gcc | |
CCFLAGS = -Wall -Wextra | |
LDFLAGS = | |
HEADER = header.h | |
SRC = main.c | |
OBJ = $(SRC:.c=.o) | |
RM = rm -f |
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
#include <stdio.h> | |
union Color | |
{ | |
int hexcode; | |
struct | |
{ | |
unsigned char b; | |
unsigned char g; | |
unsigned char r; |
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
isPrime :: Int -> Bool | |
isPrime 2 = True | |
isPrime 3 = True | |
isPrime x | |
| x < 2 = False | |
| x `mod` 2 == 0 || x `mod` 3 == 0 = False | |
| otherwise = divCheck 5 | |
where divCheck d | |
| d * d > x = True | |
| x `mod` d == 0 || x `mod` (d + 2) == 0 = False |
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
-- Reverse Polish Notation parser | |
-- from: http://learnyouahaskell.com/functionally-solving-problems | |
rpn :: String -> Float | |
rpn expr = head $ foldl foldFunc [] (words expr) | |
where foldFunc acc op | |
| head op `elem` ['1'..'9'] = (read op :: Float) : acc | |
| otherwise = applyOp op (acc !! 1) (head acc) : drop 2 acc | |
applyOp op a b = case op of "+" -> a + b | |
"-" -> a - b |
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
nom=didier age=43,xp=65,hp=100 | |
nom=dupond age=12,xp=34,hp=110 | |
nom=jean age=1,xp=2,hp=110 |
OlderNewer