| Bytes | Lang | Time | Link |
|---|---|---|---|
| 024 | AArch64 machine code | 250607T072036Z | 鳴神裁四点一号 |
| 020 | AWK | 250806T134210Z | xrs |
| 009 | Vyxal 3 | 250606T143504Z | Themooni |
| 027 | Python 3.8 prerelease | 250606T190444Z | Rhaixer |
| 009 | 05AB1E | 250616T000148Z | Lucenapo |
| 020 | Perl 5 p | 250612T212327Z | Xcali |
| 019 | Haskell | 250607T123732Z | Ibozz91 |
| 041 | Arsla | 250611T185158Z | aitzazis |
| 010 | 05AB1E | 250610T080708Z | Kevin Cr |
| 012 | dc | 250606T184811Z | Digital |
| 010 | Charcoal | 250607T202023Z | Neil |
| 008 | Jelly | 250606T165528Z | Jonathan |
| 023 | Ruby | 250606T232649Z | Value In |
| 040 | Tcl | 250606T153441Z | sergiol |
| 019 | APL+WIN | 250606T141907Z | Graham |
| 020 | Google Sheets / Excel | 250606T141259Z | z.. |
| 023 | JavaScript ES6 | 250606T140955Z | Arnauld |
AArch64 machine code, 24 bytes
-4 bytes by @ceilingcat
More -4 bytes by @ceilingcat
Returns with 2% error
f.o: file format elf64-littleaarch64
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000018 0000000000000000 0000000000000000 00000040 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .data 00000000 0000000000000000 0000000000000000 00000058 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 0000000000000000 0000000000000000 00000058 2**0
ALLOC
Contents of section .text:
0000 0310601e 2000431f 0008621e 63c0611e ..`. .C...b.c.a.
0010 6018601e c0035fd6 `.`..._.
Disassembly of section .text:
0000000000000000 <f>:
0: 1e601003 fmov d3, #2.000000000000000000e+00
4: 1f430020 fmadd d0, d1, d3, d0
8: 1e620800 fmul d0, d0, d2
c: 1e61c063 fsqrt d3, d3
10: 1e601860 fdiv d0, d3, d0
14: d65f03c0 re
Original source
Uses \$1.44\thickapprox1.414...=\sqrt2\$
/// fn (d0: f64, d1: f64, d2: f64) d0: f64
/// r1==d0, r2==d1, c1==d2
.globl f
f:
fmov d3,2.0 // d3 is 2.0
fmadd d0,d1,d3,d0 // d0 is (2*r2)+r1
fmul d0,d0,d2 // d0 is ((2*r2)+r1)*c1
fsqrt d3,d3 // d3 is sqrt(2)
fdiv d0,d3,d0 // d0 is sqrt(2)/(((2*r2)+r1)*c1)
ret
How I tested on Termux
$ cat main.c
#include <stdio.h>
double f(double, double, double);
int main(void) {
printf("%f\n", f(1.0, 1.0, 1.0));
printf("%f\n", f(1000.0, 1000.0, 10.2));
printf("%f\n", f(569.6, 123.7, 0.5));
}
$ clang -o main f.s main.c
$ ./main
0.471405
0.000046
0.003462
Vyxal 3, 9 bytes
d+×Ꮠξℭ²$÷
-1 byte by johnathan allan
-1 byte by lucenaposition by showing that 1440000 compresses better
d+×Ꮠξℭ²$÷
Ꮠξℭ # compressed integer 1200
² # squared (= 1440000)
$÷ # divided by
d # R2 (implicit) * 2
+ # + R1 (implicit)
× # * C1 (implicit)
# implicit output
💎
Created with the help of Luminespire.
<script type="vyxal3">
d+×Ꮠξℭ²$÷
</script>
<script>
args=[["1","1","1"],["1000","1000","10.2"],["123.7","569.6","0.5"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
Python 3.8 (pre-release), 28 27 bytes
To round output, change /c to //c.
lambda a,b,c:72e4/(a/2+b)/c
05AB1E, 9 bytes
·+*Ž4µn/z
Input is in the order R2, R1, C1.
· # Double the first (implicit) input R2: 2*R2
+ # Add it to the second (implicit) input R1: 2*R2+R1
* # Multiply it by the third (implicit) input C1: (2*R2+R1)*C1
Ž4µ # Push compressed integer 1200
n # Square it: 1440000
/ # Divide by 1440000
z # Take the multiplicative inverse
# (after which the result is output implicitly)
Haskell, 22 19 bytes
a!b=(72e4/(a/2+b)/)
Same equation as Javascript answer, not much to improve here.
Edit: -3 bytes thanks to Maki
Arsla, 41 bytes
2->R1 3->R2 4->C1 1.44 R1 2 R2 * + C1 * /
Arsla does not expect input in a standard way because it stores value to the stack and assumes the programmer to be its user (acting as a domain specific language)
05AB1E, 10 bytes
·+*Ƶh4°*s÷
Inputs in the order \$R2,R1,C1\$.
Try it online or verify all test cases.
Ƶh4°* could alternatively be Ž5¦₄* or •MbF•; and ·+* could alternatively be *2β (with inputs \$[R2,R1],C1\$) for the same byte-count.
Explanation:
· # Double the first (implicit) input R2: 2*R2
+ # Add it to the second (implicit) input R1: 2*R2+R1
* # Multiply it by the third (implicit) input C1: (2*R2+R1)*C1
# or alternatively:
* # Multiply the two (implicit) inputs together: [R2*C1,R1*C1]
2β # Convert it from a base-2 list to a base-10 integer: 2*R2*C1 + R1*C1
Ƶh # Push compressed integer 144
4° # Push 10 ** 4: 10000
* # Multiply the two together: 1440000
# or alternatively:
Ž5¦ # Push compressed integer 1440
₄* # Multiply it by 1000: 1440000
# or alternatively
•MbF• # Push compressed integer 1440000
s # Swap so the earlier (2*R2+R1)*C1 is at the top again
÷ # Integer-divide the 1440000 by this
# (after which the result is output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why Ƶh is 144; Ž5¦ is 1440; and •MbF• is 1440000.
dc, 12
C00d*?2*+*/p
Inputs are pushed to the stack in order C1, R1, R2.
Explanation
C00 # push 1200 to the stack
d* # duplicate and multiply to get 1440000
? # push 3 inputs to stack
2* # multiply R2 * 2
+ # add R1
* # multiply by C1
/ # divide 1440000 by result above
p # print
Charcoal, 10 bytes
I∕×⁷²⁰φ×⁺⊘
Try it online! Link is to "verbose" version of code. Takes input in JSON format; append three Ns to allow conversion from plain text. Explanation:
⁷²⁰ Literal integer `720`
× Multiplied by
φ Predefined variable `1000`
∕ Divided by
Implicit input
⊘ Halved
⁺ Plus
Implicit input
× Times
Implicit input
I Cast to string
Implicitly print
Jelly, 9 8 bytes
×Ḅ144ȷ4÷
A dyadic Link that accepts [R2, R1] on the left and C1 on the right and yields the 555 chip's frequency in Hertz.
How?
×Ḅ144ȷ4÷ - Link: pair of floats, [R2, R1]; float C1
× - {[R2, R1]} multiply by {C1} -> [R2 × C1, R1 × C1]
Ḅ - convert from binary -> 2 × R2 × C1 + R1 × C1
144ȷ4 - 144 × 10⁴ -> 1,440,000
÷ - {1,440,000} divide by {2 × R2 × C1 + R1 × C1}
Previous at 9 bytes
H+×⁵72ȷ4÷
A full program that accepts three arguments - R1, R2, and C1 - and prints the 555 chip's frequency in Hertz.
How?
H+×⁵72ȷ4÷ - Main Link: float R1; float R2
H - halve R1 -> R1 / 2
+ - add R2 to that -> R1 / 2 + R2
⁵ - get the third argument -> float C1
× - multiply -> (R1 / 2 + R2) × C1
72ȷ4 - 72 × 10⁴ -> 720,000
÷ - divide -> 720,000 / ((R1 / 2 + R2) × C1)
- implicit print
APL+WIN, 20 19 bytes
-1 byte thanks to z..
Prompts for C1 followed by R2 and then R1.
⌊.5+144E4÷(⎕+2×⎕)×⎕
Google Sheets / Excel, 20 bytes
Expects R1 in A1, R2 in A2, C in A3.
=1200^2/(A1+2*A2)/A3
This is technically 19 but it auto converts 144e4 to 1440000 when I hit enter (making it 21)
=144e4/(A1+2*A2)/A3
