Skip to content

Instantly share code, notes, and snippets.

Require Import Arith.
Require Import List.
Import ListNotations.
Check 1 :: 2 :: nil.
Check [1; 2].
Fixpoint make_payrolls_rec (d a: nat) (r: list (nat * nat)) :=
match d with
| 0 => r
@anton0xf
anton0xf / OveroadedLemmas.v
Last active March 30, 2025 08:04
overloaded lemmas in coq (bad) example
(*** oveloaded lemmas *)
(** Lambda World 2018 - How to make ad hoc proof automation less ad hoc
by Aleksandar Nanevski
https://www.youtube.com/watch?v=yFIaP1YCcxQ&t=36s *)
Require Import Bool.
Require Import String.
Require Import FunctionalExtensionality.
Require Import List.
Import ListNotations.
@anton0xf
anton0xf / NatComm.v
Last active March 19, 2025 10:36
пример индуктивного доказательства
Require Import Nat.
Theorem add_comm: forall n m: nat, n + m = m + n.
Proof.
induction n as [|n' IH].
- (** n = O *)
intro m. simpl. rewrite <- plus_n_O. reflexivity.
- (** n = S n' *)
intro m. simpl. rewrite <- plus_n_Sm. rewrite IH. reflexivity.
Qed.
module NextBiggerSpec (spec) where
import Test.Hspec
import Test.QuickCheck
import NextBigger (nextBigger)
import Data.List (sort,unfoldr)
import Data.Tuple (swap)
import Data.Maybe (isJust,fromJust)
spec :: Spec
import itertools
class Cons:
def __init__(self, head, tail_fn):
self.head = head
self._tail_fn = tail_fn
self._tail = None
def tail(self):
@anton0xf
anton0xf / fib-memo.rkt
Created September 25, 2022 13:03
memoized fibonacci example on Racket
#lang racket
(define (fib n)
(if (< n 2) n
(+ (fib (- n 1))
(fib (- n 2)))))
(time (fib 35))
; cpu time: 5219 real time: 5138 gc time: 747
; => 9227465
(require memo)
@anton0xf
anton0xf / InsertBeforeTest.java
Created January 31, 2022 10:57
Insert value into LinkedList before other value. And set iterator to point on iserted value
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
public class InsertBeforeTest {
private void insertBefore(int before, int val, ListIterator<Integer> iter) {
while(iter.hasNext()) {
;; run it by command
;; $ emacs -Q --script test2.el
(setq line "asdf qwer")
(add-face-text-property 0 4 'a t line)
(add-face-text-property 0 5 'b t line)
(print line)
;; #("asdf qwer" 0 4 (face (a b)) 4 5 (face b))
(setq word (substring line 0 4))
;; run it by command
;; $ emacs -Q --script test-add-face-text-property.el
(setq line "asdf qwer")
(add-face-text-property 0 4 'a t line)
(add-face-text-property 0 4 'a t line)
(print line)
;; #("asdf qwer" 0 4 (face a))
(add-face-text-property 0 5 'b t line)
(add-face-text-property 0 5 'b t line)
(defun company--begin-new ()
(let (prefix c)
(cl-dolist (backend (if company-backend
;; prefer manual override
(list company-backend)
company-backends))
(setq prefix
(if (or (symbolp backend)
(functionp backend))
(when (company--maybe-init-backend backend)