Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE TypeOperators #-}
{- ver. 2017 -}
module MiniPrelude (
module Prelude ,
module MiniPrelude
) where
-- import GHC.Types hiding ((:))
-- import qualified GHC.Types as GTypes
-- This exercise covers the first 6 and the 8th chapters of "Learn You a Haskell for Great Good!"
-- Chapter 1 - http://learnyouahaskell.com/introduction
-- Chapter 2 - http://learnyouahaskell.com/starting-out
-- Chapter 3 - http://learnyouahaskell.com/types-and-typeclasses
-- Chapter 4 - http://learnyouahaskell.com/syntax-in-functions
-- Chapter 5 - http://learnyouahaskell.com/recursion
-- Chapter 6 - http://learnyouahaskell.com/higher-order-functions
-- Chapter 8 - http://learnyouahaskell.com/making-our-own-types-and-typeclasses
@Zekt
Zekt / DeclareData.agda
Last active August 15, 2021 14:38
Showcasing usage of declareData and defineData now being tested in Zekt/agda.
{-# OPTIONS -v meta:5 #-}
--{-# OPTIONS -v tc.data.con:16 #-}
--{-# OPTIONS -v tc.unquote.def:11 #-}
--{-# OPTIONS -v tc.data.sort:21 #-}
--{-# OPTIONS -v tc.data.con.comp:6 #-}
--{-# OPTIONS -v tc.conv.term:21 #-}
--{-# OPTIONS -v scope.lhs:60 #-}
--{-# OPTIONS -v scope.operators:60 #-}
open import Reflection
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
let
all-hies = import (fetchTarball "https://github.com/infinisil/all-hies/tarball/4b6aab017cdf96a90641dc287437685675d598da") {};
in
{
@Zekt
Zekt / histogram.hs
Created May 7, 2018 18:03
practice for FLOLAC
toRecord :: (Int -> Int) -> Int -> (Int -> Int)
toRecord r x y | x == y = (r x) + 1
| otherwise = r y
histogram :: [Int] -> String
histogram xs = unlines (f record max) ++ "==========\n0123456789\n"
where count = foldl toRecord (const 0) xs
record = map count [0..9]
max = maximum record
@Zekt
Zekt / nub.hs
Created April 27, 2018 21:24
Wow, Such nub
import Data.List
nub xs = map fst . filter (uncurry notElem) $ zip xs (inits xs)
@Zekt
Zekt / sprout-linked-list.cpp
Created May 26, 2017 18:09
資訊之芽 2017 250 Linked-List
#include <iostream>
struct Node {
int data;
Node* next;
};
Node* head;
void print_list();
void push_front(int data);
void pop_front();
@Zekt
Zekt / sprout-double-linked-list.cpp
Created May 26, 2017 18:04
資訊之芽 2017 170 Doubly linked list
struct node {
int data;
node *prev, *next; //分別指向前一格與後一格
};
void insert(node *prev, int data) {
node* newNode = new node;
newNode->data = data;
newNode->prev = prev;
newNode->next = prev->next;
@Zekt
Zekt / sprout-lining-problem.cpp
Last active May 26, 2017 17:58
資訊之芽 2017 1415 排隊問題
#include<iostream>
//#include<cstdio>
struct node {
int num;
node* prev = nullptr;
node* next = nullptr;
};
void printLine(node* head);
@Zekt
Zekt / splitting vector.cpp
Last active January 9, 2016 14:44
Split a vector into fixed-size blocks and handle remaining objects. #Iterate #Split #Block
int* input = new int[num];
vector<thread> threads;
int i;
for(i = 0; i+segment_size < num; i += segment_size)
threads.push_back(thread(sort_segment, input+i, segment_size));
if(num-i > 0)
threads.push_back(thread(sort_segment, input+i, num-i));