Kaynağa Gözat

Day 1

master
Noëlle Anthony 4 yıl önce
ebeveyn
işleme
82e5d9b2ec
3 değiştirilmiş dosya ile 133 ekleme ve 0 silme
  1. 10
    0
      2019/01a.py
  2. 100
    0
      2019/01ain.txt
  3. 23
    0
      2019/01b.py

+ 10
- 0
2019/01a.py Dosyayı Görüntüle

@@ -0,0 +1,10 @@
def main():
with open("01ain.txt", "r") as file:
lines = file.readlines()
masses = [int(x) for x in lines]
fuels = [(x//3) - 2 for x in masses]
print(fuels)
print(sum(fuels))

if __name__ == "__main__":
main()

+ 100
- 0
2019/01ain.txt Dosyayı Görüntüle

@@ -0,0 +1,100 @@
118868
88841
133680
148066
70887
93213
124243
92767
71322
86793
53650
102703
146958
53031
148282
124989
74375
122044
122693
74204
74869
81803
124436
68495
74865
70765
81537
61376
145342
137159
115230
119293
147126
130191
131330
122891
135407
116334
130325
138521
71955
53806
122260
102573
70032
75981
111555
135654
50805
122186
138172
96422
124781
55894
54337
149926
63809
146163
55131
55796
92771
80288
111619
134602
82245
72505
117209
92383
149101
135399
112166
134000
88771
63963
103731
74915
146347
125390
126249
131534
142038
55327
58784
85003
65909
89879
128715
138559
146209
145040
116032
130046
131664
125899
141918
88426
50488
67943
79677
94858

+ 23
- 0
2019/01b.py Dosyayı Görüntüle

@@ -0,0 +1,23 @@
def main():
#lines = [12, 14, 1969, 100756]
with open("01ain.txt", "r") as file:
lines = file.readlines()
masses = [int(x) for x in lines]
fuels = [(x//3) - 2 for x in masses]
newfuels = []
for fuel in fuels:
of = fuel
f = fuel
while f > 0:
af = (f//3) - 2
if af > 0:
of += af
f = af
else:
f = 0
newfuels.append(of)
#print(newfuels)
print(sum(newfuels))

if __name__ == "__main__":
main()

Loading…
İptal
Kaydet