This file contains hidden or 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
gcd' :: Int -> Int -> Int | |
gcd' a b = if (b/=0) then gcd' b (mod a b) else a | |
isPrime :: Integer -> Bool | |
isPrime a = if a==1 then False else iter a 2 | |
iter a n = if (n * n > a) then True else | |
if (mod a n)==0 then False else iter a (n+1) | |
This file contains hidden or 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
try([],X,Y,0) :- X = [];Y = []. | |
try([H|T],[],[],C):-write(T),write([]),write([H]),try(T, [], [H], C1), C is C1+1. | |
try([H1|T1],[],[H3|T3],C):- H1 < H3, try(T1, [], [H1|[H3|T3]], C1), C is C1+1. | |
try([H1|T1],[],[H3|T3],C):- H3 < H1, try([H1|T1], H3, T3, C1), C is C1+1. | |
try([H1|T1], [H2|T2], L3, C) :- H1 < H2, L=[H1|[H2|T2]], try(T1, L, L3, C1), C is C1+1.%1->2 | |
try([H1|T1], L2, [H3|T3], C) :- H1 < H3, L=[H1|[H3|T3]], try(T1, L2, L, C1), C is C1+1.%1->3 | |
try([H1|T1], [H2|T2], L3, C) :- H2 < H1, L=[H2|[H1|T1]], try(L, T2, L3, C1), C is C1+1.%2->1 | |
try(L1, [H2|T2], [H3|T3], C) :- H2 < H3, L=[H2|[H3|T3]], try(L1, T2, L, C1), C is C1+1.%2->3 |
This file contains hidden or 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
comp(El1, El2, CompFunc) :- call(CompFunc, El1, El2). | |
filterOdd([], []). | |
filterOdd([H|T], Akk) :- nechetn(H), !, filterOdd(T, Akk1), Akk = [H|Akk1]. | |
filterOdd([_|T], Akk) :- filterOdd(T, Akk). | |
nechetn(X) :- X mod 2 =:= 1. | |
filter([], [],_). |
This file contains hidden or 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
addHead(_,[],[]). | |
addHead(N, [H1|T1], [[N|H1]|T2]) :- addHead(N, T1, T2). | |
subset(L, Set) :- iter(L,Set,[]). | |
iter([],Set,Akk) :- sort(Set, Set1), sort(Akk, Akk1), Akk1=Set1. | |
iter([H|T],Set,Akk) :- addHead(H, T, Newlst) , append(Newlst,Akk, Akk1), iter(T, Set,Akk1). |
This file contains hidden or 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
%----------symm----------------- | |
symm(List) :- iter(List, []). | |
iter(L, L):-!. | |
iter([_|L], L):-!. | |
iter([H|T], Akk) :- iter(T, [H|Akk]). | |
%---------------reverse------------ | |
reverse_main(L1, L2) :- reverse_iter(L1, L2, []). | |
reverse_iter([], L2, L2):-!. |
This file contains hidden or 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
#lang racket | |
(define (intersect-line-segment L point1 point2) | |
(if (<= (* (+ (* (car L) (car point1))(* (cadr L) (cadr point1))(caddr L))(+ (* (car L) (car point2))(* (cadr L) (cadr point2)) (caddr L))) 0) | |
#t | |
#f)) | |
(define (intersect-line-pol P L) | |
(define (iter pred P) | |
(if (empty? P) |
This file contains hidden or 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
(define (BFS a b prosm route queue G) | |
(if (empty? queue) | |
#f | |
(let* ((wave (filter (lambda(x)(and (= x b) (= 0 (list-ref x prosm)))) (list-ref (- a 1) G)))) | |
(if (empty? wave) | |
#f | |
(if (belong-to-queue? b wave) | |
route | |
(map | |
(define (main filename) |
This file contains hidden or 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
1)В графе, заданном списком смежных вершин найти диаметр | |
2)Задан ориентированный граф списком рёбер. Найти любой цикл. | |
3)В графе найти все мосты.(граф задан списками смежности) | |
4)В графе найти все точки сочленения.(граф задан списками смежности) |
NewerOlder