Compare commits
22 Commits
v0.3
...
3675ee066f
Author | SHA1 | Date | |
---|---|---|---|
3675ee066f | |||
f7a0384ff3 | |||
19f9c3c333 | |||
eebc90e392 | |||
5acd4908ab | |||
f022fda0d6 | |||
6d6ef03710 | |||
b5d0d55290 | |||
81548b20e6 | |||
ede6827cb6 | |||
015da8fd34 | |||
326038107c | |||
a1b8f22383 | |||
fb4d81fe67 | |||
497c7d0bea | |||
b5db1fbdc2 | |||
1adc60c991 | |||
4980d8b57c | |||
8d048e9a68 | |||
f9a739f556 | |||
3b24d422d2 | |||
e8b1d79f79 |
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Ignore CMake files:
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles/
|
||||||
|
cmake_install.cmake
|
||||||
|
Makefile
|
||||||
|
|
||||||
|
# Ignore build files:
|
||||||
|
build/
|
13
CMakeLists.txt
Normal file
13
CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.6)
|
||||||
|
project(MMMCalc)
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic-errors")
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0")
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3")
|
||||||
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -g -O3")
|
||||||
|
set(CMAKE_C_FLAGS_MIN_SIZEREL "${CMAKE_C_FLAGS} -Os")
|
||||||
|
|
||||||
|
set(SRCS
|
||||||
|
src/Main.c)
|
||||||
|
|
||||||
|
add_executable(mmmcalc ${SRCS})
|
18
README.md
18
README.md
@ -1,12 +1,16 @@
|
|||||||
MMMCalc
|
MMMCalc
|
||||||
=======
|
=======
|
||||||
|
|
||||||
This is a very simple project, it was made for educational purposes (hence why it is open-source), and I encourage everyone to contribute if they have something to add.
|
### Compiling
|
||||||
|
MMMCalc uses [CMake](http://cmake.org/) to compile. Please install the C development tools and CMake (along with whichever build script you plan on having CMake generate) in order to run this command.
|
||||||
|
```bash
|
||||||
|
$ cd build/
|
||||||
|
$ cmake ..
|
||||||
|
$ make
|
||||||
|
```
|
||||||
|
|
||||||
The most simple way to build this project is to move to the src folder/directory and run
|
### Contributing
|
||||||
|
To contribute, simply open a pull request, however, be aware that this code is licensed under a GNU GPLv3 and so will yours.
|
||||||
|
|
||||||
$ javac MMMCalc.java
|
### License
|
||||||
|
All code in this repository is under the [GNU GPLv3](/LICENSE).
|
||||||
This will allow you to build the project that should work properly if you are downloading one of the releases (if you download the straight from the master branch it might have some problems).
|
|
||||||
|
|
||||||
To contact me, send me an e-mail at <nicolas.ortega.froysa@gmail.com>.
|
|
||||||
|
0
build/.keep
Normal file
0
build/.keep
Normal file
14
src/Main.c
Normal file
14
src/Main.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// 0 = false;
|
||||||
|
// 1 = true;
|
||||||
|
char version[16] = "v0.5";
|
||||||
|
int verbose = 0;
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
printf("MMMCalc %s, Copyright (c) 2016 Nicolás A. Ortega.\n", version);
|
||||||
|
printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
|
||||||
|
printf("This program is free software and you are welcome to redistribute\n");
|
||||||
|
printf("under the terms and conditions of the GNU GPLv3 or higher.\n\n");
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,2 +0,0 @@
|
|||||||
Manifest-Version: 0.2
|
|
||||||
Main-Class: MMMCalc
|
|
@ -1,3 +1,5 @@
|
|||||||
|
package mmmcalc;
|
||||||
|
|
||||||
import java.lang.Math;
|
import java.lang.Math;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -6,7 +8,7 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* @author Nicolás A. Ortega
|
* @author Nicolás A. Ortega
|
||||||
* @copyright (C) Nicolás A. Ortega
|
* @copyright (C) Nicolás A. Ortega
|
||||||
* @license GNU General Public License 3.0 (GPLv3)
|
* @license GNU GPLv3
|
||||||
* @year 2014
|
* @year 2014
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -23,7 +25,7 @@ public class MMMCalc {
|
|||||||
private static float variance = 0;
|
private static float variance = 0;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("MMMCalc v0.2, Copyright (C) 2014 Nicolás A. Ortega\n" +
|
System.out.println("MMMCalc v0.4, Copyright (C) 2014 Nicolás A. Ortega\n" +
|
||||||
"This program comes with ABSOLUTELY NO WARRANTY; for details use '-w'\n" +
|
"This program comes with ABSOLUTELY NO WARRANTY; for details use '-w'\n" +
|
||||||
"This is free software, and you are welcome to redistribute it\n" +
|
"This is free software, and you are welcome to redistribute it\n" +
|
||||||
"under certain conditions; use '-c' for details.\n");
|
"under certain conditions; use '-c' for details.\n");
|
||||||
@ -92,7 +94,7 @@ public class MMMCalc {
|
|||||||
calcStdDev();
|
calcStdDev();
|
||||||
calcVariance();
|
calcVariance();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("You did not mention any variables. Use the -h argument for help.");
|
System.out.println("You did not mention any variables. Use the -h argument for help.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,30 +137,58 @@ public class MMMCalc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void calcQ1() {
|
private static void calcQ1() {
|
||||||
int q1Pos = numArray.length / 4;
|
int q1Pos;
|
||||||
boolean exact;
|
// c stands for case... Cases correspond to their order in the following if statements (4 different cases).
|
||||||
|
int c;
|
||||||
|
|
||||||
if(numArray.length % 4 == 0) {
|
if(numArray.length % 2.0 == 0) {
|
||||||
q1 = (numArray[q1Pos] + numArray[q1Pos-1]) / 2;
|
q1Pos = (int)(numArray.length / 4);
|
||||||
exact = false;
|
if(numArray.length % 4.0 == 0) {
|
||||||
|
q1 = (numArray[q1Pos] + numArray[q1Pos-1]) / 2;
|
||||||
|
c = 1;
|
||||||
|
} else {
|
||||||
|
q1 = numArray[q1Pos];
|
||||||
|
c = 2;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
q1 = numArray[q1Pos];
|
if(Math.ceil(numArray.length / 2.0) % 2.0 == 0) {
|
||||||
exact = true;
|
q1Pos = (int)(Math.ceil(numArray.length / 2.0) / 2.0);
|
||||||
|
q1 = (numArray[q1Pos] + numArray[q1Pos+1]) / 2;
|
||||||
|
c = 3;
|
||||||
|
} else {
|
||||||
|
q1Pos = (int)Math.ceil(numArray.length / 4.0);
|
||||||
|
q1 = numArray[q1Pos];
|
||||||
|
c = 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Q1: " + q1);
|
System.out.println("Q1: " + q1);
|
||||||
|
|
||||||
if(verbose) {
|
if(verbose) {
|
||||||
for(int i = 0; i < numArray.length; i++) {
|
for(int i = 0; i < numArray.length; i++) {
|
||||||
if(!exact) {
|
if(c == 1) {
|
||||||
if(i == q1Pos - 1) {
|
if(i == q1Pos - 1) {
|
||||||
System.out.print(">>" + numArray[i] + " !" + q1 + "! ");
|
System.out.print(">>" + numArray[i] + " !" + q1 + "! ");
|
||||||
} else if( i == q1Pos) {
|
} else if(i == q1Pos) {
|
||||||
System.out.print(numArray[i] + "<< ");
|
System.out.print(numArray[i] + "<< ");
|
||||||
} else {
|
} else {
|
||||||
System.out.print(numArray[i] + " ");
|
System.out.print(numArray[i] + " ");
|
||||||
}
|
}
|
||||||
} else {
|
} else if(c == 2) {
|
||||||
|
if(i == q1Pos) {
|
||||||
|
System.out.print(">>" + numArray[i] + "<< ");
|
||||||
|
} else {
|
||||||
|
System.out.print(numArray[i] + " ");
|
||||||
|
}
|
||||||
|
} else if(c == 3) {
|
||||||
|
if(i == q1Pos) {
|
||||||
|
System.out.print(">>" + numArray[i] + " !" + q1 + "! ");
|
||||||
|
} else if(i == q1Pos + 1) {
|
||||||
|
System.out.print(numArray[i] + "<< ");
|
||||||
|
} else {
|
||||||
|
System.out.print(numArray[i] + " ");
|
||||||
|
}
|
||||||
|
} else if(c == 4) {
|
||||||
if(i == q1Pos) {
|
if(i == q1Pos) {
|
||||||
System.out.print(">>" + numArray[i] + "<< ");
|
System.out.print(">>" + numArray[i] + "<< ");
|
||||||
} else {
|
} else {
|
||||||
@ -206,12 +236,13 @@ public class MMMCalc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Needs to calculate haflway between the median value and the last value.
|
||||||
private static void calcQ3() {
|
private static void calcQ3() {
|
||||||
int q3Pos = (numArray.length * 3) / 4;
|
/*int q3Pos = (numArray.length * 3) / 4;
|
||||||
boolean exact;
|
boolean exact;
|
||||||
|
|
||||||
if((numArray.length * 3) % 4 == 0) {
|
if((numArray.length * 3) % 4 != 0) {
|
||||||
q3 = (numArray[q3Pos] + numArray[q3Pos-1]) / 2;
|
q3 = (numArray[q3Pos+1] + numArray[q3Pos]) / 2;
|
||||||
exact = false;
|
exact = false;
|
||||||
} else {
|
} else {
|
||||||
q3 = numArray[q3Pos];
|
q3 = numArray[q3Pos];
|
||||||
@ -223,9 +254,9 @@ public class MMMCalc {
|
|||||||
if(verbose) {
|
if(verbose) {
|
||||||
for(int i = 0; i < numArray.length; i++) {
|
for(int i = 0; i < numArray.length; i++) {
|
||||||
if(!exact) {
|
if(!exact) {
|
||||||
if(i == q3Pos - 1) {
|
if(i == q3Pos) {
|
||||||
System.out.print(">>" + numArray[i] + " !" + q3 + "! ");
|
System.out.print(">>" + numArray[i] + " !" + q3 + "! ");
|
||||||
} else if(i == q3Pos) {
|
} else if(i == q3Pos + 1) {
|
||||||
System.out.print(numArray[i] + "<< ");
|
System.out.print(numArray[i] + "<< ");
|
||||||
} else {
|
} else {
|
||||||
System.out.print(numArray[i] + " ");
|
System.out.print(numArray[i] + " ");
|
||||||
@ -239,7 +270,8 @@ public class MMMCalc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.print("\n\n");
|
System.out.print("\n\n");
|
||||||
}
|
}*/
|
||||||
|
System.out.println("Q3 is not currently functional.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void calcMode() {
|
private static void calcMode() {
|
||||||
@ -308,7 +340,6 @@ public class MMMCalc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void calcVariance() {
|
private static void calcVariance() {
|
||||||
// NOTE: I'm doing it this way so I don't have to convert the variables to doubles and lose precision.
|
|
||||||
variance = stdDev * stdDev;
|
variance = stdDev * stdDev;
|
||||||
|
|
||||||
System.out.println("Variance: " + variance);
|
System.out.println("Variance: " + variance);
|
Reference in New Issue
Block a user