Compare commits
5 Commits
455db932ad
...
66706d26f2
Author | SHA1 | Date |
---|---|---|
Bram van den Heuvel | 66706d26f2 | |
Bram | edcc3caf91 | |
Bram | 2cf9264509 | |
Bram | 55e76024b3 | |
Bram | 25bb949724 |
|
@ -0,0 +1,7 @@
|
|||
both: p1 p2
|
||||
|
||||
p1:
|
||||
gcc -o main1 part_1.c -lcs50
|
||||
|
||||
p2:
|
||||
gcc -o main2 part_2.c -lcs50
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,43 @@
|
|||
#include <stdio.h>
|
||||
#include <cs50.h>
|
||||
#include <string.h>
|
||||
|
||||
// The amount of input lines
|
||||
const int lines = 1000;
|
||||
|
||||
int extract_number(char *text);
|
||||
|
||||
int main(void) {
|
||||
int sum = 0;
|
||||
|
||||
for (int i = 0; i < lines; i++) {
|
||||
sum += extract_number(get_string(""));
|
||||
}
|
||||
|
||||
printf("%i\n", sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get the right number from both sides of the string
|
||||
*/
|
||||
int extract_number(char *text) {
|
||||
int length = strlen(text);
|
||||
int first;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = text[i];
|
||||
|
||||
if (c >= '0' && c <= '9') {
|
||||
first = c - '0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i <= length; i++) {
|
||||
char c = text[length - i];
|
||||
|
||||
if (c >= '0' && c <= '9') {
|
||||
return (first * 10) + (c - '0');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// The amount of input lines
|
||||
const int lines = 1000;
|
||||
|
||||
// The amount of numbers that can be found
|
||||
const int number_size = 10;
|
||||
|
||||
const char numbers[10][6] =
|
||||
{ "zero"
|
||||
, "one"
|
||||
, "two"
|
||||
, "three"
|
||||
, "four"
|
||||
, "five"
|
||||
, "six"
|
||||
, "seven"
|
||||
, "eight"
|
||||
, "nine"
|
||||
};
|
||||
|
||||
int extract_number(int *numbers, int size);
|
||||
int *find_numbers(char *text);
|
||||
int numbers_size(int *numbers);
|
||||
int starts_with_number(char *text);
|
||||
|
||||
int main(void) {
|
||||
int sum = 0;
|
||||
|
||||
for (int i = 0; i < lines; i++) {
|
||||
// Instead of directly looping through the array,
|
||||
// we extract a list of integers first
|
||||
int *ns = find_numbers(get_string(""));
|
||||
|
||||
// Then use that list to increase the sum
|
||||
sum += extract_number(ns, numbers_size(ns));
|
||||
|
||||
// Free all allocated information
|
||||
free(ns);
|
||||
}
|
||||
|
||||
printf("%i\n", sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Given a list of integers, combines the first and the last digit to create a
|
||||
single number between 0 and 100.
|
||||
*/
|
||||
int extract_number(int *numbers, int size) {
|
||||
return (numbers[0] * 10) + numbers[size - 1];
|
||||
}
|
||||
|
||||
// Convert a string to an array of integers
|
||||
int *find_numbers(char *text) {
|
||||
int length = strlen(text);
|
||||
|
||||
int *items = malloc(sizeof(int) * length);
|
||||
int cursor = 0;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = text[i];
|
||||
|
||||
if (c >= '0' && c <= '9') {
|
||||
items[cursor] = c - '0';
|
||||
cursor++;
|
||||
}
|
||||
else {
|
||||
int n = starts_with_number(text + i);
|
||||
|
||||
if (n >= 0) {
|
||||
items[cursor] = n;
|
||||
cursor++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items[cursor] = -1;
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
int numbers_size(int *numbers) {
|
||||
int i = 0;
|
||||
|
||||
while (numbers[i] >= 0) {
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Determine whether a (sub)string starts with a given number.
|
||||
*/
|
||||
int starts_with_number(char *text) {
|
||||
for (int i = 0; i < number_size; i ++) {
|
||||
if (strstr(text, numbers[i]) == text) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// If not, return -1
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
both: p1 p2
|
||||
|
||||
p1:
|
||||
gcc -o main1 part_1.c -lcs50 -I../include ../include/parse.c
|
||||
|
||||
p2:
|
||||
gcc -o main2 part_2.c -lcs50 -I../include ../include/parse.c
|
|
@ -0,0 +1,100 @@
|
|||
Game 1: 7 blue, 6 green, 3 red; 3 red, 5 green, 1 blue; 1 red, 5 green, 8 blue; 3 red, 1 green, 5 blue
|
||||
Game 2: 9 green, 1 blue, 12 red; 1 blue, 18 green, 8 red; 2 blue, 6 green, 13 red; 3 blue, 13 red, 7 green; 5 blue, 4 red, 4 green; 6 blue, 7 green, 4 red
|
||||
Game 3: 5 blue, 9 red, 14 green; 10 green, 3 blue; 11 red, 2 blue, 8 green; 5 red, 2 blue; 5 blue, 7 green, 8 red
|
||||
Game 4: 2 red, 3 blue, 2 green; 17 green, 6 blue, 1 red; 3 blue, 5 green, 1 red; 4 red, 1 blue, 16 green; 5 red, 4 blue, 13 green; 14 green, 5 blue, 6 red
|
||||
Game 5: 3 red, 17 green, 10 blue; 9 blue, 5 green; 14 green, 9 blue, 11 red
|
||||
Game 6: 4 green, 18 blue, 3 red; 6 green, 8 blue, 9 red; 4 green, 9 blue, 7 red; 9 red, 1 green, 12 blue
|
||||
Game 7: 1 blue, 14 green; 1 red, 4 blue, 15 green; 3 blue, 6 green; 3 blue, 2 green, 1 red; 1 red, 3 green, 1 blue
|
||||
Game 8: 10 red, 3 blue, 3 green; 5 blue, 7 red, 3 green; 3 red, 3 green, 11 blue; 1 red, 7 green, 10 blue; 13 blue, 5 green, 5 red; 1 green, 17 blue, 3 red
|
||||
Game 9: 1 blue, 6 green; 7 green, 2 red; 3 red, 2 green; 1 blue, 4 red, 3 green; 7 green, 1 blue, 1 red
|
||||
Game 10: 14 green, 6 blue, 1 red; 8 green, 5 red, 1 blue; 8 green, 5 blue, 5 red; 2 green, 3 blue, 5 red
|
||||
Game 11: 1 blue, 2 green; 1 blue, 1 green, 7 red; 1 blue, 4 green, 7 red; 2 red, 2 green, 1 blue
|
||||
Game 12: 5 blue, 12 green, 12 red; 11 green, 3 red; 14 green, 3 blue, 18 red
|
||||
Game 13: 2 green, 6 red; 6 red, 5 blue; 7 red, 3 blue, 8 green; 7 red, 8 green; 3 blue, 2 green, 3 red; 1 blue, 8 red, 6 green
|
||||
Game 14: 18 green, 6 blue, 5 red; 5 blue, 15 red, 19 green; 7 green, 11 blue, 20 red; 5 red, 18 green, 7 blue
|
||||
Game 15: 3 red, 16 green, 1 blue; 11 green, 6 red, 1 blue; 12 green, 2 red; 17 green, 1 blue, 14 red
|
||||
Game 16: 3 red, 2 green, 5 blue; 1 green, 6 blue, 1 red; 1 green, 2 blue, 3 red; 1 blue, 1 red; 5 blue, 1 green, 2 red
|
||||
Game 17: 3 blue, 6 red; 1 blue, 2 red; 1 blue, 1 green, 7 red; 1 green, 7 red, 2 blue; 7 red, 1 blue; 1 green, 8 red, 1 blue
|
||||
Game 18: 6 green, 10 red; 6 red, 7 green; 10 red, 11 green; 10 red, 2 blue, 5 green
|
||||
Game 19: 2 blue; 1 blue, 4 green, 6 red; 7 green, 6 red, 2 blue; 2 blue, 5 red, 4 green; 1 green, 10 red
|
||||
Game 20: 6 red, 5 green, 10 blue; 5 blue, 5 green, 9 red; 7 blue, 3 green, 3 red; 9 blue, 12 red, 1 green
|
||||
Game 21: 4 red, 18 blue, 14 green; 3 green, 14 blue, 5 red; 5 green, 12 blue; 1 blue, 2 red, 1 green; 5 red, 11 green, 7 blue; 17 green, 4 red, 15 blue
|
||||
Game 22: 1 blue, 14 green, 4 red; 7 green, 10 red; 9 green, 1 blue, 9 red; 1 blue, 8 green, 5 red
|
||||
Game 23: 4 blue, 5 green, 2 red; 6 blue, 8 red, 4 green; 4 blue, 17 red, 14 green
|
||||
Game 24: 3 green, 8 blue; 3 blue, 5 green, 13 red; 17 red, 4 green
|
||||
Game 25: 19 red, 9 blue, 1 green; 3 green, 18 red, 6 blue; 1 green, 7 red, 7 blue; 8 blue, 1 red
|
||||
Game 26: 10 green, 12 blue, 2 red; 9 red; 10 blue, 12 green, 9 red
|
||||
Game 27: 2 blue, 8 green, 6 red; 5 green, 9 red; 4 red, 11 green
|
||||
Game 28: 10 blue, 20 red; 14 blue, 3 green, 2 red; 9 red, 12 blue, 1 green
|
||||
Game 29: 4 red, 1 blue, 2 green; 1 green, 6 red, 1 blue; 15 red
|
||||
Game 30: 1 red, 13 blue, 6 green; 3 blue, 4 green; 19 blue, 11 green; 1 red, 11 green, 14 blue
|
||||
Game 31: 10 red, 12 green; 12 green, 10 red; 2 blue, 15 red, 12 green; 2 green, 2 blue, 15 red; 9 green, 5 red, 2 blue
|
||||
Game 32: 5 blue, 5 green, 8 red; 5 green, 6 red; 5 blue, 8 red, 4 green; 5 green, 3 blue, 6 red
|
||||
Game 33: 1 red, 9 green, 5 blue; 17 green, 4 blue; 3 green, 2 blue; 10 green, 2 blue; 1 blue, 4 green; 2 green, 9 blue
|
||||
Game 34: 11 blue, 11 red, 9 green; 13 red, 3 blue, 5 green; 9 green, 12 blue, 5 red; 13 red, 8 blue, 5 green
|
||||
Game 35: 1 green, 3 red, 7 blue; 1 red, 3 green, 9 blue; 1 blue, 2 green, 1 red; 11 blue, 5 red, 6 green
|
||||
Game 36: 4 blue, 12 green, 16 red; 7 blue, 11 green; 8 green, 5 blue, 1 red; 14 green, 3 red
|
||||
Game 37: 13 red, 5 blue, 9 green; 1 red, 10 blue, 14 green; 1 green, 2 blue, 10 red; 13 red, 10 blue; 1 blue, 8 green
|
||||
Game 38: 3 red, 4 blue, 8 green; 1 red, 11 blue, 4 green; 13 blue, 8 green; 3 red, 3 green, 10 blue; 1 red, 1 blue, 1 green; 1 green, 2 red, 10 blue
|
||||
Game 39: 9 red, 7 blue, 1 green; 15 red, 4 green, 1 blue; 2 green, 8 blue, 7 red; 6 blue, 11 red; 12 red, 2 blue, 7 green
|
||||
Game 40: 13 red, 3 green, 1 blue; 3 green, 10 red; 16 red
|
||||
Game 41: 1 blue, 3 red; 7 blue, 5 red, 3 green; 4 red, 3 blue, 2 green; 2 blue, 5 red, 1 green; 3 green, 4 red, 3 blue; 5 blue, 2 red
|
||||
Game 42: 1 red, 4 green; 11 red, 4 green; 13 red; 1 blue, 10 red; 1 blue, 2 red, 4 green
|
||||
Game 43: 11 green, 13 red, 1 blue; 11 green, 9 red, 2 blue; 7 green; 13 green, 15 red; 1 blue, 14 green
|
||||
Game 44: 5 green, 14 blue, 15 red; 13 blue, 15 green; 9 green, 15 red, 6 blue
|
||||
Game 45: 16 red, 8 blue; 1 green, 4 blue, 6 red; 4 blue, 8 red; 12 red, 3 blue, 3 green; 2 green, 4 red, 4 blue; 2 green, 8 blue, 10 red
|
||||
Game 46: 12 blue, 3 green, 12 red; 9 red, 9 blue; 3 green, 12 red; 10 red, 6 green; 2 red, 7 blue
|
||||
Game 47: 9 green, 6 red; 1 blue, 7 red, 10 green; 1 green, 2 red; 1 red, 3 green
|
||||
Game 48: 9 blue, 5 green, 13 red; 14 green, 4 red; 15 red, 9 green, 1 blue; 4 blue, 6 red, 13 green; 9 green, 8 blue, 8 red
|
||||
Game 49: 5 blue, 3 red; 1 green, 2 red, 5 blue; 1 green, 7 blue; 3 green
|
||||
Game 50: 8 red, 6 green; 10 blue, 4 green, 6 red; 8 green, 11 blue, 9 red
|
||||
Game 51: 5 blue; 13 blue; 1 red, 2 blue, 1 green; 1 red, 8 blue
|
||||
Game 52: 7 blue; 1 red, 2 green, 12 blue; 1 red, 5 blue; 2 red, 7 blue, 4 green; 3 green, 2 red, 2 blue
|
||||
Game 53: 10 blue, 12 red; 3 green, 5 blue, 3 red; 14 red, 4 green, 7 blue; 1 red, 14 blue
|
||||
Game 54: 2 blue, 14 red, 3 green; 3 green, 7 red; 2 blue, 3 green, 9 red; 3 green, 7 red; 1 green, 14 red, 1 blue
|
||||
Game 55: 3 green, 9 red, 12 blue; 5 blue, 5 green, 2 red; 7 green, 14 red, 12 blue
|
||||
Game 56: 1 blue, 3 red, 4 green; 5 red, 8 green, 1 blue; 3 green, 1 blue, 2 red
|
||||
Game 57: 8 blue, 13 red, 2 green; 3 blue, 5 red; 7 red, 2 green; 2 red, 5 blue, 3 green; 1 green, 4 blue
|
||||
Game 58: 4 green, 3 red, 2 blue; 5 green, 2 blue, 10 red; 11 green, 1 red, 2 blue; 4 red, 5 green
|
||||
Game 59: 5 green; 4 green, 2 blue; 1 red, 9 green; 7 green, 2 blue; 16 green, 1 blue
|
||||
Game 60: 6 green, 5 blue, 1 red; 5 blue, 3 green, 6 red; 1 green, 5 blue, 14 red; 6 red, 4 blue, 3 green
|
||||
Game 61: 2 green, 6 red, 6 blue; 6 blue, 3 red; 1 green, 2 red, 2 blue; 1 red, 2 green; 5 red, 1 green, 2 blue; 2 green, 6 red, 6 blue
|
||||
Game 62: 18 green, 8 blue, 1 red; 8 green, 4 red; 13 blue, 1 red, 3 green; 7 blue, 2 green, 4 red; 4 blue, 12 green, 5 red; 12 green, 11 blue
|
||||
Game 63: 2 red, 3 blue; 10 green, 13 red, 1 blue; 11 red, 3 green, 4 blue
|
||||
Game 64: 1 green, 16 red; 17 blue, 9 red, 1 green; 14 red, 7 blue
|
||||
Game 65: 7 blue, 11 red, 11 green; 7 red, 11 green; 3 blue, 13 red, 11 green; 5 green, 6 blue; 11 blue, 8 red, 3 green
|
||||
Game 66: 3 blue, 1 green, 3 red; 5 blue, 2 green, 5 red; 1 blue, 2 green, 7 red; 2 blue, 6 red; 7 red, 2 green, 2 blue; 2 red
|
||||
Game 67: 1 blue, 6 red, 2 green; 1 blue, 10 green, 6 red; 8 red, 2 blue, 4 green; 7 green, 9 red, 1 blue; 8 red, 7 green; 5 green, 1 blue
|
||||
Game 68: 15 blue, 8 green, 2 red; 6 blue, 2 green; 5 red, 6 green, 8 blue; 6 red, 11 green, 7 blue; 1 red, 3 blue; 5 red, 6 green, 5 blue
|
||||
Game 69: 5 blue, 4 green; 1 green, 11 red, 9 blue; 4 green, 15 blue, 6 red; 11 blue, 4 green, 5 red; 8 red, 3 green; 5 blue, 8 red
|
||||
Game 70: 5 blue, 4 red, 8 green; 6 blue, 6 green; 14 blue, 7 red, 1 green; 2 green, 6 blue, 3 red; 7 red, 11 blue, 3 green
|
||||
Game 71: 13 red, 6 blue, 10 green; 7 red, 12 green; 9 green, 14 red, 2 blue
|
||||
Game 72: 9 red, 3 green, 3 blue; 8 red, 7 blue, 5 green; 3 blue, 2 green, 1 red; 1 red, 2 blue, 2 green; 10 red, 7 green, 6 blue
|
||||
Game 73: 4 green, 3 red; 1 red; 2 red, 2 blue, 2 green; 1 blue, 3 red, 1 green; 2 blue, 3 red, 2 green; 1 red, 1 blue
|
||||
Game 74: 12 green, 4 red, 4 blue; 3 red, 13 green; 1 red, 13 green, 1 blue; 1 red, 3 blue, 6 green; 6 blue, 5 red, 4 green; 7 blue, 5 green, 1 red
|
||||
Game 75: 11 red, 1 green; 12 blue, 1 red; 2 blue, 1 green, 4 red; 11 red; 12 red, 6 green, 10 blue; 4 green, 5 blue, 7 red
|
||||
Game 76: 2 blue, 5 red, 6 green; 1 red, 10 green, 11 blue; 7 red, 11 green; 4 red, 10 blue, 10 green; 7 blue, 16 green, 2 red
|
||||
Game 77: 2 blue, 11 red, 4 green; 6 green, 3 blue, 2 red; 2 blue, 2 red, 7 green; 8 red, 14 blue, 5 green; 5 green, 2 blue, 18 red
|
||||
Game 78: 9 red, 7 green, 6 blue; 12 blue, 6 red; 1 red, 15 blue, 7 green; 3 blue, 11 green, 1 red
|
||||
Game 79: 3 blue; 1 blue; 1 red, 1 blue, 1 green; 3 blue; 5 blue, 1 red; 1 blue, 1 green, 1 red
|
||||
Game 80: 18 blue, 13 green, 7 red; 18 blue, 3 green, 3 red; 2 red, 9 blue, 14 green
|
||||
Game 81: 11 blue, 6 green, 3 red; 8 green, 12 red, 10 blue; 5 red, 4 blue, 13 green
|
||||
Game 82: 2 blue, 3 red; 4 blue, 17 red; 9 red; 12 red; 1 green, 6 blue, 7 red; 20 red
|
||||
Game 83: 1 blue, 1 red; 3 red, 1 blue; 3 red, 5 green; 1 blue, 2 green, 4 red; 5 green, 3 blue, 2 red
|
||||
Game 84: 4 red, 2 blue, 2 green; 8 red, 10 blue; 1 green, 15 red, 8 blue
|
||||
Game 85: 15 green; 11 red, 2 blue, 5 green; 8 red, 2 blue, 12 green; 15 red, 10 green; 10 red, 15 green; 17 red, 1 blue, 11 green
|
||||
Game 86: 6 blue, 1 red; 2 green, 1 red, 8 blue; 2 green, 10 blue; 10 blue, 2 green; 1 red, 5 blue
|
||||
Game 87: 4 red, 4 blue; 18 red, 8 blue; 16 red; 4 red, 1 green, 3 blue; 14 red, 9 blue
|
||||
Game 88: 11 green, 7 blue, 4 red; 3 red; 2 blue, 12 red, 19 green; 13 red, 3 blue, 2 green
|
||||
Game 89: 1 green, 1 red; 1 blue, 1 red, 6 green; 6 green, 3 red; 5 green, 2 red, 6 blue; 7 blue, 2 red, 8 green; 1 red, 2 blue
|
||||
Game 90: 3 green, 3 red, 3 blue; 5 green, 2 blue, 3 red; 1 blue, 2 red; 11 green, 1 blue, 2 red; 1 green, 3 blue, 4 red
|
||||
Game 91: 7 blue, 2 red; 2 blue, 1 red, 1 green; 6 blue, 1 red; 1 red, 7 blue
|
||||
Game 92: 11 green, 16 blue; 17 red, 7 blue, 9 green; 11 green, 3 blue, 12 red; 2 blue, 1 green, 6 red
|
||||
Game 93: 6 red, 1 blue, 3 green; 1 blue, 8 red, 7 green; 3 red, 5 green; 1 red, 2 green; 3 red, 7 green; 2 green, 15 red, 1 blue
|
||||
Game 94: 7 blue, 2 red, 2 green; 9 blue, 4 red, 2 green; 9 blue, 5 red, 3 green; 1 blue, 4 red, 3 green; 4 red, 1 green, 7 blue; 9 blue, 3 green, 3 red
|
||||
Game 95: 1 blue, 2 green, 2 red; 6 green, 6 red, 1 blue; 3 blue, 5 red, 2 green; 1 blue; 5 green, 2 red, 2 blue
|
||||
Game 96: 3 blue, 6 red, 5 green; 5 blue, 8 green, 9 red; 2 red, 5 green, 1 blue; 6 green, 4 blue, 3 red; 2 green, 2 blue; 6 blue, 4 green
|
||||
Game 97: 6 green, 8 blue, 5 red; 9 green, 6 blue; 3 green, 3 blue; 2 blue, 10 green, 4 red
|
||||
Game 98: 11 blue, 1 green, 9 red; 5 green, 1 blue, 6 red; 13 blue, 6 green, 10 red; 6 blue, 4 green, 9 red
|
||||
Game 99: 4 red, 3 green, 3 blue; 6 blue, 4 green, 11 red; 3 green, 15 red; 1 blue, 6 green, 14 red
|
||||
Game 100: 14 green, 6 blue, 12 red; 2 green, 1 blue, 2 red; 12 red, 7 blue, 3 green; 1 blue, 12 red, 8 green
|
|
@ -0,0 +1,76 @@
|
|||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <parse.h>
|
||||
|
||||
// 1957 is too low
|
||||
|
||||
// The amount of games expected
|
||||
const int games = 100;
|
||||
|
||||
// How many of each cube are allowed
|
||||
const int allowed_red = 12;
|
||||
const int allowed_green = 13;
|
||||
const int allowed_blue = 14;
|
||||
|
||||
// How many letter each color takes up
|
||||
const int chars_red = strlen("red");
|
||||
const int chars_green = strlen("green");
|
||||
const int chars_blue = strlen("blue");
|
||||
|
||||
// Pre-defined functions
|
||||
int game_score(char *text);
|
||||
|
||||
int main(void) {
|
||||
int sum = 0;
|
||||
|
||||
char *inputs[games];
|
||||
for (int i = 0; i < games; i++) {
|
||||
inputs[i] = get_string("");
|
||||
}
|
||||
|
||||
for (int i = 0; i < games; i++) {
|
||||
sum += game_score(inputs[i]);
|
||||
}
|
||||
|
||||
printf("%i\n", sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Determine a game's score.
|
||||
*/
|
||||
int game_score(char *text) {
|
||||
int value = 0;
|
||||
int game;
|
||||
int *cursor = &value;
|
||||
|
||||
parse_token(text, cursor, "Game ");
|
||||
parse_int(text, cursor, &game);
|
||||
parse_token(text, cursor, ":");
|
||||
|
||||
do
|
||||
{
|
||||
int number;
|
||||
|
||||
parse_token(text, cursor, " ");
|
||||
parse_int(text, cursor, &number);
|
||||
parse_token(text, cursor, " ");
|
||||
|
||||
if (parse_token(text, cursor, "red")) {
|
||||
if (number > allowed_red) {
|
||||
return 0;
|
||||
}
|
||||
} else if (parse_token(text, cursor, "green")) {
|
||||
if (number > allowed_green) {
|
||||
return 0;
|
||||
}
|
||||
} else if (parse_token(text, cursor, "blue")) {
|
||||
if (number > allowed_blue) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (parse_token(text, cursor, ";") || parse_token(text, cursor, ","));
|
||||
|
||||
return game;
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <parse.h>
|
||||
|
||||
// 1957 is too low
|
||||
|
||||
// The amount of games expected
|
||||
const int games = 100;
|
||||
|
||||
// How many of each cube are allowed
|
||||
const int allowed_red = 12;
|
||||
const int allowed_green = 13;
|
||||
const int allowed_blue = 14;
|
||||
|
||||
// How many letter each color takes up
|
||||
const int chars_red = strlen("red");
|
||||
const int chars_green = strlen("green");
|
||||
const int chars_blue = strlen("blue");
|
||||
|
||||
// Pre-defined functions
|
||||
int game_score(char *text);
|
||||
|
||||
int main(void) {
|
||||
int sum = 0;
|
||||
|
||||
char *inputs[games];
|
||||
for (int i = 0; i < games; i++) {
|
||||
inputs[i] = get_string("");
|
||||
}
|
||||
|
||||
for (int i = 0; i < games; i++) {
|
||||
sum += game_score(inputs[i]);
|
||||
}
|
||||
|
||||
printf("%i\n", sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Determine a game's score.
|
||||
*/
|
||||
int game_score(char *text) {
|
||||
int value = 0;
|
||||
int game;
|
||||
int *cursor = &value;
|
||||
int red = 0, green = 0, blue = 0;
|
||||
|
||||
parse_token(text, cursor, "Game ");
|
||||
parse_int(text, cursor, &game);
|
||||
parse_token(text, cursor, ":");
|
||||
|
||||
do
|
||||
{
|
||||
int number;
|
||||
|
||||
parse_token(text, cursor, " ");
|
||||
parse_int(text, cursor, &number);
|
||||
parse_token(text, cursor, " ");
|
||||
|
||||
if (parse_token(text, cursor, "red")) {
|
||||
if (number > red) {
|
||||
red = number;
|
||||
}
|
||||
} else if (parse_token(text, cursor, "green")) {
|
||||
if (number > green) {
|
||||
green = number;
|
||||
}
|
||||
} else if (parse_token(text, cursor, "blue")) {
|
||||
if (number > blue) {
|
||||
blue = number;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (parse_token(text, cursor, ";") || parse_token(text, cursor, ","));
|
||||
|
||||
return red * green * blue;
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/* This parsing library aims to imitate how Elm parses strings.
|
||||
|
||||
In contrast to Elm, however, this function makes use of the side-effects that
|
||||
C brings, allowing for impurity and a lack of need to return values.
|
||||
|
||||
Instead, every parser merely returns a boolean that expresses whether it had
|
||||
parsed successfully.
|
||||
*/
|
||||
|
||||
#include <parse.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
const bool DEBUG = false;
|
||||
|
||||
/* Parse a single char and fetch the result.
|
||||
*/
|
||||
bool parse_char(char *text, int *cursor, char *c) {
|
||||
int length = strlen(text);
|
||||
|
||||
if (DEBUG) printf("Parsing a char : ");
|
||||
|
||||
if (*cursor == length) {
|
||||
if (DEBUG) printf("Reached end of string [FAIL]\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
*c = text[*cursor];
|
||||
*cursor = *cursor + 1;
|
||||
if (DEBUG) printf("%c [Success]\n", *c);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Parse an integer.
|
||||
*/
|
||||
bool parse_int(char *text, int *cursor, int *output) {
|
||||
int is_negative = parse_token(text, cursor, "-");
|
||||
|
||||
if (DEBUG) printf("Parsing int : ");
|
||||
int answer = 0;
|
||||
char c = text[*cursor];
|
||||
|
||||
if (c < '0' || c > '9') {
|
||||
if (DEBUG) printf("%c [FAIL]\n", c);
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (DEBUG) printf("%c", c);
|
||||
answer = (answer * 10) + (c - '0');
|
||||
*cursor = *cursor + 1;
|
||||
c = text[*cursor];
|
||||
}
|
||||
while (c >= '0' && c <= '9');
|
||||
|
||||
if (DEBUG) printf(" [Success ]\n");
|
||||
|
||||
if (is_negative) {
|
||||
answer = -1 * answer;
|
||||
}
|
||||
|
||||
*output = answer;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Parse a token of text.
|
||||
*/
|
||||
bool parse_token(char *text, int *cursor, char *token) {
|
||||
int length = strlen(token), text_length = strlen(text);
|
||||
if (DEBUG) printf("Parsing token \"%s\" : ", token);
|
||||
|
||||
if (text_length - *cursor < length) {
|
||||
if (DEBUG) printf("Token too long, won't fit. [FAIL]\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (DEBUG) printf("%c", text[*cursor + i]);
|
||||
if (text[*cursor + i] != token[i]) {
|
||||
if (DEBUG) printf(" [FAIL]\n");
|
||||
*cursor = *cursor + i;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) printf(" [Success]\n");
|
||||
*cursor = *cursor + length;
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/* This parsing library aims to imitate how Elm parses strings.
|
||||
|
||||
In contrast to Elm, however, this function makes use of the side-effects that
|
||||
C brings, allowing for impurity and a lack of need to return values.
|
||||
|
||||
Instead, every parser merely returns a boolean that expresses whether it had
|
||||
parsed successfully.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Parse a single char and fetch the result.
|
||||
*/
|
||||
bool parse_char(char *text, int *cursor, char *c);
|
||||
|
||||
/* Parse an integer.
|
||||
*/
|
||||
bool parse_int(char *text, int *cursor, int *output);
|
||||
|
||||
/* Parse a token of text.
|
||||
*/
|
||||
bool parse_token(char *text, int *cursor, char *token);
|
|
@ -0,0 +1,13 @@
|
|||
{ pkgs ? import <nixpkgs> {}
|
||||
}:
|
||||
pkgs.mkShell {
|
||||
name="dev-environment";
|
||||
buildInputs = [
|
||||
pkgs.libgcc
|
||||
pkgs.libcs50
|
||||
pkgs.valgrind
|
||||
];
|
||||
shellHook = ''
|
||||
echo "Start developing! :D"
|
||||
'';
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"Orasund/elm-ui-widgets": "3.4.0",
|
||||
"avh4/elm-color": "1.0.0",
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/parser": "1.1.0",
|
||||
"elm/svg": "1.0.1",
|
||||
"mdgriffith/elm-ui": "1.1.8",
|
||||
"miniBill/elm-fast-dict": "1.1.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/json": "1.1.3",
|
||||
"elm/regex": "1.0.0",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.3",
|
||||
"elm-community/intdict": "3.0.0",
|
||||
"fredcy/elm-parseint": "2.0.1",
|
||||
"noahzgordon/elm-color-extra": "1.0.2",
|
||||
"turboMaCk/queue": "1.1.0"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,330 @@
|
|||
module Main exposing (main)
|
||||
|
||||
import Browser
|
||||
import Element
|
||||
import Element.Background
|
||||
import Element.Input
|
||||
import Puzzles.Day1 as Day1
|
||||
import Puzzles.Day2 as Day2
|
||||
import Task
|
||||
import Tools.Colors as C
|
||||
import Widget
|
||||
import Widget.Customize
|
||||
import Widget.Material as Material
|
||||
import Widget.Material.Typography as Typography
|
||||
|
||||
|
||||
main : Program () Model Msg
|
||||
main =
|
||||
Browser.document
|
||||
{ init = init
|
||||
, view = view
|
||||
, update = update
|
||||
, subscriptions = subscriptions
|
||||
}
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ view : Window
|
||||
, input : String
|
||||
, output1 : Calculating
|
||||
, output2 : Calculating
|
||||
}
|
||||
|
||||
|
||||
type Calculating
|
||||
= Outcome String
|
||||
| Calculating
|
||||
| InvalidInput String
|
||||
| NoInput
|
||||
|
||||
|
||||
type Window
|
||||
= Home
|
||||
| Day Int
|
||||
|
||||
|
||||
type alias Puzzle =
|
||||
String -> Result String String
|
||||
|
||||
|
||||
getFunctions : Window -> ( Puzzle, Puzzle )
|
||||
getFunctions window =
|
||||
case window of
|
||||
Home ->
|
||||
( always <| Err "There is no puzzle for this page!"
|
||||
, always <| Err "There is no puzzle for this page!"
|
||||
)
|
||||
|
||||
Day 1 ->
|
||||
( Day1.puzzle1, Day1.puzzle2 )
|
||||
|
||||
Day 2 ->
|
||||
( Day2.puzzle1, Day2.puzzle2 )
|
||||
|
||||
_ ->
|
||||
( always <| Err "This puzzle has no implementation yet!"
|
||||
, always <| Err "This puzzle has no implementation yet!"
|
||||
)
|
||||
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init () =
|
||||
( { view = Home
|
||||
, input = ""
|
||||
, output1 = NoInput
|
||||
, output2 = NoInput
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
type Msg
|
||||
= ChangeWindow Window
|
||||
| OnInput String
|
||||
| DoNothing
|
||||
| Calculate1 Window (Result String String)
|
||||
| Calculate2 Window (Result String String)
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
ChangeWindow window ->
|
||||
( { view = window
|
||||
, input = ""
|
||||
, output1 = NoInput
|
||||
, output2 = NoInput
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
OnInput input ->
|
||||
( { model
|
||||
| input = input
|
||||
, output1 = Calculating
|
||||
, output2 = Calculating
|
||||
}
|
||||
, if input == model.input then
|
||||
Cmd.none
|
||||
|
||||
else
|
||||
Cmd.batch
|
||||
[ Task.succeed input
|
||||
|> Task.map (getFunctions model.view |> Tuple.first)
|
||||
|> Task.perform (Calculate1 model.view)
|
||||
, Task.succeed input
|
||||
|> Task.map (getFunctions model.view |> Tuple.second)
|
||||
|> Task.perform (Calculate2 model.view)
|
||||
]
|
||||
)
|
||||
|
||||
DoNothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
Calculate1 w (Ok s) ->
|
||||
if w /= model.view then
|
||||
( model, Cmd.none )
|
||||
|
||||
else
|
||||
( { model | output1 = Outcome s }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
Calculate1 w (Err s) ->
|
||||
if w /= model.view then
|
||||
( model, Cmd.none )
|
||||
|
||||
else
|
||||
( { model | output1 = InvalidInput s }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
Calculate2 w (Ok s) ->
|
||||
if w /= model.view then
|
||||
( model, Cmd.none )
|
||||
|
||||
else
|
||||
( { model | output2 = Outcome s }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
Calculate2 w (Err s) ->
|
||||
if w /= model.view then
|
||||
( model, Cmd.none )
|
||||
|
||||
else
|
||||
( { model | output2 = InvalidInput s }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions model =
|
||||
Sub.none
|
||||
|
||||
|
||||
view : Model -> Browser.Document Msg
|
||||
view model =
|
||||
{ title = "Document Title"
|
||||
, body =
|
||||
[ Widget.menuBar
|
||||
(Material.menuBar palette)
|
||||
{ title =
|
||||
"aoc2023"
|
||||
|> Element.text
|
||||
|> Element.el Typography.h3
|
||||
, deviceClass =
|
||||
Element.Desktop
|
||||
, openLeftSheet = Nothing
|
||||
, openRightSheet = Nothing
|
||||
, openTopSheet = Nothing
|
||||
, primaryActions = []
|
||||
, search = Nothing
|
||||
}
|
||||
, Element.row [ Element.height Element.fill, Element.width Element.fill ]
|
||||
[ Element.el
|
||||
[ Element.fill
|
||||
|> Element.maximum 200
|
||||
|> Element.width
|
||||
, Element.alignTop
|
||||
]
|
||||
(List.map
|
||||
(\( window, text ) ->
|
||||
Widget.fullBleedItem
|
||||
(Material.fullBleedItem palette)
|
||||
{ text = text
|
||||
, onPress = Just (ChangeWindow window)
|
||||
, icon = always Element.none
|
||||
}
|
||||
)
|
||||
[ ( Home, "Home" )
|
||||
, ( Day 1, "Day 1" )
|
||||
, ( Day 2, "Day 2" )
|
||||
, ( Day 3, "Day 3" )
|
||||
]
|
||||
|> Widget.itemList Material.column
|
||||
)
|
||||
, Element.column
|
||||
[ Element.height Element.fill
|
||||
, Element.width Element.fill
|
||||
, C.background (picker C.Dark C.White)
|
||||
, Element.padding 20
|
||||
, Element.spacing 20
|
||||
]
|
||||
(case model.view of
|
||||
Home ->
|
||||
[ "Advent of Code 2023"
|
||||
|> Element.text
|
||||
|> Element.el Typography.h3
|
||||
]
|
||||
|
||||
Day i ->
|
||||
[ [ "Using the following input for day "
|
||||
++ String.fromInt i
|
||||
++ ": "
|
||||
|> Element.text
|
||||
, Element.Input.multiline
|
||||
[ Element.fill
|
||||
|> Element.maximum 500
|
||||
|> Element.height
|
||||
, Element.scrollbarX
|
||||
]
|
||||
{ onChange = OnInput
|
||||
, text = model.input
|
||||
, placeholder =
|
||||
"Insert puzzle input here..."
|
||||
|> Element.text
|
||||
|> Element.Input.placeholder []
|
||||
|> Just
|
||||
, label = Element.Input.labelHidden "input"
|
||||
, spellcheck = False
|
||||
}
|
||||
]
|
||||
, case model.output1 of
|
||||
Outcome s ->
|
||||
[ "Part 1 answer:"
|
||||
|> Element.text
|
||||
, Element.Input.multiline
|
||||
[ Element.width Element.fill ]
|
||||
{ onChange = always DoNothing
|
||||
, text = s
|
||||
, placeholder = Nothing
|
||||
, label = Element.Input.labelHidden "answer-1"
|
||||
, spellcheck = False
|
||||
}
|
||||
]
|
||||
|
||||
Calculating ->
|
||||
[ "Calculating part 1..."
|
||||
|> Element.text
|
||||
]
|
||||
|
||||
InvalidInput s ->
|
||||
[ "INVALID INPUT FOR PART 1"
|
||||
|> Element.text
|
||||
, Element.Input.multiline
|
||||
[ Element.width Element.fill ]
|
||||
{ onChange = always DoNothing
|
||||
, text = s
|
||||
, placeholder = Nothing
|
||||
, label = Element.Input.labelHidden "answer-1"
|
||||
, spellcheck = False
|
||||
}
|
||||
]
|
||||
|
||||
NoInput ->
|
||||
List.singleton Element.none
|
||||
, case model.output2 of
|
||||
Outcome s ->
|
||||
[ "Part 2 answer:"
|
||||
|> Element.text
|
||||
, Element.Input.multiline
|
||||
[ Element.width Element.fill ]
|
||||
{ onChange = always DoNothing
|
||||
, text = s
|
||||
, placeholder = Nothing
|
||||
, label = Element.Input.labelHidden "answer-2"
|
||||
, spellcheck = False
|
||||
}
|
||||
]
|
||||
|
||||
Calculating ->
|
||||
[ "Calculating part 2..."
|
||||
|> Element.text
|
||||
]
|
||||
|
||||
InvalidInput s ->
|
||||
[ "INVALID INPUT FOR PART 2"
|
||||
|> Element.text
|
||||
, Element.Input.multiline
|
||||
[ Element.width Element.fill ]
|
||||
{ onChange = always DoNothing
|
||||
, text = s
|
||||
, placeholder = Nothing
|
||||
, label = Element.Input.labelHidden "answer-2"
|
||||
, spellcheck = False
|
||||
}
|
||||
]
|
||||
|
||||
NoInput ->
|
||||
List.singleton Element.none
|
||||
]
|
||||
|> List.concat
|
||||
)
|
||||
]
|
||||
]
|
||||
|> Element.column [ Element.width Element.fill, Element.height Element.fill ]
|
||||
|> Element.layout [ Element.height Element.fill ]
|
||||
|> List.singleton
|
||||
}
|
||||
|
||||
|
||||
picker : C.Picker
|
||||
picker =
|
||||
C.get C.Trichromatic C.LightMode
|
||||
|
||||
|
||||
palette : Material.Palette
|
||||
palette =
|
||||
C.defaultPalette picker
|
|
@ -0,0 +1,64 @@
|
|||
module Puzzles.Day1 exposing (puzzle1, puzzle2)
|
||||
|
||||
|
||||
puzzle1 : String -> Result String String
|
||||
puzzle1 input =
|
||||
input
|
||||
|> String.split "\n"
|
||||
|> List.map puzzle1Nums
|
||||
|> List.indexedMap
|
||||
(\i items ->
|
||||
case items of
|
||||
head :: tail ->
|
||||
Ok (calibrationValue head tail)
|
||||
|
||||
[] ->
|
||||
Err i
|
||||
)
|
||||
|> List.foldl
|
||||
(\value sum ->
|
||||
case ( value, sum ) of
|
||||
( _, Err _ ) ->
|
||||
sum
|
||||
|
||||
( Err i, Ok _ ) ->
|
||||
Err ("Line" ++ (String.fromInt <| i + 1) ++ "does not contain any numbers")
|
||||
|
||||
( Ok a, Ok b ) ->
|
||||
Ok (a + b)
|
||||
)
|
||||
(Ok 0)
|
||||
|> Result.map String.fromInt
|
||||
|
||||
|
||||
puzzle1Nums : String -> List Int
|
||||
puzzle1Nums s =
|
||||
s
|
||||
|> String.toList
|
||||
|> List.map String.fromChar
|
||||
|> List.filterMap String.toInt
|
||||
|
||||
|
||||
calibrationValue : Int -> List Int -> Int
|
||||
calibrationValue head tail =
|
||||
tail
|
||||
|> List.reverse
|
||||
|> List.head
|
||||
|> Maybe.withDefault head
|
||||
|> (+) (head * 10)
|
||||
|
||||
|
||||
puzzle2 : String -> Result String String
|
||||
puzzle2 input =
|
||||
input
|
||||
|> String.replace "zero" "z0ero"
|
||||
|> String.replace "one" "o1ne"
|
||||
|> String.replace "two" "t2wo"
|
||||
|> String.replace "three" "t3hree"
|
||||
|> String.replace "four" "f4our"
|
||||
|> String.replace "five" "f5ive"
|
||||
|> String.replace "six" "s6ix"
|
||||
|> String.replace "seven" "s7even"
|
||||
|> String.replace "eight" "e8ight"
|
||||
|> String.replace "nine" "n9ine"
|
||||
|> puzzle1
|
|
@ -0,0 +1,150 @@
|
|||
module Puzzles.Day2 exposing (puzzle1, puzzle2)
|
||||
|
||||
import Parser as P exposing ((|.), (|=), Parser)
|
||||
|
||||
|
||||
type alias Game =
|
||||
{ number : Int, games : List RGB }
|
||||
|
||||
|
||||
type alias RGB =
|
||||
{ red : Int, green : Int, blue : Int }
|
||||
|
||||
|
||||
maxAllowed : RGB
|
||||
maxAllowed =
|
||||
{ red = 12, green = 13, blue = 14 }
|
||||
|
||||
|
||||
puzzle1 : String -> Result String String
|
||||
puzzle1 input =
|
||||
case P.run parser input of
|
||||
Err a ->
|
||||
Debug.log "Output" a
|
||||
|> always (Err "Invalid input")
|
||||
|
||||
Ok g ->
|
||||
g
|
||||
|> List.map
|
||||
(\{ number, games } ->
|
||||
let
|
||||
isLegal : Bool
|
||||
isLegal =
|
||||
List.all
|
||||
(\rgb ->
|
||||
List.all
|
||||
(\f -> f rgb <= f maxAllowed)
|
||||
[ .red, .green, .blue ]
|
||||
)
|
||||
games
|
||||
in
|
||||
if isLegal then
|
||||
number
|
||||
|
||||
else
|
||||
0
|
||||
)
|
||||
|> List.sum
|
||||
|> String.fromInt
|
||||
|> Ok
|
||||
|
||||
|
||||
puzzle2 : String -> Result String String
|
||||
puzzle2 input =
|
||||
case P.run parser input of
|
||||
Err a ->
|
||||
Debug.log "Output" a
|
||||
|> always (Err "Invalid input")
|
||||
|
||||
-- 179502 too high
|
||||
Ok g ->
|
||||
g
|
||||
|> List.map
|
||||
(\{ games } ->
|
||||
let
|
||||
getMaximumFor : (RGB -> Int) -> Int
|
||||
getMaximumFor f =
|
||||
games
|
||||
|> List.map f
|
||||
|> List.maximum
|
||||
|> Maybe.withDefault 0
|
||||
in
|
||||
[ .red, .green, .blue ]
|
||||
|> List.map getMaximumFor
|
||||
|> List.product
|
||||
)
|
||||
|> List.sum
|
||||
|> String.fromInt
|
||||
|> Ok
|
||||
|
||||
|
||||
parser : Parser (List Game)
|
||||
parser =
|
||||
andOneMore
|
||||
{ separator = "\n"
|
||||
, item = gameParser
|
||||
}
|
||||
|
||||
|
||||
gameParser : Parser Game
|
||||
gameParser =
|
||||
P.succeed Game
|
||||
|. P.keyword "Game"
|
||||
|. P.spaces
|
||||
|= P.int
|
||||
|. P.symbol ":"
|
||||
|. P.spaces
|
||||
|= rgbLines
|
||||
|
||||
|
||||
rgbLines : Parser (List RGB)
|
||||
rgbLines =
|
||||
andOneMore
|
||||
{ separator = ";"
|
||||
, item = rgbParser
|
||||
}
|
||||
|
||||
|
||||
rgbParser : Parser RGB
|
||||
rgbParser =
|
||||
P.succeed (List.foldl (<|) (RGB 0 0 0))
|
||||
|= andOneMore
|
||||
{ separator = ","
|
||||
, item = rgbStmt
|
||||
}
|
||||
|
||||
|
||||
rgbStmt : Parser (RGB -> RGB)
|
||||
rgbStmt =
|
||||
P.succeed (|>)
|
||||
|= P.int
|
||||
|. P.spaces
|
||||
|= P.oneOf
|
||||
[ P.succeed (\i rgb -> { rgb | red = i })
|
||||
|. P.keyword "red"
|
||||
, P.succeed (\i rgb -> { rgb | blue = i })
|
||||
|. P.keyword "blue"
|
||||
, P.succeed (\i rgb -> { rgb | green = i })
|
||||
|. P.keyword "green"
|
||||
]
|
||||
|
||||
|
||||
andOneMore : { separator : String, item : Parser a } -> Parser (List a)
|
||||
andOneMore { separator, item } =
|
||||
P.loop []
|
||||
(\xs ->
|
||||
P.succeed (\x state -> state (x :: xs))
|
||||
|= item
|
||||
|. onlySpaces
|
||||
|= P.oneOf
|
||||
[ P.succeed P.Loop
|
||||
|. P.token separator
|
||||
, P.succeed P.Done
|
||||
]
|
||||
|. onlySpaces
|
||||
)
|
||||
|
||||
|
||||
onlySpaces : Parser ()
|
||||
onlySpaces =
|
||||
P.chompWhile (\c -> c == ' ')
|
|
@ -0,0 +1,11 @@
|
|||
module Puzzles.DayX exposing (puzzle1, puzzle2)
|
||||
|
||||
|
||||
puzzle1 : String -> Result String String
|
||||
puzzle1 _ =
|
||||
Err "Not implemented yet!"
|
||||
|
||||
|
||||
puzzle2 : String -> Result String String
|
||||
puzzle2 _ =
|
||||
Err "Not implemented yet!"
|
|
@ -0,0 +1,563 @@
|
|||
module Tools.Colors exposing (..)
|
||||
|
||||
{-| This module aims to create color palettes that fit the Noordstar color scheme.
|
||||
-}
|
||||
|
||||
import Color exposing (rgb255)
|
||||
import Element
|
||||
import Element.Background
|
||||
import Element.Font
|
||||
import Svg
|
||||
import Svg.Attributes exposing (fill)
|
||||
import Widget.Material exposing (Palette)
|
||||
|
||||
|
||||
type alias Color =
|
||||
Color.Color
|
||||
|
||||
|
||||
type Name
|
||||
= Primary
|
||||
| Secondary
|
||||
| Tertiary
|
||||
| Quaternary
|
||||
| Extra
|
||||
| Black
|
||||
| White
|
||||
|
||||
|
||||
type Shade
|
||||
= Light
|
||||
| Medium
|
||||
| Dark
|
||||
|
||||
|
||||
{-| Based on the user's preferences, the website can be displayed in light mode or dark mode.
|
||||
-}
|
||||
type Mode
|
||||
= LightMode
|
||||
| DarkMode
|
||||
|
||||
|
||||
{-| The website supports color blindness friendly color palettes.
|
||||
This way, everyone can enjoy the website's graphs without having to distinguish
|
||||
colors that they cannot distinguish.
|
||||
-}
|
||||
type Blindness
|
||||
= Trichromatic -- ALL THREE
|
||||
| Protanomaly -- BARELY RED
|
||||
| Deuteranomaly -- BARELY GREEN
|
||||
| Tritanomaly -- BARELY BLUE
|
||||
| Protanopia -- NO RED
|
||||
| Deuteranopia -- NO GREEN
|
||||
| Tritanopia -- NO BLUE
|
||||
| Monochromacy -- NO COLOR
|
||||
| BlueConeMonochromacy -- BARELY COLOR
|
||||
|
||||
|
||||
type alias Picker =
|
||||
Shade -> Name -> Color
|
||||
|
||||
|
||||
{-| Get a color based on the right criteria.
|
||||
-}
|
||||
get : Blindness -> Mode -> Shade -> Name -> Color
|
||||
get blindness mode shade name =
|
||||
let
|
||||
trueName : Name
|
||||
trueName =
|
||||
name |> flipName mode
|
||||
|
||||
trueShade : Shade
|
||||
trueShade =
|
||||
shade |> flipShade mode
|
||||
in
|
||||
toBlindnessPalette blindness
|
||||
|> toColor blindness trueName
|
||||
|> fromShade trueShade
|
||||
|> (\( r, g, b ) -> rgb255 r g b)
|
||||
|
||||
|
||||
defaultPalette : Picker -> Palette
|
||||
defaultPalette p =
|
||||
{ primary = p Medium Primary
|
||||
, secondary = p Medium Secondary
|
||||
, background = p Dark White
|
||||
, surface = p Light White
|
||||
, error = p Light Secondary
|
||||
, on =
|
||||
{ primary = p Light White
|
||||
, secondary = p Light White
|
||||
, background = p Light Black
|
||||
, surface = p Dark Black
|
||||
, error = p Medium White
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{-| Get a blindness color palette based on a blindness input.
|
||||
-}
|
||||
toBlindnessPalette : Blindness -> BlindnessPalette
|
||||
toBlindnessPalette blindness =
|
||||
case blindness of
|
||||
Trichromatic ->
|
||||
trichromatic
|
||||
|
||||
Protanomaly ->
|
||||
protanomaly
|
||||
|
||||
Deuteranomaly ->
|
||||
deuteranomaly
|
||||
|
||||
Tritanomaly ->
|
||||
tritanomaly
|
||||
|
||||
Protanopia ->
|
||||
protanopia
|
||||
|
||||
Deuteranopia ->
|
||||
deuteranopia
|
||||
|
||||
Tritanopia ->
|
||||
tritanopia
|
||||
|
||||
Monochromacy ->
|
||||
monochromacy
|
||||
|
||||
BlueConeMonochromacy ->
|
||||
blueConeMonochromacy
|
||||
|
||||
|
||||
flipName : Mode -> Name -> Name
|
||||
flipName mode name =
|
||||
case mode of
|
||||
LightMode ->
|
||||
name
|
||||
|
||||
DarkMode ->
|
||||
case name of
|
||||
Black ->
|
||||
White
|
||||
|
||||
White ->
|
||||
Black
|
||||
|
||||
_ ->
|
||||
name
|
||||
|
||||
|
||||
flipShade : Mode -> Shade -> Shade
|
||||
flipShade mode shade =
|
||||
case ( mode, shade ) of
|
||||
( LightMode, _ ) ->
|
||||
shade
|
||||
|
||||
( DarkMode, Dark ) ->
|
||||
Light
|
||||
|
||||
( DarkMode, Medium ) ->
|
||||
Medium
|
||||
|
||||
( DarkMode, Light ) ->
|
||||
Dark
|
||||
|
||||
|
||||
{-| We distringuish the following colours:
|
||||
|
||||
| Protan | Deuter | Tritan | Mono |
|
||||
|
||||
- Blue | Blue | Blue | Blue | Blue |
|
||||
- Green | Green | Green | Green | XXXXXX | [Orange]
|
||||
- Yellow | Yellow | Yellow | XXXXXX | Yellow | [Orange]
|
||||
- Orange | XXXXXX | XXXXXX | Orange | Orange | [Green,Red]
|
||||
- Red | Red | Red | Red | Red |
|
||||
- Black | Black | Black | Black | Black |
|
||||
- White | White | White | White | White |
|
||||
|
||||
In other words:
|
||||
|
||||
Primary | Blue | Blue | Blue | Blue |
|
||||
Secondary | Red | Red | Red | Red |
|
||||
Tertiary | Yellow | Yellow | Orange | Yellow |
|
||||
Quaternary | Green | Green | Green | Orange |
|
||||
-----------|--------|--------|--------|--------|
|
||||
Rest | Orange | Orange | Yellow | Green |
|
||||
|
||||
-}
|
||||
toColor : Blindness -> Name -> (BlindnessPalette -> ColorPalette)
|
||||
toColor blindness name =
|
||||
case name of
|
||||
Primary ->
|
||||
.blue
|
||||
|
||||
Secondary ->
|
||||
.red
|
||||
|
||||
Tertiary ->
|
||||
case blindness of
|
||||
Tritanopia ->
|
||||
.orange
|
||||
|
||||
_ ->
|
||||
.yellow
|
||||
|
||||
Quaternary ->
|
||||
case blindness of
|
||||
Monochromacy ->
|
||||
.orange
|
||||
|
||||
_ ->
|
||||
.green
|
||||
|
||||
Extra ->
|
||||
case blindness of
|
||||
Tritanopia ->
|
||||
.yellow
|
||||
|
||||
Monochromacy ->
|
||||
.green
|
||||
|
||||
_ ->
|
||||
.orange
|
||||
|
||||
Black ->
|
||||
.black
|
||||
|
||||
White ->
|
||||
.white
|
||||
|
||||
|
||||
fromShade : Shade -> ColorPalette -> ( Int, Int, Int )
|
||||
fromShade shade =
|
||||
case shade of
|
||||
Light ->
|
||||
.light
|
||||
|
||||
Medium ->
|
||||
.medium
|
||||
|
||||
Dark ->
|
||||
.dark
|
||||
|
||||
|
||||
type alias ColorPalette =
|
||||
{ light : ( Int, Int, Int )
|
||||
, medium : ( Int, Int, Int )
|
||||
, dark : ( Int, Int, Int )
|
||||
}
|
||||
|
||||
|
||||
type alias BlindnessPalette =
|
||||
{ blue : ColorPalette
|
||||
, green : ColorPalette
|
||||
, yellow : ColorPalette
|
||||
, orange : ColorPalette
|
||||
, red : ColorPalette
|
||||
, black : ColorPalette
|
||||
, white : ColorPalette
|
||||
}
|
||||
|
||||
|
||||
{-| No color blindness
|
||||
-}
|
||||
trichromatic : BlindnessPalette
|
||||
trichromatic =
|
||||
{ blue = { light = ( 0x42, 0x87, 0xFF ), medium = ( 0x42, 0x7F, 0xF0 ), dark = ( 0x00, 0x54, 0xBD ) }
|
||||
, green = { light = ( 0x86, 0xEA, 0xD1 ), medium = ( 0x5E, 0xA4, 0x93 ), dark = ( 0x3E, 0x6D, 0x62 ) }
|
||||
, yellow = { light = ( 0xFC, 0xF9, 0x2B ), medium = ( 0xD2, 0xD0, 0x24 ), dark = ( 0xAF, 0xAD, 0x1E ) }
|
||||
, orange = { light = ( 0xFF, 0xBB, 0x93 ), medium = ( 0xCC, 0x95, 0x75 ), dark = ( 0xA3, 0x77, 0x5E ) }
|
||||
, red = { light = ( 0xDC, 0x00, 0x00 ), medium = ( 0xB0, 0x00, 0x00 ), dark = ( 0x8C, 0x00, 0x00 ) }
|
||||
, black = { light = ( 0x2C, 0x2C, 0x48 ), medium = ( 0x1D, 0x1D, 0x30 ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFE, 0xFA, 0xF5 ), dark = ( 0xF2, 0xEF, 0xEA ) }
|
||||
}
|
||||
|
||||
|
||||
{-| Weak red vision
|
||||
-}
|
||||
protanomaly : BlindnessPalette
|
||||
protanomaly =
|
||||
{ blue = { light = ( 0x49, 0x86, 0xFE ), medium = ( 0x46, 0x7E, 0xEF ), dark = ( 0x00, 0x55, 0xB9 ) }
|
||||
, green = { light = ( 0xBE, 0xDD, 0xCA ), medium = ( 0x85, 0x9B, 0x8E ), dark = ( 0x58, 0x67, 0x5F ) }
|
||||
, yellow = { light = ( 0xFE, 0xF4, 0x88 ), medium = ( 0xDD, 0xCC, 0x23 ), dark = ( 0xB8, 0xAA, 0x1D ) }
|
||||
, orange = { light = ( 0xE6, 0xC4, 0x97 ), medium = ( 0xB8, 0x9D, 0x78 ), dark = ( 0x93, 0x7D, 0x61 ) }
|
||||
, red = { light = ( 0x9F, 0x47, 0x12 ), medium = ( 0x7F, 0x39, 0x0F ), dark = ( 0x65, 0x2D, 0x0C ) }
|
||||
, black = { light = ( 0x27, 0x2D, 0x49 ), medium = ( 0x1A, 0x1E, 0x31 ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFF, 0xFA, 0xF6 ), dark = ( 0xF4, 0xEE, 0xEA ) }
|
||||
}
|
||||
|
||||
|
||||
{-| Weak green vision
|
||||
-}
|
||||
deuteranomaly : BlindnessPalette
|
||||
deuteranomaly =
|
||||
{ blue = { light = ( 0x18, 0x8A, 0xFA ), medium = ( 0x18, 0x82, 0xEC ), dark = ( 0x00, 0x59, 0xA9 ) }
|
||||
, green = { light = ( 0xC6, 0xD9, 0xD5 ), medium = ( 0x8B, 0x98, 0x95 ), dark = ( 0x5C, 0x65, 0x64 ) }
|
||||
, yellow = { light = ( 0xFE, 0xF3, 0x9C ), medium = ( 0xEE, 0xC5, 0x2B ), dark = ( 0xC6, 0xA4, 0x23 ) }
|
||||
, orange = { light = ( 0xF5, 0xBF, 0x92 ), medium = ( 0xC4, 0x99, 0x74 ), dark = ( 0x9D, 0x7A, 0x5D ) }
|
||||
, red = { light = ( 0xA9, 0x43, 0x00 ), medium = ( 0x87, 0x36, 0x00 ), dark = ( 0x6C, 0x2B, 0x00 ) }
|
||||
, black = { light = ( 0x26, 0x2E, 0x48 ), medium = ( 0x19, 0x1E, 0x30 ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFE, 0xFA, 0xF5 ), dark = ( 0xFA, 0xEC, 0xEC ) }
|
||||
}
|
||||
|
||||
|
||||
{-| Weak blue vision
|
||||
-}
|
||||
tritanomaly : BlindnessPalette
|
||||
tritanomaly =
|
||||
{ blue = { light = ( 0x18, 0x93, 0xC5 ), medium = ( 0x18, 0x8A, 0xBA ), dark = ( 0x00, 0x5E, 0x88 ) }
|
||||
, green = { light = ( 0x8C, 0xE7, 0xE9 ), medium = ( 0x62, 0xA2, 0xA4 ), dark = ( 0x41, 0x6B, 0x6D ) }
|
||||
, yellow = { light = ( 0xFE, 0xF1, 0xAC ), medium = ( 0xDA, 0xC7, 0x92 ), dark = ( 0xB6, 0xA5, 0x79 ) }
|
||||
, orange = { light = ( 0xFF, 0xB8, 0xB2 ), medium = ( 0xCE, 0x92, 0x8D ), dark = ( 0xA5, 0x74, 0x71 ) }
|
||||
, red = { light = ( 0xDB, 0x0D, 0x00 ), medium = ( 0xAF, 0x0A, 0x00 ), dark = ( 0x8B, 0x08, 0x00 ) }
|
||||
, black = { light = ( 0x29, 0x2F, 0x3B ), medium = ( 0x1B, 0x1F, 0x27 ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFD, 0xFA, 0xFB ), dark = ( 0xF4, 0xED, 0xF7 ) }
|
||||
}
|
||||
|
||||
|
||||
{-| Red-blind vision
|
||||
-}
|
||||
protanopia : BlindnessPalette
|
||||
protanopia =
|
||||
{ blue = { light = ( 0x4D, 0x86, 0xFE ), medium = ( 0x48, 0x7E, 0xEF ), dark = ( 0x00, 0x56, 0xB6 ) }
|
||||
, green = { light = ( 0xDE, 0xD6, 0xC6 ), medium = ( 0x9C, 0x96, 0x8B ), dark = ( 0x67, 0x64, 0x5D ) }
|
||||
, yellow = { light = ( 0xFF, 0xF2, 0xBE ), medium = ( 0xE3, 0xCA, 0x22 ), dark = ( 0xBD, 0xA8, 0x1D ) }
|
||||
, orange = { light = ( 0xD8, 0xCA, 0x9A ), medium = ( 0xAD, 0xA1, 0x7A ), dark = ( 0x8A, 0x81, 0x62 ) }
|
||||
, red = { light = ( 0x7D, 0x6F, 0x1C ), medium = ( 0x64, 0x59, 0x17 ), dark = ( 0x4F, 0x47, 0x12 ) }
|
||||
, black = { light = ( 0x24, 0x2E, 0x4A ), medium = ( 0x18, 0x1E, 0x31 ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFF, 0xFA, 0xF6 ), dark = ( 0xF5, 0xEE, 0xEA ) }
|
||||
}
|
||||
|
||||
|
||||
{-| Green-blind vision
|
||||
-}
|
||||
deuteranopia : BlindnessPalette
|
||||
deuteranopia =
|
||||
{ blue = { light = ( 0x00, 0x8C, 0xF8 ), medium = ( 0x00, 0x84, 0xEA ), dark = ( 0x00, 0x5B, 0x9D ) }
|
||||
, green = { light = ( 0xEB, 0xD0, 0xD7 ), medium = ( 0xA5, 0x92, 0x97 ), dark = ( 0x6D, 0x61, 0x65 ) }
|
||||
, yellow = { light = ( 0xFF, 0xEF, 0xDC ), medium = ( 0xFE, 0xBF, 0x2E ), dark = ( 0xD3, 0x9F, 0x26 ) }
|
||||
, orange = { light = ( 0xF0, 0xC2, 0x92 ), medium = ( 0xBF, 0x9B, 0x74 ), dark = ( 0x99, 0x7B, 0x5D ) }
|
||||
, red = { light = ( 0x8C, 0x69, 0x00 ), medium = ( 0x70, 0x54, 0x00 ), dark = ( 0x59, 0x43, 0x00 ) }
|
||||
, black = { light = ( 0x23, 0x2F, 0x47 ), medium = ( 0x16, 0x1F, 0x30 ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFF, 0xF9, 0xFA ), dark = ( 0xFF, 0xEA, 0xED ) }
|
||||
}
|
||||
|
||||
|
||||
{-| Blue-blind vision
|
||||
-}
|
||||
tritanopia : BlindnessPalette
|
||||
tritanopia =
|
||||
{ blue = { light = ( 0x00, 0x99, 0xA4 ), medium = ( 0x00, 0x90, 0x9B ), dark = ( 0x00, 0x63, 0x69 ) }
|
||||
, green = { light = ( 0x90, 0xE5, 0xF7 ), medium = ( 0x65, 0xA0, 0xAD ), dark = ( 0x43, 0x6B, 0x73 ) }
|
||||
, yellow = { light = ( 0xFF, 0xED, 0xF6 ), medium = ( 0xDF, 0xC2, 0xD1 ), dark = ( 0xBA, 0xA1, 0xAE ) }
|
||||
, orange = { light = ( 0xFF, 0xB7, 0xC3 ), medium = ( 0xCF, 0x90, 0x9B ), dark = ( 0xA6, 0x73, 0x7C ) }
|
||||
, red = { light = ( 0xDA, 0x14, 0x00 ), medium = ( 0xAF, 0x10, 0x00 ), dark = ( 0x8B, 0x0D, 0x00 ) }
|
||||
, black = { light = ( 0x27, 0x30, 0x34 ), medium = ( 0x1A, 0x20, 0x22 ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFC, 0xFA, 0xFF ), dark = ( 0xF5, 0xEC, 0xFE ) }
|
||||
}
|
||||
|
||||
|
||||
{-| Color-less vision
|
||||
-}
|
||||
monochromacy : BlindnessPalette
|
||||
monochromacy =
|
||||
{ blue = { light = ( 0x80, 0x80, 0x80 ), medium = ( 0x7A, 0x7A, 0x7A ), dark = ( 0x47, 0x47, 0x47 ) }
|
||||
, green = { light = ( 0xC9, 0xC9, 0xC9 ), medium = ( 0x8D, 0x8D, 0x8D ), dark = ( 0x5E, 0x5E, 0x5E ) }
|
||||
, yellow = { light = ( 0xE2, 0xE2, 0xE2 ), medium = ( 0xBD, 0xBD, 0xBD ), dark = ( 0x9D, 0x9D, 0x9D ) }
|
||||
, orange = { light = ( 0xCB, 0xCB, 0xCB ), medium = ( 0xA2, 0xA2, 0xA2 ), dark = ( 0x81, 0x81, 0x81 ) }
|
||||
, red = { light = ( 0x42, 0x42, 0x42 ), medium = ( 0x35, 0x35, 0x35 ), dark = ( 0x2A, 0x2A, 0x2A ) }
|
||||
, black = { light = ( 0x2F, 0x2F, 0x2F ), medium = ( 0x1F, 0x1F, 0x1F ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFB, 0xFB, 0xFB ), dark = ( 0xEF, 0xEF, 0xEF ) }
|
||||
}
|
||||
|
||||
|
||||
{-| Blue cone monochromacy
|
||||
-}
|
||||
blueConeMonochromacy : BlindnessPalette
|
||||
blueConeMonochromacy =
|
||||
{ blue = { light = ( 0x69, 0x83, 0xAE ), medium = ( 0x66, 0x7C, 0xA5 ), dark = ( 0x2D, 0x4C, 0x72 ) }
|
||||
, green = { light = ( 0xB1, 0xD5, 0xCC ), medium = ( 0x7C, 0x95, 0x8F ), dark = ( 0x52, 0x63, 0x5F ) }
|
||||
, yellow = { light = ( 0xEB, 0xEA, 0x9F ), medium = ( 0xC5, 0xC4, 0x85 ), dark = ( 0xA4, 0xA3, 0x6F ) }
|
||||
, orange = { light = ( 0xDE, 0xC5, 0xB7 ), medium = ( 0xB1, 0x9D, 0x92 ), dark = ( 0x8D, 0x7D, 0x74 ) }
|
||||
, red = { light = ( 0x7A, 0x2A, 0x2A ), medium = ( 0x62, 0x22, 0x22 ), dark = ( 0x4E, 0x1B, 0x1B ) }
|
||||
, black = { light = ( 0x2E, 0x2E, 0x38 ), medium = ( 0x1E, 0x1E, 0x25 ), dark = ( 0x00, 0x00, 0x00 ) }
|
||||
, white = { light = ( 0xFF, 0xFF, 0xFF ), medium = ( 0xFC, 0xFB, 0xF9 ), dark = ( 0xF0, 0xEF, 0xED ) }
|
||||
}
|
||||
|
||||
|
||||
svgFill : Color -> Svg.Attribute msg
|
||||
svgFill =
|
||||
Color.toCssString >> fill
|
||||
|
||||
|
||||
svgStroke : Color -> Svg.Attribute msg
|
||||
svgStroke =
|
||||
Color.toCssString >> Svg.Attributes.stroke
|
||||
|
||||
|
||||
font : Color -> Element.Attribute msg
|
||||
font =
|
||||
Color.toRgba >> Element.fromRgb >> Element.Font.color
|
||||
|
||||
|
||||
background : Color -> Element.Attribute msg
|
||||
background =
|
||||
Color.toRgba >> Element.fromRgb >> Element.Background.color
|
||||
|
||||
|
||||
transparent : Color
|
||||
transparent =
|
||||
Color.rgba 0 0 0 0
|
||||
|
||||
|
||||
|
||||
-- PRIMARY COLOR
|
||||
|
||||
|
||||
primaryColor : Color
|
||||
primaryColor =
|
||||
noordstarBlue
|
||||
|
||||
|
||||
darkPrimaryColor : Color
|
||||
darkPrimaryColor =
|
||||
rgb255 0x00 0x54 0xBD
|
||||
|
||||
|
||||
lightPrimaryColor : Color
|
||||
lightPrimaryColor =
|
||||
rgb255 0x80 0xAE 0xFF
|
||||
|
||||
|
||||
textOnPrimaryColor : Color
|
||||
textOnPrimaryColor =
|
||||
Color.white
|
||||
|
||||
|
||||
|
||||
-- SECONDARY COLOR
|
||||
|
||||
|
||||
secondaryColor : Color
|
||||
secondaryColor =
|
||||
rgb255 0xFF 0x8A 0x65
|
||||
|
||||
|
||||
darkSecondaryColor : Color
|
||||
darkSecondaryColor =
|
||||
rgb255 0xC7 0x5B 0x39
|
||||
|
||||
|
||||
lightSecondaryColor : Color
|
||||
lightSecondaryColor =
|
||||
rgb255 0xFF 0xBB 0x93
|
||||
|
||||
|
||||
textOnSecondaryColor : Color
|
||||
textOnSecondaryColor =
|
||||
Color.black
|
||||
|
||||
|
||||
|
||||
-- NOORDSTAR PALETTE
|
||||
|
||||
|
||||
noordstarBlue : Color
|
||||
noordstarBlue =
|
||||
rgb255 0x42 0x7F 0xF0
|
||||
|
||||
|
||||
noordstarYellow : Color
|
||||
noordstarYellow =
|
||||
rgb255 0xD2 0xD0 0x24
|
||||
|
||||
|
||||
noordstarGreen : Color
|
||||
noordstarGreen =
|
||||
rgb255 0x5E 0xA4 0x93
|
||||
|
||||
|
||||
noordstarRed : Color
|
||||
noordstarRed =
|
||||
rgb255 0xB0 0x00 0x00
|
||||
|
||||
|
||||
noordstarBlack : Color
|
||||
noordstarBlack =
|
||||
rgb255 0x2C 0x2C 0x48
|
||||
|
||||
|
||||
noordstarWhite : Color
|
||||
noordstarWhite =
|
||||
rgb255 0xF2 0xEF 0xEA
|
||||
|
||||
|
||||
|
||||
-- PALETTES
|
||||
|
||||
|
||||
primaryPalette : Palette
|
||||
primaryPalette =
|
||||
{ primary = primaryColor
|
||||
, secondary = secondaryColor
|
||||
, background = noordstarWhite
|
||||
, surface = noordstarWhite
|
||||
, error = noordstarRed
|
||||
, on =
|
||||
{ primary = textOnPrimaryColor
|
||||
, secondary = textOnSecondaryColor
|
||||
, background = Color.black
|
||||
, surface = Color.black
|
||||
, error = Color.white
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
darkPalette : Palette
|
||||
darkPalette =
|
||||
{ primary = darkPrimaryColor
|
||||
, secondary = darkSecondaryColor
|
||||
, background = noordstarWhite
|
||||
, surface = noordstarWhite
|
||||
, error = noordstarRed
|
||||
, on =
|
||||
{ primary = Color.white
|
||||
, secondary = Color.white
|
||||
, background = Color.black
|
||||
, surface = Color.black
|
||||
, error = Color.white
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lightPalette : Palette
|
||||
lightPalette =
|
||||
{ primary = lightPrimaryColor
|
||||
, secondary = lightSecondaryColor
|
||||
, background = noordstarWhite
|
||||
, surface = noordstarWhite
|
||||
, error = noordstarRed
|
||||
, on =
|
||||
{ primary = Color.black
|
||||
, secondary = Color.black
|
||||
, background = Color.black
|
||||
, surface = Color.black
|
||||
, error = Color.white
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
secondaryPalette : Palette
|
||||
secondaryPalette =
|
||||
{ primary = secondaryColor
|
||||
, secondary = primaryColor
|
||||
, background = Color.white
|
||||
, surface = Color.white
|
||||
, error = noordstarRed
|
||||
, on =
|
||||
{ primary = textOnSecondaryColor
|
||||
, secondary = textOnPrimaryColor
|
||||
, background = Color.black
|
||||
, surface = Color.black
|
||||
, error = Color.white
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue