- 0 Posts
- 13 Comments
Joined 3 years ago
Cake day: July 7th, 2023
You are not logged in. If you use a Fediverse account that is able to follow users, you can follow this user.
Joey@programming.devto
Showerthoughts@lemmy.world•People who were born in the year 2000 can never forget what age they are.
8·2 years agoI think the point is just that the little bit of math is very easy if you’re born in 2000.
Joey@programming.devto
Fuck AI@lemmy.world•Parents Sue School That Gave Bad Grade to Student Who Used AI to Complete Assignment
20·2 years agoHe already admitted to using AI
Joey@programming.devto
Programming@programming.dev•DARPA suggests turning old C code automatically into Rust – using AI, of course
7·2 years agoSo a translation of legacy code into Rust would either attain memory safety, or wouldn’t compile.
They’d probably have to make sure it doesn’t use the
unsafekeyword to guarantee this.
Awww Mom! Now I’m even more happy! You ruin EVERYTHING!
The Japanese Mario 2 was released outside of Japan on the Super Nintendo in the Super Mario All-Stars game. It’s known as “Super Mario Bros. The Lost Levels” on that cartridge.
Keep practicing!
Oh yeah that’s a good point. I have seen that before but I didn’t think of it at the time.
My solution in rust. I’m sure there’s a lot more clever ways to do it but this is what I came up with.
Code
use std::{io::prelude::*, fs::File, path::Path, io }; fn main() { run_solution(false); println!("\nPress enter to continue"); let mut buffer = String::new(); io::stdin().read_line(&mut buffer).unwrap(); run_solution(true); } fn run_solution(check_for_spelled: bool) { let data = load_data("data/input"); println!("\nProcessing Data..."); let mut sum: u64 = 0; for line in data.lines() { // Doesn't seem like the to_ascii_lower call is needed but... just in case let first = get_digit(line.to_ascii_lowercase().as_bytes(), false, check_for_spelled); let last = get_digit(line.to_ascii_lowercase().as_bytes(), true, check_for_spelled); let num = (first * 10) + last; // println!("\nLine: {} -- First: {}, Second: {}, Num: {}", line, first, last, num); sum += num as u64; } println!("\nFinal Sum: {}", sum); } fn get_digit(line: &[u8], from_back: bool, check_for_spelled: bool) -> u8 { let mut range: Vec = (0..line.len()).collect(); if from_back { range.reverse(); } for i in range { if is_num(line[i]) { return (line[i] - 48) as u8; } if check_for_spelled { if let Some(num) = is_spelled_num(line, i) { return num; } } } return 0; } fn is_num(c: u8) -> bool { c >= 48 && c <= 57 } fn is_spelled_num(line: &[u8], start: usize) -> Option { let words = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]; for word_idx in 0..words.len() { let mut i = start; let mut found = true; for c in words[word_idx].as_bytes() { if i < line.len() && *c != line[i] { found = false; break; } i += 1; } if found && i <= line.len() { return Some(word_idx as u8 + 1); } } return None; } fn load_data(file_name: &str) -> String { let mut file = match File::open(Path::new(file_name)) { Ok(file) => file, Err(why) => panic!("Could not open file {}: {}", Path::new(file_name).display(), why), }; let mut s = String::new(); let file_contents = match file.read_to_string(&mut s) { Err(why) => panic!("couldn't read {}: {}", Path::new(file_name).display(), why), Ok(_) => s, }; return file_contents; }






He would have wanted to keep the trucks/wheels/bearings/etc (if you keep that stuff a new board alone would be cheaper than the fee) and it’s a lot quicker to snap the board than sit there taking it apart.