27 Mayıs 2016 Cuma

STRATEJI VE TAKTIK ARASINDAKI FARK NEDIR?

Strateji uzun sureli bir plandir.Geneldir.
Taktik ise kisa surelidir.Kisa vadeli veya anlik planlardir.Ozel bir durum icin gecerlidir.

Taktik yapacak bir sey varken ne yapilmasi gerektigini bilmek, strateji ise yapacak bir sey yokken ne yapmak gerektigini bilmektir.(Savielly Tartakower)


25 Mayıs 2016 Çarşamba

SCHEME / PROLOG DEBUGGING / TRACE

Debugging in DrRacket with Scheme is like this.
For example here is our code:


(define survives?
(lambda (position n)
(if (< n 3)
#t
(if (= position 3)
#f
(survives? (modulo (+ position (- n 3)) n) (- n 1) )))))

(require racket/trace) ; we added this end of the code
(trace survives?)


> (survives? 4 5)
>(survives? 4 5)
>(survives? 1 4)
>(survives? 2 3)
>(survives? 2 2)
<#t
#t

Debugging in Prolog is like this in SWIProlog :

?- trace, ekle2([1,2],[3,4],K).
   Call: (8) ekle2([1, 2], [3, 4], _G6833) ? creep
   Call: (9) ekle2([2], [3, 4], _G6958) ? creep
   Call: (10) ekle2([], [3, 4], _G6961) ? creep
   Exit: (10) ekle2([], [3, 4], [3, 4]) ? creep
   Exit: (9) ekle2([2], [3, 4], [2, 3, 4]) ? creep
   Exit: (8) ekle2([1, 2], [3, 4], [1, 2, 3, 4]) ? creep
K = [1, 2, 3, 4].



9 Mayıs 2016 Pazartesi

Adobe Reader Kaldigin Yerden Devam Etme

Adobe Reader da kaldigimiz yerden goruntulemeye devam istiyorsak bu ozelligi aktif hale getirelim.Adobe Reader ile bir pdf dosyasi acip Ust menuden Duzenle kismindan Tercihleri seciyoruz.Acilan pencereden Belgeler kismindan Belgeleri Acarken kaldigi yerden goruntule kismina tik koyuyoruz.Ve hepsi bu kadar ....



PROLOG CALISMALARIM #2


LISTS



Swi prolog Windows ta calistirmak icin ['/Users/user_name/Location/ex1.pl']. Ubuntu da calistirmak icin ['/home/user_name/Location/ex1.pl'].
1) There are given some facts for some German numbers and their English translation.

tran(eins,one).tran(zwei,two).tran(drei,three).tran(vier,four).tran(funf,five).tran(sechs,six).
We should write a predicate listtrans(G,E) where G german number, E english number of that number. For example listtran([eins,neun,zwei],X). should give X = [one,nine,two].

listtrans([],[]). 'The empty list should give empty number'
listtrans([X|T1],[Y|T2]):- tran(X,Y), listtrans(T1,T2).


2) We should duplicate the elements of a given list and return that new list.

For example double([1,a,5]) should return [1,1,a,a,5,5]

double([],[]).
double([A|T1],[A,A|T2]):- double(T1,T2).


3) We should combine elements of two given lists and return that new list.

For example combin([a,b,c],[1,2,3,4],X) should return X=[a,1,b,2,c,3,4]

combin(H1,[],H1).
combin([],H2,H2).
combin([H1|T1],[H2|T2],[H1,H2|T3]) :- combin(T1,T2,T3).

4) Finding the length of a list.

leng([],0).
leng([H|T],X) :- leng(T,Y), X is Y+1.

5) Another way of finding length of a list using Accumulator.

leng1([],Acc,Acc).
leng1([_|T],Acc,L) :- Acc1 is Acc+1, leng1(T,Acc1,L).




Representation Of Some Arithmetic Operations In Prolog



?- 5=:=5.
yes

?- 5=\=5.
false

etc...

6) Maximum element of a list.


maxElement([H|T],A,Max) :- H>A, maxElement(T,H,Max).
maxElement([H|T],A,Max) :- H =< A, maxElement(T,A,Max).
maxElement([],A,A).

7) Add 1 to each element of a list.

