-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 6, Lanternfish
93 lines (86 loc) · 2.08 KB
/
Day 6, Lanternfish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
[int day=6; string name="Lanternfish";]
--------------------------------------------------------------------------------------
[int part=1;]
--------------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
long long n,d,a[100000000],f;
char s;
void displaytext(string t,double delay,bool end){
int i=0;
while (t[i]!='\0'){
cout<<t[i];
usleep(1000000*delay);
i++;
}
if(end)cout<<endl;
}
int main(){
displaytext("Enter amount of Lanternfish.",0.1,true);
cin>>n;
displaytext("Enter Lanternfish data.",0.1,true);
for(int i=1;i<=n;i++){
cin>>s;
if(s==',')cin>>s;
a[i]=s-'0';
}
displaytext("Enter amount of days for simulation.",0.1,true);
cin>>d;
displaytext("Processing...",0.05,false);
sleep(1);
for(int i=1;i<=d;i++){
f=0;
for(int j=1;j<=n;j++){
if(a[j]==0)a[j]=7,f++;
a[j]--;
}
for(int j=1;j<=f;j++)n++,a[n]=8;
}
displaytext("\nAmount of Lanternfish after "+to_string(d)+" days:",0.05,false);
sleep(1);
displaytext(to_string(n),0.05,false);
return 0;
}
--------------------------------------------------------------------------------------
[int part=2;]
--------------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
unsigned long long n,d,a[100000000],b[10],sa,sb;
char s;
void displaytext(string t,double delay,bool end){
int i=0;
while (t[i]!='\0'){
cout<<t[i];
usleep(1000000*delay);
i++;
}
if(end)cout<<endl;
}
int main(){
displaytext("Enter amount of Lanternfish.",0.05,true);
cin>>n;
displaytext("Enter Lanternfish data.",0.05,true);
for(int i=1;i<=n;i++){
cin>>s;
if(s==',')cin>>s;
a[i]=s-'0';
b[a[i]]++;
}
displaytext("Enter amount of days for simulation.",0.05,true);
cin>>d;
displaytext("Processing...",0.05,false);
sleep(1);
for(int i=1;i<=d;i++){
for(int j=1;j<=8;j++)b[j-1]=b[j];
b[8]=sa;
b[6]+=sa;
sa=b[0];
}
n=0;
for(int i=0;i<=8;i++)n+=b[i];
displaytext("\nAmount of Lanternfish after "+to_string(d)+" days:",0.05,false);
sleep(1);
displaytext(to_string(n),0.05,false);
return 0;
}