Skip to content

Instantly share code, notes, and snippets.

View righ1113's full-sized avatar
🏠
Working from home

righ1113

🏠
Working from home
View GitHub Profile
@righ1113
righ1113 / Ramsey05.idr
Last active July 5, 2023 19:56
ラムゼーの有名なやつ in Idris, Egison
-- module Ramsey05
module Main
%default total
comb : Nat -> List a -> List (List a)
comb Z _ = [[]]
comb (S n) [] = []
comb (S n) (x :: xs) = [x :: y | y <- comb n xs] ++ comb (S n) xs
@righ1113
righ1113 / BreakLoop.hs
Last active June 14, 2019 23:54
foldl, foldrを元にした、蓄積変数付き、脱出可能なloop関数
-- 参考記事:https://mkotha.hatenadiary.org/entry/20110430/1304122048
module BreakLoop where
import Prelude hiding (take)
myLoop :: (accT -> a -> (accT -> b) -> b) -> (accT -> b) -> accT -> [a] -> b
myLoop _ g acc [] = g acc
myLoop f g acc (x:xs) = f acc x $ \acc' -> myLoop f g acc' xs
@righ1113
righ1113 / ArrowExample.hs
Last active April 23, 2020 08:50
アローの例題
{-
参考記事:
https://qiita.com/Lugendre/items/6b4a8c8a9c85fcdcb292
https://qiita.com/waddlaw/items/49874f4cf9b680e4b015
-}
{-# LANGUAGE Arrows #-}
module ArrowExample where
import Prelude hiding (id, (.))
import Control.Category (Category(..))
@righ1113
righ1113 / Godel07.idr
Last active July 5, 2023 19:58
ゲーデルの不完全性定理 in Idris
module Godel07
%default total
%hide Functor
-- 証明をYesコンストラクタでくるんで、Proofable型にする
data Proofable : Type -> Type where
Yes : (prf : prop) -> Proofable prop
@righ1113
righ1113 / multiOf3-N.egi
Created September 28, 2019 06:48
各桁の和が3の倍数な整数は3の倍数 in Egison
;; > egison -N
;; > loadFile("multiOf3-N.egi")
def sumMulti?(x, n2, y) =
match (sum(map(($i -> x_i), 1..n2)) + y) as mod(3)
| 0 -> #t
| _ -> #f
def afterCheck?(ans) =
@righ1113
righ1113 / poker-N.egi
Last active October 2, 2019 12:03
ジョーカー付きポーカー役判定をnew syntaxで
;; > egison -N
;; > loadFile("poker-N.egi")
;;;
;;;
;;; Poker-hands demonstration
;;;
;;;
;;
@righ1113
righ1113 / sudoku-N.egi
Last active July 5, 2023 19:56
数独 in Egison
;; > egison -N
;; > loadFile("sudoku-N.egi")
def parse(str) = map(read, map(1#pack([%1]),
match S.replace(".", "0", str) as string
| loop($i, (1, 81, _), <cons $x_i ...>, <nil>) -> map(($i -> x_i), 1..81) ))
;; checkHintPattern
def chp(n, str) = let hintValue = nth(n, parse(str)) in
@righ1113
righ1113 / ackermann.rs
Last active July 5, 2023 19:57
並列計算 & 多倍長 in Rust
// main.rsにコピペする
// Cargo.toml
// [dependencies]
// num-traits = "0.2.7"
// num-bigint = "0.2"
extern crate num_traits;
extern crate num_bigint;
@righ1113
righ1113 / addTrace01.txt
Last active August 9, 2022 21:10
CPLの練習
★★★19/10/27 理解できた
★★★19/10/22 理解できなかった
cpl> simp add1.pair(o, s.s.o)
0:add1.pair(o,s.s.o)*I
1[1]:pair(o,s.s.o)*I
2:add1*pair(o,s.s.o)
let add1 = ev.prod(pr(cur(pi2), cur(s.ev)), nat); add1が
let add3 = ev.pair(pr(cur(pi2), cur(s.ev)).pi1, pi2); add3と同じになってる
3:ev.pair(pr(cur(pi2),cur(s.ev)).pi1,pi2)*pair(o,s.s.o)
4[1]:pair(pr(cur(pi2),cur(s.ev)).pi1,pi2)*pair(o,s.s.o)
@righ1113
righ1113 / test01.ref
Last active November 16, 2019 04:39
Refalの練習
/*
https://github.com/bmstu-iu9/refal-5-lambda
> chcp 65001
> srefc.bat test01.ref
*/
/* 先頭と末尾が同じ文字なら、それを削っていく */
Pal {
= True;