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
proc addcomma {num} { | |
set s {}; set r {} | |
if {$num < 0} { | |
set result "-" | |
set num [expr abs($num)] | |
} | |
lassign [split $num .] upper lower | |
set len [string length $upper] | |
for {set i 0} {$i < $len} {incr i} { | |
set s [list [string index $upper $i] $s] |
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
namespace path {::tcl::mathop ::tcl::mathfunc} | |
proc primes n { | |
set half [/ [- $n 1] 2] | |
set xs [lrepeat $half 1] | |
set p 0; set root [/ [sqrt $n] 2] | |
while {$p < $root} { | |
if {[lindex $xs $p]} { | |
set step [+ [* 2 $p] 3] | |
set index [+ $p $step] | |
while {$index < $half} { lset xs $index 0; incr index $step } |
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
proc prime? n { | |
if {$n <= 0} { return 0 } | |
if {$n >= 341550071728321} { error prime? } | |
if {$n < 4759123141} { set as {2 7 61} } else { set as {2 3 5 7 11 13 17} } | |
if {$n == 2 || $n == 3 || $n == 5 || $n == 7 || $n == 11 || $n == 13 || $n == 17 || $n == 61} { | |
return 1 | |
} | |
if {$n == 1 || $n % 2 == 0} { return 0 } | |
set d [expr {$n - 1}] | |
while {$d % 2 == 0} { set d [expr {$d / 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
# Zeller's congruence | |
# 0 => Sunday | |
proc zeller {y m d} { | |
set t {0 3 2 5 0 3 5 1 4 6 2 4} | |
if {$m < 3} { incr y -1 } | |
expr {($y + $y/4 - $y/100 + $y/400 + [lindex $t $m-1] + $d) % 7} | |
} |
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
/* Concurrent Clean code for ini file */ | |
:: INI = {section :: String, key :: String, value :: String} | |
instance toString INI where | |
toString ini = ini.section +++ "\t" +++ ini.key +++ "\t" +++ ini.value | |
toStringINIList :: [INI] -> String | |
toStringINIList ini = f "" "" ini where | |
f str _ [] = str |
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
definition module Primes | |
isPrime :: Int -> Bool | |
isPrimeMR :: Int -> Bool | |
primes :: [Int] | |
primeArray :: Int -> {#Bool} | |
primeList :: Int -> [Int] | |
rangePrimes :: Int Int -> [Int] |
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
permutation :: [a] -> [[a]] | Eq a | |
permutation [] = [[]] | |
permutation xs = [[x:rest] \\ x <- xs, rest <- (permutation o filter ((<>) x)) xs] | |
perm :: [[a]] -> [[a]] | Eq a | |
perm [] = [[]] | |
perm [xs:xss] = [[x:rest] \\ x <- xs, rest <- (perm o map (filter ((<>) x))) xss] | |
powerSet :: [a] -> [[a]] | |
powerSet [] = [[]] |
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
definition module PairingHeap | |
:: Heap a = Empty | Node a [Heap a] | |
peek :: (Heap a) -> a | |
push :: a -> (Heap a) -> (Heap a) | Ord a | |
pop :: (Heap a) -> (Heap a) | Ord a | |
listToHeap :: ([a] -> (Heap a)) | Ord a | |
heapToList :: (Heap a) -> [a] | Ord a |
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
module Main | |
import StdEnv, StdDebug, StdLib, BigInt, Rational//, StdOverloadedList, Parsers | |
//--------------------------------------------------------------------------------- | |
S :: (a -> b -> c) (a -> b) a -> c | |
S f g x = f x (g 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
definition module EulerIO | |
put :: a *World -> *World | <<< a | |
puts :: [a] *World -> *World | <<< a | |
reads :: File -> [Char] | |
readlines :: File -> [String] | |
splitCharsAt :: Char -> ([Char] -> [[Char]]) | |
splitStringAt :: Char -> String -> [String] |
OlderNewer