mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
Starting eoc5, and how did I not notice the weird cow problem that snuck its way into the scene directory?
This commit is contained in:
parent
ad05030641
commit
acfd23c82e
2 changed files with 39 additions and 58 deletions
39
eoc/chapter5.py
Normal file
39
eoc/chapter5.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from helpers import *
|
||||
|
||||
from mobject.tex_mobject import TexMobject
|
||||
from mobject import Mobject
|
||||
from mobject.image_mobject import ImageMobject
|
||||
from mobject.vectorized_mobject import *
|
||||
|
||||
from animation.animation import Animation
|
||||
from animation.transform import *
|
||||
from animation.simple_animations import *
|
||||
from animation.playground import *
|
||||
from topics.geometry import *
|
||||
from topics.characters import *
|
||||
from topics.functions import *
|
||||
from topics.fractals import *
|
||||
from topics.number_line import *
|
||||
from topics.combinatorics import *
|
||||
from topics.numerals import *
|
||||
from topics.three_dimensions import *
|
||||
from topics.objects import *
|
||||
from scene import Scene
|
||||
from scene.zoomed_scene import ZoomedScene
|
||||
from scene.reconfigurable_scene import ReconfigurableScene
|
||||
from camera import Camera
|
||||
from mobject.svg_mobject import *
|
||||
from mobject.tex_mobject import *
|
||||
|
||||
from eoc.chapter1 import OpeningQuote, PatreonThanks
|
||||
from eoc.graph_scene import *
|
||||
|
||||
class Chapter3OpeningQuote(OpeningQuote):
|
||||
CONFIG = {
|
||||
"quote" : [
|
||||
"Using the chain rule is like peeling an onion: ",
|
||||
"you have to deal with each layer at a time, and ",
|
||||
"if it is too big you will start crying."
|
||||
],
|
||||
"author" : "(Anonymous professor)"
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
import numpy as np
|
||||
import random
|
||||
|
||||
class CowProblem():
|
||||
def __init__(self):
|
||||
self.reset()
|
||||
self.directions = [
|
||||
(1, 0),
|
||||
(1, 1),
|
||||
(0, 1),
|
||||
(-1, 1),
|
||||
(-1, 0),
|
||||
(-1, -1),
|
||||
(0, -1),
|
||||
(1, -1),
|
||||
]
|
||||
|
||||
def reset(self):
|
||||
self.field = np.ones((11, 11), dtype = 'bool')
|
||||
self.cow_x = 0
|
||||
self.cow_y = 0
|
||||
|
||||
def step(self):
|
||||
valid_step = False
|
||||
while not valid_step:
|
||||
step_x, step_y = random.choice(self.directions)
|
||||
if self.cow_x + step_x > 0 and self.cow_x + step_x < 11 and self.cow_y + step_y > 0 and self.cow_y + step_y < 11:
|
||||
valid_step = True
|
||||
self.cow_x += step_x
|
||||
self.cow_y += step_y
|
||||
self.field[self.cow_x, self.cow_y] = False
|
||||
|
||||
def total_grass_after_n_steps(self, n):
|
||||
for x in range(n):
|
||||
self.step()
|
||||
return sum(sum(self.field))
|
||||
|
||||
def num_steps_for_half_eaten(self):
|
||||
result = 0
|
||||
while sum(sum(self.field)) > 121/2:
|
||||
self.step()
|
||||
result += 1
|
||||
return result
|
||||
|
||||
def average_number_of_steps_for_half_eaten(self, sample_size):
|
||||
run_times = []
|
||||
for x in range(sample_size):
|
||||
run_times.append(
|
||||
self.num_steps_for_half_eaten()
|
||||
)
|
||||
self.reset()
|
||||
return np.mean(run_times)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue