Rust, score= ~6,081.9
Guesses each number 1-9. Aborts if the number found is less than 0.8 * number.
use rand;
use rand::{Rng, RngCore};
struct Which {
rng: rand::rngs::ThreadRng,
numbers: Vec<f32>,
score: f32
}
impl Which {
fn new(rng: rand::rngs::ThreadRng) -> Which {
...
@mousetail as an example, the function takes in a single number and runs the simulation for 1000 iterations. Let's say the number is the value of 0.8 in your code so a real between 0 and 1
In accordance with our meta agreement, since one candidate received more votes than the others, we have a new featured language! Throughout September 2022, our Language of the Month will be:
Prolog
What's a Language of the Month?
See the meta post for nominations. In short, during September, th...
An ant starts on an edge of a dodecahedron, facing parallel to it. At each step, it walks forward to the next vertex and turns either left or right to continue onto one of the other two edges that meet there. A sequence of left/right choices that returns the ant to its initial state (edge and dir...
SPICE is an electrical circuit simulation program originating from UC Berkeley. Your goal is to implement a minimalistic version which can solve for the nodal voltages and branch currents of a circuit composed of resistors and DC current sources.
Input Format
The input may come from a file, io ...
Given an integer n > 9, for each possible insertion between digits in that integer, insert an addition + and evaluate. Then, take the original number modulo those results. Output the sum total of these operations.
An example with n = 47852:
47852 % (4785+2) = 4769
47852 % (478+52) = 152
47852 ...
Say, would anyone here happen to know the best way to optimize some trivial assembly?
ldh [32]
and #0xf3f
jeq #0x01, drop
jeq #0x02, drop
jeq #0x04, drop
jeq #0x08, drop
jeq #0x10, drop
jeq #0x11, drop
jeq #0x12, drop
jeq #0x14, drop
jeq #0x18, drop
jeq #0x19, drop
ret #1
drop:
ret #0
I can't think of any efficient way to optimize this since jumps are only allowed forward (language is cBPF).
Persistence of a number
Given a blackbox function \$f : \mathbb N \times \mathbb N \to \mathbb N\$ and a positive integer \$x = d_1d_2d_3...d_n\$, where \$d_i\$ are digits with \$d_1 \ne 0\$, output the persistance of \$x\$ under \$f\$.
Shortest code wins
@Bubbler Hm, OK I'll try writing it like that and see if it's shorter.
The first "if x == 0x10 or 0x19" probably wouldn't work because the and #0xf3f is used to mask out bits that should be ignored, so I'd have to still keep that AND in there.
Since there's only one general-purpose register and one index register, doing if (x & 0xf20) might require an extra instruction or two.
Er, actually no, I can use jset for that.
Yeah it looks like that saved two instructions. I'll test it out.
(It'd be easier if it had some sort of popcnt, but it doesn't)
ldh [32]
and #0xf3f
jeq #0x10, drop
jeq #0x19, drop
jset #0xf20, match
and #0xf
jeq #0x1, drop
jeq #0x2, drop
jeq #0x4, drop
jeq #0x8, drop
match:
ret #1
drop:
ret #0
If the machine was something closer to x86, I could suggest something like selecting x-th bit from a 32-bit constant (the ten positions are 0, the rest are 1)