Skip Navigation
Rust Day 6 solution, I feel like a god rn

I messed around in desmos for like 20 mins trying to find an algebraic solution to day 6 and made this. I feel as if this is the best way to solve the problem by graphing f(x) = (x-max_time/2)^2. Finding its y-intercept, finding its vertex (max_time/2) and then finding the minimum x needed to get the max distance by solving for max_distance = f(x).

```rust fn main() { let mut raw_input = include_str!("input.txt") .lines() .map(|f| {

f.split_ascii_whitespace() .skip(1) .collect::<String>() .parse::<usize>() .unwrap()

//for part 1, first parse then collect to a Vec<&str>

}) ;

let max_time = raw_input.next().unwrap(); let max_distance = raw_input.next().unwrap();

print!("{}", determine_range(max_time, max_distance));

//let max_times = raw_input.next().unwrap(); //let max_distances = raw_input.next().unwrap();

// let races = (0..max_times.len()).map(|i| { // determine_range(max_times[i], max_distances[i]) // });

// let total = races.reduce(|acc,x| x*acc).unwrap(); }

fn determine_range(max_time: usize, max_dist: usize) -> f64 { let vertex = max_time as f64/2.0; let min_y = vertex * vertex - max_dist as f64; let min_x = vertex - min_y.sqrt()+ 0.001;

let mut res = 2.0 * ( (vertex-0.001).floor() - min_x.ceil() + 1.0); if vertex.fract() == 0.0 { res+=1.0; } res } ```

1
how to turn events on and off in Javascript

Hello, so I am experiencing a problem in my javascript app where I cannot stop a user spamming a button. The app is used to draw three random numbers from a range. when a button is clicked, a number is drawn and a special animation plays, then the next number can be drawn. I am having trouble preventing the user from spamming the draw button. So far I have tried using a local variable called enabled which is set to false when the animation is playing and checked to be true before the actual animation function executes (its set back to false after it executes). I have also tried to remove and add the event listener of the button dynamically when it is pressed. Is there any way you guys think I can solve the issue? Thank you. The code should be in an image with the post.

7
Rust Rodio audio playback
  • Man I implemented something like the Sink option and it is playing the audio clips at inputted intervals just as I wanted. The only thing missing for me now is just the intervals, which means i just need to tinker with my exponential time functions. Thank you so much for your help.

  • Rust Rodio audio playback
  • I dont want to pause/play the source. I simply want to replay it over and over again but with a delay in between. The audio is a click of a game wheel spinning, its duration is somewhere in the low milliseconds. I have an exponential function which tells the program how much time to sleep until the next click on the wheel. I just want to play the sound each time the wheel clicks. Do you think appending the sound to a sink and removing it once Sink.sleep_until_end() finishes would produce that outcome.

  • Rust Rodio audio playback

    Hello, I really need help figuring out Rodio audio playback for a rust project. I need to play a short audio clip of a casino wheel turning a certain amount of times in a loop. When I run the main function, the program plays the audio clip once and then stops completely. If anybody who has used Rodio can give me help it would be greatly appreciated. Also, I have tried using a longer duration in the play_sound function but it doesn't change anything. Thank you

    7
    InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)UN
    uncle_agrey @lemmy.ml
    Posts 3
    Comments 3