Initial commit

This commit is contained in:
Gregory Campbell
2021-07-08 21:26:21 -04:00
commit 3f13c058be
7 changed files with 395 additions and 0 deletions
Executable
+101
View File
@@ -0,0 +1,101 @@
--Program Created by Gregory Campbell
--For class CIS*3190's Assignment 3
--Last updated: April 7th, 2017
with ada.Text_IO; use Ada.Text_IO;
with ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with ada.strings.unbounded; use ada.strings.unbounded;
with ada.strings.unbounded.Text_IO; use ada.strings.unbounded.Text_IO;
with Ada.Calendar; use Ada.Calendar;
procedure kmp is
-- Declaration of variables
fp : file_type;
line : unbounded_string;
fileName, word : string(1..100);
wordLen, lineLen, correct, wordCount, fileLen, found : integer;
StartTime, FinTime : Time;
milli : Duration;
begin
wordCount := 0;
found := 0;
-- Asking user for file name and pattern string
put_line("Input the file you want to read from: ");
get_line(fileName, fileLen);
put_line("Input the word or pattern you want to search for: ");
get_line(word, wordLen);
-- Timing of program begins
StartTime := Clock;
-- open file
open(fp, in_file, fileName);
put_line("Match(s) found at character position: ");
-- Loop through all lines of the file checking for matches
-- If a direct match is found the character position is printed
loop
exit when end_of_file(fp);
get_line(fp, line);
lineLen := length(line);
-- Each file line is loopeed through to see if an exact character match
-- happens when compared to the pattern string
for i in 1..lineLen loop
wordCount := wordCount + 1;
correct := 0;
if (Element(line, i)) = word(1) and (i+wordLen) <= lineLen then
for j in 1..wordLen loop
if (Element(line, (i+j-1))) = word(j) then
correct := correct + 1;
end if;
end loop;
if(correct = wordLen) then
put(wordCount); new_line;
found := 1;
end if;
end if;
end loop;
wordCount := wordCount + 1;
end loop;
close(fp);
-- Prints if no matches are found
if(found = 0)then
put_line("No Match Found");
end if;
FinTime := Clock;
milli := (finTime-StartTime);
-- File is closed and a second clock time is ran to
-- calculate and display the full program run time in seconds
put_line("Total Time (seconds): " & Duration'Image(FinTime - StartTime));
-- Exception if file doesn't exist, user is notified end program ends
exception
when name_error =>
put_line("Error: File not found.");
end kmp;
Executable
+109
View File
@@ -0,0 +1,109 @@
//Program Created by Gregory Campbell
//For class CIS*3190's Assignment 3
//Last updated: April 7th, 2017
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(){
//Declaration of variables
FILE *fp;
char file[100];
char line[256];
char word[100];
int wordLen = 0, lineLen = 0, correct = 0, count = 0;
int i,j, found = 0;
//Asking user for file name and pattern string
printf("Input the file you want to read from: \n");
scanf("%s", file);
printf("Input the word or pattern you want to search for: \n");
scanf("%s", word);
//Timing of program begins
clock_t begin = clock();
//Grab length of pattern string
wordLen = strlen(word);
//open file
fp = fopen(file, "r");
//Check if file exists, if not notify user and end program
if(fp){
printf("Match(s) found at character position: \n");
//Loop through all lines of the file checking for matches
//If a direct match is found the character position is printed
while (fgets(line, sizeof(line), fp)) {
if(strcmp(line, "\n") != 0){
lineLen = strlen(line);
//Each file line is loopeed through to see if an exact character match
//happens when compared to the pattern string
for(i = 0; i < lineLen; i++){
count++;
correct = 0;
if(line[i] == word[0] && i+wordLen < lineLen){
for(j = 0; j < wordLen; j++){
if(line[i+j] == word[j]){
correct++;
}
}
if(correct == wordLen){
printf("%d\n", count);
found = 1;
}
}
}
} else {
count++;
}
}
} else {
printf("Error: File not found.\n");
return 1;
}
//Prints if no matches are found
if(found == 0){
printf("No Match Found\n");
}
//File is closed and a second clock time is ran to
//calculate and display the full program run time in seconds
fclose(fp);
clock_t end = clock();
double timeSpent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Total Time (seconds): %f \n", timeSpent);
return 0;
}
Executable
+109
View File
@@ -0,0 +1,109 @@
!Program Created by Gregory Campbell
!For class CIS*3190's Assignment 3
!Last updated: April 7th, 2017
program kmp
implicit none
! Declaration of variables
character(len=100) :: fileName
character(len=100) :: word
character(len=9999) :: line
character :: wordC, lineC
logical :: lexist
real :: start, finish, total
integer :: wordLen, lineLen, correct, wordCount, i, j, eof, found, fileLen
found = 0
eof = 0
fileLen = 0
!Asking user for file name and pattern string
write(*,*) 'Input the file you want to read from: '
read(*,'(A)') fileName
write(*,*) 'Input the word or pattern you want to search for: '
read(*,'(A)') word
!Timing of program begins
call cpu_time(start)
!Grab length of pattern string
wordLen = len(trim(word))
!Check if file exists, if not notify user and end program
inquire(file=fileName, exist=lexist)
if(lexist) then
!open file
open(unit=9, status='old', file=fileName)
write(*,*)'Match(s) found at character position: '
!Loop through all lines of the file checking for matches
!If a direct match is found the character position is printed
do
read(9,'(A)', iostat=eof) line
lineLen = len(trim(line))
fileLen = fileLen + lineLen
!Each file line is loopeed through to see if an exact character match
!happens when compared to the pattern string
do i = 1, (lineLen+1)
wordCount = wordCount + 1
correct = 0
if(line(i:i) == word(1:1) .and. i+wordLen <= lineLen+1) then
do j = 0, wordLen
if(line((i+j):(i+j)) == word(j+1:j+1)) then
correct = correct + 1
end if
end do
if(correct >= wordLen .and. eof == 0) then
write(*,*) wordCount
found = 1
end if
end if
end do
if(eof /= 0) exit
end do
close (9, status='keep')
else
write(*,*) 'Error: File not found.'
end if
!Prints if no matches are found
if(found == 0) then
write(*,*) 'No Match Found'
end if
!File is closed and a second clock time is ran to
!calculate and display the full program run time in seconds
call cpu_time(finish)
total = (finish-start)
write(*,*) 'Total Time (seconds): ', total
end
+16
View File
@@ -0,0 +1,16 @@
main:
make c
make fortran
make ada
c: kmp.c
gcc -g -Wall -o kmp-c kmp.c
fortran: kmp.f95
gfortran -o kmp-fortran kmp.f95
ada: kmp.adb
gnatmake -o kmp-ada kmp.adb
clean:
rm kmp-ada kmp.ali kmp.o kmp-fortran kmp-c test.txt
Executable
+23
View File
@@ -0,0 +1,23 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id leo gravida dolor tempus consequat. Vivamus lorem odio, vulputate in efficitur blandit, accumsan vel nulla. Maecenas tristique consequat eleifend. Sed sagittis sapien convallis massa vestibulum blandit. Morbi euismod ex a diam faucibus porta. Nam mattis, arcu quis ornare ultricies, orci dolor congue turpis, a hendrerit nibh ex eu nunc. Donec posuere eget lorem aliquam congue. Sed non ex ligula. Aenean mattis volutpat metus ut finibus. Etiam non lobortis sem. Cras pellentesque sollicitudin nibh, sit amet tempus leo dictum ut. Proin placerat aliquet eros volutpat auctor. Cras ac vehicula justo. Fusce felis erat, facilisis eu diam eget, scelerisque lacinia massa. Nullam neque mi, ultrices a dui vitae, faucibus efficitur mi.
Aliquam consequat consequat dapibus. Vivamus lobortis fringilla varius. Proin malesuada ipsum odio, tincidunt fringilla quam pretium eget. Morbi et ex laoreet, maximus odio a, elementum est. Proin id turpis sit amet leo viverra laoreet. Quisque sagittis orci a sapien semper, at tristique risus ullamcorper. Curabitur commodo dictum sem sed suscipit. Aliquam quis porttitor tortor. Aenean non ligula et libero cursus eleifend. Donec cursus ex id sodales maximus. Fusce nec faucibus turpis. Ut dapibus sodales ligula ac facilisis.
Nunc porta sit amet tortor eu porttitor. Suspendisse libero lacus, placerat eget lacus in, maximus commodo ante. Phasellus eget purus in est condimentum porttitor quis eget risus. Proin iaculis lacus risus, vitae euismod odio cursus eget. Vivamus vestibulum erat at ipsum aliquet lobortis. Donec blandit, tellus et iaculis lacinia, ligula libero eleifend mi, vitae iaculis ipsum lectus a ex. Nullam porta felis a imperdiet ultrices. Mauris id neque vitae libero tristique accumsan sit amet vitae arcu. Proin efficitur cursus felis nec interdum. Quisque id dictum ligula.
Mauris id hendrerit sem. Pellentesque sollicitudin massa ac nibh interdum, vel lobortis ex lacinia. Curabitur consequat eleifend lacinia. Maecenas elementum metus in magna euismod, et ornare ligula sollicitudin. Sed vehicula posuere orci ac semper. Morbi pellentesque, est id volutpat fermentum, dolor felis condimentum sem, sit amet tempor libero est id augue. Nullam laoreet id sapien vel pellentesque.
Cras ac dolor ante. Phasellus posuere libero sit amet augue iaculis cursus. Sed ultrices orci sollicitudin, fermentum nibh in, tincidunt ligula. In ut semper justo. Praesent at justo at odio feugiat gravida ac sit amet orci. Aenean nec euismod ipsum. Suspendisse non ex interdum, feugiat nunc id, tempus enim.
Aliquam auctor lectus felis, id elementum libero ultricies in. Fusce at cursus leo, quis efficitur diam. Vestibulum ante felis, auctor et purus at, mattis volutpat sapien. Praesent finibus eget ligula sed volutpat. Mauris nec diam neque. Quisque accumsan risus nec quam tempor, sed mollis nulla ultrices. Aenean varius libero quis turpis semper, vel posuere erat consequat. Proin sollicitudin suscipit interdum. In interdum tempus hendrerit.
Donec laoreet fringilla diam, a congue ipsum. Pellentesque placerat lacus justo, placerat blandit sapien auctor a. Donec sagittis, neque sit amet egestas aliquam, dui est faucibus turpis, in consequat augue justo vulputate justo. Nunc non justo neque. In nulla mi, dictum ac porta non, aliquet vestibulum leo. Nulla odio quam, porttitor ut ultrices vel, pellentesque ut urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam eu ornare nisl, in sagittis risus. Phasellus congue feugiat placerat.
Sed aliquam magna vitae velit viverra, et maximus turpis suscipit. Donec sit amet ligula vel mauris interdum pretium. Phasellus sit amet placerat libero. Pellentesque non turpis a velit pulvinar feugiat. Nunc egestas lobortis auctor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed at neque ac nisl tristique tincidunt. Donec et lacus posuere, venenatis velit ut, pretium felis. Nunc scelerisque lorem turpis, nec tristique ex imperdiet at. Vivamus pretium diam eget libero molestie, ut varius magna placerat. Nam odio eros, venenatis vitae dignissim et, lacinia sed nulla. Vivamus pretium est a malesuada euismod.
Proin nec justo quis justo aliquet dapibus. Morbi bibendum vitae diam sit amet congue. Pellentesque sed risus a nisi ultrices semper. Etiam feugiat dui eu massa luctus, eget malesuada nulla mollis. Quisque hendrerit, justo eget scelerisque luctus, odio dui ultricies lacus, a euismod sem turpis at ex. Morbi purus orci, pulvinar et lectus nec, pellentesque sollicitudin nulla. Curabitur libero ipsum, ullamcorper quis finibus feugiat, ultricies ut ligula. Duis pellentesque sagittis maximus. Phasellus finibus elit sit amet est ultricies, ac scelerisque eros malesuada. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nam fermentum arcu at nisi gravida, ac congue turpis mollis.
Pellentesque elementum vehicula purus nec facilisis. Nunc congue, lacus vitae hendrerit gravida, urna arcu suscipit dui, ut tincidunt nulla lorem eget nisl. Mauris eu urna ipsum. Phasellus sodales in enim id euismod. Aliquam vel ullamcorper quam. Ut sem neque, tincidunt id tortor id, ultrices bibendum erat. Pellentesque accumsan tellus nec condimentum viverra. Cras consequat erat vel neque lacinia, a condimentum mauris semper. Morbi quis sodales dui, non euismod purus. Cras lacinia nisl quis est lobortis bibendum. Nullam et velit magna. Proin ut ligula at urna vestibulum commodo. Vestibulum sed tristique velit. Phasellus ullamcorper tellus et augue vulputate varius. Pellentesque volutpat purus mi.
Vivamus euismod elementum nunc sit amet malesuada. Nullam eu convallis risus. Nunc mollis fringilla velit vel tincidunt. Donec elit quam, molestie ut turpis quis, feugiat vulputate sem. Ut eu pharetra neque. Phasellus dictum lorem sit amet justo venenatis aliquam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam non ipsum ac massa hendrerit interdum nec ac est. Curabitur odio lectus, pharetra id sollicitudin eget, consequat nec lacus.
Phasellus ornare risus a sem rhoncus finibus at vitae purus. Aenean id vestibulum urna. Fusce at magna ac erat dapibus interdum a sit amet nibh. Vivamus venenatis feugiat odio non ultrices. Nulla ultrices pulvinar risus, id venenatis metus. Suspendisse a porttitor dui. Donec quis tortor lectus. Donec condimentum dignissim urna at sollicitudin. In in nibh gravida, cursus nulla vitae, tempor nisl. Sed sed dapibus libero. Etiam leo eros, pellentesque a mauris dictum, aliquam sagittis urna. Donec velit sapien, dictum in mattis ac, tristique eget massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu cursus est. Integer bibendum.
Executable
+24
View File
@@ -0,0 +1,24 @@
TACGCAATGCGTATCATTCTGCTGGGCGCTCCGGGCGCAGGTAAA
GGTACTCAGGCTCAATTCATCATGGAGAAATACGGCATTCCGCAA
ATCTCTACTGGTGACATGTTGCGCGCCGCTGTAAAAGCAGGTTCT
GAGTTAGGTCTGAAAGCAAAAGAAATTATGGATGCGGGCAAGTT
GGTGACTGATGAGTTAGTTATCGCATTACTCAAAGAACGTATCACA
CAGGAAGATTGCCGCGATGGTTTTCTGTTAGACGGGTTCCCGCGT
ACCATTCCTCAGGCAGATGCCATGAAAGAAGCCGGTATCAAAGTT
GATTATGTGCTGGAGTTTGATGTTCCAGACGAGCTGATTGTTGAG
CGCATTGTCGGCCGTCGGGTACATGCTGCTTCAGGCCGTGTTTATC
ACGTTAAATTCAACCCACCTAAAGTTGAAGATAAAGATGATGTTAC
CGGTGAAGAGCTGACTATTCGTAAAGATGATCAGGAAGCGACTGT
CCGTAAGCGTCTTATCGAATATCATCAACAAACTGCACCATTGGTT
TCTTACTATCATAAAGAAGCGGATGCAGGTAATACGCAATATTTTAA
ACTGGACGGAACCCGTAATGTAGCAGAAGTCAGTGCTGAACTGG
CGACTATTCTCGGTTAATTCTGGATGGCCTTATAGCTAAGGCGGTT
TAAGGCCGCCTTAGCTATTTCAAGTAAGAAGGGCGTAGTACCTACA
AAAGGAGATTTGGCATGATGCAAAGCAAACCCGGCGTATTAATGG
TTAATTTGGGGACACCAGATGCTCCAACGTCGAAAGCTATCAAGC
GTTATTTAGCTGAGTTTTTGAGTGACCGCCGGGTAGTTGATACTTC
CCCATTGCTATGGTGGCCATTGCTGCATGGTGTTATTTTACCGCTTC
GGTCACCACGTGTAGCAAAACTTTATCAATCCGTTTGGATGGAAG
AGGGCTCTCCTTTATTGGTTTATAGCCGCCGCCAGCAGAAAGCACT
GGCAGCAAGAATGCCTGATATTCCTGTAGAATTAGGCATGAGCTAT
GGTTCAC
Executable
+13
View File
@@ -0,0 +1,13 @@
Dijkstra interview 1985
Q Speaking of programming bottlenecks—what will the impact of the research in artificial intelligence be?
A Can you research something that is not science? I feel that the effort to use machines to try to mimic human reasoning is both foolish and dangerous. It is foolish because if you look at human reasoning as is, it is pretty lousy; even the most trained mathematicians are amateur thinkers. Instead of trying to imitate what we are good at, I think it is much more fascinating to investigate what we are poor at. It is foolish to use machines to imitate human beings, while machines are very good at being machines, and that is precisely something that human beings are very poor at. Any successful AI project by its very nature would castrate the machine.
Q Computer science has become very popular, are there too many students, are there too few students—and do you see any change in the level of preparedness of the entering student between now and say ten years ago?
A The topic is devastatingly popular. Because computing is now supposed to cure all the ills of the world and more. I once gave a short summary of the fact that over the centuries scientific effort had been a complete disaster. The first scientific effort of course was the production of the elixir that would give eternal youth, but very rapidly they discovered that there was little point in living eternally, if you would live in eternal poverty, so the next major scientific project was how to turn anything into gold. Now it was quite clear that the planning of these two major research efforts was beyond the powers of the seers of the day, so for sound managerial reasons the next hot issue became the accurate prediction of the future. As time went by the original goals were forgotten. Medicine divorced itself from quackery, chemistry divorced itself from alchemy and astronomy divorced itself from astrology. However there is still some feeling of guilt in the academic community, because as soon as promising new branch of science or technology emerges, it is saddled up with the old hopes. The current boom in computing is an immediate reflection of absolutely unrealistic hopes. So if you ask whether there are too many or too few students: an order of magnitude too many. From a scientific point of view you would like to weed out the lot. Keep the brightest 2% and do business. The current generation of freshmen coming in is not only ill prepared, they have been misguided.
Q Are you suggesting that the personal computer boom has fostered fruitless play rather than ....
A Yes. I have said it before in public and I am perfectly willing to repeat it that someone introduced to computers via Basic is in all probability mentally mutilated beyond redemption. That is no joke. A major branch of the Siberian Academy of Arts and sciences is aimed at keeping Basic out of Siberian high schools.
Q So what will get in?
A Probably Basic.
Q Of other languages that are becoming popular, are there any that offer any better hope?
A Oh yes. The popularity of Pascal is very encouraging. Not because it is ideal, but it is definitely orders of magnitude better than any of its competitors. Besides that it is interesting because it is a one man product, without any form of political or industrial backing. It has gained its popularity in slightly over a decade, because at the time of its inception it was so much better than anything else available.
Q We have seen Lisp emerge in documenting constructs?
A Lisp was great at the time of its inception if only for a radically new way of using machines. It has suffered the fate of having been elevated to a status of de facto standard with all its defects. Despite its conceptual novelty a lot of the design of Lisp is terribly amateurish even by the standards of the time. When I read the first manual, the Lisp 1.5 manual, published in 1961, I could not believe my eyes. It was an extremely poor language. Now it has become the defacto standard of the AI community, which now suffers from Lisp, the way the rest of the world suffered from Fortran.