add_one([H1|T1],[H2|T2]) :- H2 is H1+1, add_one(T1,T2).
add_one([],[]).

?-add_one([1,2,4,6],X).
X = [2,3,5,7].

8) Scalar Multiplication
For example scalar_mult(3,[2,4,7],Result) should give
Result = [6,12,21]

scalar_mul(A,[],[]).
scalar_mul(A,[H1|T1],[H2|T2]) :- H2 is A*H1, scalar_mul(A,T1,T2).

9) Dot Product
For example dot([2,5,6],[3,4,1],Result) should give
2*3 + 5*4 + 6*1 = 32 Result = 32

dot([],[],0).
dot([H1|T1],[H2|T2],R) :- dot(T1,T2,Result), R is H1*H2+Result.

10) Controlling Palindrome

pal(L) :- reverse(L,L).

?-pal([e,v,e]).
true

11) Write a predicate to control whether given value is second element of list.

second(X,L) :- [_,X|_] = L

12) Write a predicate to control whether given value is last element of list.

last(X,[X]).
last(X,[Y|T]) :- last(X,T).


13) Write a predicate toptail(InList,Outlist) which says ‘no’ if inlist is a list containing fewer than 2 elements, and which deletes the first and the last elements of Inlist and returns the result as Outlist, when Inlist is a list containing at least 2 elements. For example: toptail([a],T). no toptail([a,b],T). T=[] toptail([a,b,c],T). T=[b]

top_tail([_|T],L) :- append(L,[_],T).

?- trace, toptail([a,b,c,d],T).
   Call: (8) top_tail([a, b, c, d], _G1559) ? creep 
   Call: (9) lists:append(_G1559, [_G1892], [b, c, d]) ? creep
   Exit: (9) lists:append([b, c], [d], [b, c, d]) ? creep
   Exit: (8) top_tail([a, b, c, d], [b, c]) ? creep
T = [b, c] .



14) Write a predicate swapfl(List1,List2) which checks whether List1 is identical to List2, except that the first and last elements are exchanged.
For example [a,b,c,d,e] should return [e,b,c,d,a]

iden_ti_cal([H|T],L2) :- append(A,[Y],T), append([Y],A,K), append(K,[H],L2).

15) Write a predicate swap12(List1,List2) which checks whether List1 is identical to List2, except that the first two elements are exchanged.

similar([H|T],L2) :- append([Y],A,T), append([Y],[H],B), append(B,A,L2).

16) There is a street with three neighboring houses that all have a different color. They are red, blue, and green. People of different nationalities live in the different houses and they all have a different pet. Here are some more facts about them: • The Englishman lives in the red house. • The jaguar is the pet of the Spanish family. • The Japanese lives to the right of the snail keeper. • The snail keeper lives to the left of the blue house. • Who keeps the zebra? Define a predicate zebra/1 that tells you the nationality of the owner of the zebra. Hint: Think of a representation for the houses and the street. Code the four constraints in Prolog. member and sublist might be useful predicates.


komsu(A,B,[A,B|_]).
komsu(A,B,[_|T]) :- komsu(A,B,T).

zebra(X) :- Sokak = [E1,E2,E3],
        member(ev(red,english,_),Sokak),
        member(ev(_,spanish,jaguar),Sokak),
        komsu(ev(_,_,snail),ev(_,japanese,_),Sokak),
        komsu(ev(_,_,snail),ev(blue,_,_),Sokak),
        member(ev(_,X,zebra),Sokak).

?-zebra(X).
japanese

16) There is a round table of 5 seats. Women and men seat at the table. Please find whether there are three women sitting next to each other around the table using Prolog.

woman(mary).
woman(alice).
woman(lily).
man(eric).
man(john).
man(ted).

neighbour(X,Y,[X,Y,_,_,_]).
neighbour(X,Y,[_,X,Y,_,_]).
neighbour(X,Y,[_,_,X,Y,_]).
neighbour(X,Y,[_,_,_,X,Y]).
neighbour(X,Y,[Y,_,_,_,X]).

rounded_woman(X) :- Table = [mary,alice,lily,eric,ted],
                    woman(X),
                    woman(Y),
                    neighbour(X,Y,Table),
                    woman(Z),
                    neighbour(Z,X,Table).

?-rounded_woman(W).
W=alice

17) Calculating fibonacci numbers.

