Bruker goto ofte i C, er ingenting gale med det om det gjøres riktig.
Noe av min verste kode er nok noe jeg skrev i prolog for noe skole greier, første gang jeg la øye på prolog kode var uken før, og jeg var også ny til logisk programmering.
Kode
%Person definition.
%person(
% name,
% war_afghanistan,
% war_iraq,
% money,
% rich
% army
% tax
% benefits
% church
% pro_life
% government
% nuclear_weapons,
% america
% immegrants
% free_health_care
% CCTV
% privacy
% )
% Person template.
%person('name', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'no','no','no','no','no','no').
% Emma is a person that should vote labour.
person('Emma', 'no', 'no', 'no', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes', 'no','no','yes','yes','yes','no').
% Sarah is a ultra-conservative.
person('Sarah', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'yes', 'yes','no','no','yes','no').
% Sindre should vote libdem
person('Sindre', 'no', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'no', 'no','no','yes','yes','no','yes').
% Tom should vote conservative.
person('Tom', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'no', 'no', 'no', 'yes','yes','no','no','yes','no').
%person(Name,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)
% predicate to check if a person likes having privacy and freedom.
likes_freedom(Name) :-
person(Name,_,_,_,_,_,_,_,_,_,Government,_,_,_,_,CCTV,Privacy),
Government = 'no',
CCTV = 'no',
Privacy = 'yes'.
% Check if a person likes that the governments regulate things like economy, and is generally
% government supportive.
likes_regulation(Name) :-
person(Name,_,_,_,_,_,Tax,_,_,_,Government,_,_,_,_,CCTV,_),
Tax = 'yes',
Government = 'yes',
CCTV = 'yes'.
% Check if the person is a capitalist, capitalists likes money and rich people.
capitalist(Name) :-
person(Name,_,_,Money,Rich,_,_,_,_,_,_,_,_,_,_,_,_),
Money = 'yes',
Rich = 'yes'.
% Checks to see if the person is for bombing afghanistan and iraq.
afraid_of_terrorists(Name) :-
person(Name,War_Afghanistan,War_Iraq,_,_,_,_,_,_,_,_,_,_,_,_,CCTV,_),
War_Afghanistan = 'yes',
War_Iraq = 'yes',
CCTV = 'yes'.
% Check if a person would like more defence spendings.
afraid_of_china_russia(Name) :-
person(Name,_,_,_,_,Army,_,_,_,_,_,Nuclear_Weapons,_,_,_,_,_),
Nuclear_Weapons = 'yes',
Army = 'yes'.
% Check if the person is positive to giving benefits, such as free health care.
social_worrier(Name) :-
person(Name,_,_,_,_,_,Tax,Benefits,_,_,_,_,_,_,FHC,_,_),
Tax = 'yes',
Benefits = 'yes',
FHC = 'yes'.
% A person is deemed conservative if he or her is a capitalist, for bombing iraq and
% afghanistand, and wants more defence spendings.
conservative(Name) :-
capitalist(Name),
afraid_of_terrorists(Name),
afraid_of_china_russia(Name).
% A ultra-conservative is a person that is conservative, and is for politics influenced by the
% church, and is pro life.
ultra_conservative(Name) :-
conservative(Name),
person(Name,_,_,_,_,_,_,_,Church,Pro_life,_,_,_,_,_,_,_),
Church = 'yes',
Pro_life = 'yes'.
% A libdem voter is a person that likes freedom, has nothing against social benefits like free
% health care, and is not against immegrants.
libdem(Name) :-
likes_freedom(Name),
social_worrier(Name),
person(Name,_,_,_,_,_,_,_,_,_,_,_,_,Immegrants,_,_,_),
Immegrants = 'yes'.
% A labour voter is a person that is for social benefits like free health care, and likes
% government regulations of things like economy, and has nothing against immegrants.
labour(Name) :-
social_worrier(Name),
likes_regulation(Name),
person(Name,_,_,_,_,_,_,_,_,_,_,_,_,Immegrants,_,_,_),
Immegrants = 'yes'.
vote(Name) :-
ultra_conservative(Name),
write(Name),write(' is ultra-conservative and should vote conservative.'),nl.
vote(Name) :-
conservative(Name),
write(Name),write(' is conservative and should vote conservative.'),nl.
vote(Name) :-
libdem(Name),
write(Name),write(' is liberal and should vote libdem.'),nl.
vote(Name) :-
labour(Name),
write(Name),write(' is labour and should vote labour.'),nl.
Det er også noe kode jeg skrev for en robot i C++, det endte opp som en suppe av halvveis C og C++ kode, med OO noen steder og ikke andre der det burde være. Samt at jeg aldri klarte å bestemme meg for å bruke cout eller printf, og brukt litt av begge. Denne koden er litt for lang til å poste her dessverre.