kauma/src/tasks/tasks01/poly2block.rs
2024-11-01 21:20:46 +01:00

19 lines
524 B
Rust

use crate::utils::poly::{self, polynomial_2_block};
use anyhow::{Ok, Result};
use base64::prelude::*;
use serde_json::Value;
pub fn poly2block(args: &Value) -> Result<Vec<u8>> {
let coefficients: Vec<u8> = args["coefficients"]
.as_array()
.unwrap()
.into_iter()
.map(|x| x.as_u64().unwrap() as u8)
.collect();
let semantic: String = serde_json::from_value(args["semantic"].clone())?;
let result = polynomial_2_block(coefficients, &semantic).unwrap();
Ok(result)
}