1 1 2 3 5 8 13 21 ...

f(1) = 1
f(2) = 1
f(n) = f(n-1) + f(n-2)

fibo(1,1).
fibo(2,1).
fibo(X,Y) :- Z is X-1,
             fibo(Z,T),
             G is X-2,
             fibo(G,V),
             Y is T+V.
?-fibo(7,A).
A = 13

18) Occurrence of an element in list.

occur(_,[],0).
occur(A,[A|T],N) :- occur(A,T,N1), N is N1+1.
occur(A,[H|T],N) :- occur(A,T,N). 

?- occur(2,[2,1,4,2,7,2,3,9,2,2,4,2],P).
P = 6 .

19) Finding the order of an element in list.

order(A,[A|T],1).
order(A,[H|T],B) :- order(A,T,B1), B is B1+1.
?-order(a,[b,c,d,a,e],P).
P = 4


20) Finding the power of a number.

po(G,G,0,1).
po(A,A,C,S) :- po(A,A,C1,S1), C is C1+1, S is S1*A.

pow(A,B,C):- po(A,A,B,C).

?-pow(3,2,L).
L=9.

Towers of Hanoi Puzzle


Here is solition for puzzle.And Here is code for that puzzle.


   move(1,X,Y,_) :-  
    write('Move top disk from '), 
    write(X), 
    write(' to '), 
    write(Y), 
    nl. 
move(N,X,Y,Z) :- 
    N>1, 
    M is N-1, 
    move(M,X,Z,Y), 
    move(1,X,Y,_), 
    move(M,Z,Y,X).
?- ?- move(3,left,right,center).
Move top disk from left to right
Move top disk from left to center
Move top disk from right to center
Move top disk from left to right
Move top disk from center to left
Move top disk from center to right
Move top disk from left to right
true .





8 Mayıs 2016 Pazar

Scheme Calismalarim #2


Half of List



First Half of List


(define first_half 
    (lambda (lst)
            (take lst (quotient (length lst) 2))))


Last Half of List


(define first_half 
    (lambda (lst)
            (drop lst (quotient (length lst) 2))))



Mid Element of List


(define mid_element 
    (lambda (lst)
            (let loop ((aliste lst)
                       (bliste (cdr lst)))
             (cond [(null? bliste) (list (car aliste))]
                   [(null? (cdr bliste)) (list (car aliste) (cadr aliste))]
                   [else (loop (cdr aliste) (cddr bliste))]))))




Controlling Whether Given Value is Element of List


(define is_element
      (lambda (value lst)
        (cond [(null? lst) #f]
          [(equal? (car lst) (car value)) #t]
              
              [else (is_element value (cdr lst))])))

Cons structure is like this : cons

Bloga Kod / Code Ekleme

<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); line-height: 22px; margin-bottom: 11px; overflow-wrap: break-word; padding: 10.5px; word-break: break-all;"><code style="background-color: transparent; border-radius: 3px; border: 0px; padding: 0px;"><span style="color: #333333; font-family: &quot;monaco&quot; , &quot;menlo&quot; , &quot;consolas&quot; , &quot;courier new&quot; , monospace;"><span style="font-size: 11px; white-space: pre-wrap;">
Deneme</span></span></code></pre><br/>


<textarea class="bginput" cols="42" name="htmlkod" rows="5" style="background-color: whitesmoke; height: 461px; margin: 0px; width: 660px;">Buraya Kod gelcek


</textarea><br/>


<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%">
<code>buraya kodlar gelecek...</code>
</pre>

1 Mayıs 2016 Pazar

zsh ve oh-my-zsh

Install


sudo apt-get update

sudo apt-get install zsh

sudo apt-get install git-core
After this we can install oh-my-zsh

sudo curl -L http://install.ohmyz.sh | sh
Errors If we get an error which says 'Password: chsh: PAM: Authentication failure ' we should do these:
rm -fr .oh-my-zsh/

curl -L http://install.ohmyz.sh > install.sh

sh install.sh
Selecting Theme Default theme is robbyrussel.We should change this to agnoster by like this:

~/.zshrc

ZSH_THEME="robbyrussell" #(change this default one)
ZSH_THEME="agnoster" # (to this. this is one of the fancy one)
Open a new terminal window and it should look like