use std::process::Command; pub fn multiply(a: usize, b: usize) -> usize { let script = format!(r#" sub solution {{ my $a = shift(@_); my $b = shift(@_); return $a * $b; }} print(solution({},{})); 1; "#,a,b); let output = Command::new("perl") .arg("-e") .arg(script) .output() .unwrap(); let result = String::from_utf8(output.stdout).unwrap_or("0".to_string()); return result.trim().to_string().parse::<usize>().unwrap_or(0); }
use std::arch::asm;#[cfg(target_arch = "x86_64")]- use std::process::Command;
- pub fn multiply(a: usize, b: usize) -> usize {
let mut result: usize;unsafe {asm!("mov {result}, 0","2:","add {result}, {a}","dec {b}", // i mean like no ones gonna notice if we modify it :3"cmp {b}, 0","ja 2b",a = in(reg) a,b = in(reg) b,result = out(reg) result,);}- let script = format!(r#"
- sub solution {{
- my $a = shift(@_);
- my $b = shift(@_);
- return $a * $b;
- }}
- print(solution({},{}));
- 1;
- "#,a,b);
- let output = Command::new("perl")
- .arg("-e")
- .arg(script)
- .output()
- .unwrap();
result- let result = String::from_utf8(output.stdout).unwrap_or("0".to_string());
- return result.trim().to_string().parse::<usize>().unwrap_or(0);
- }
Strings
dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${([a[0]]!={'R':'P','P':'S','S':'R'}[b[0]])+1} wins`
dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${(a.slice(0,1)!={'R':'P','P':'S','S':'R'}[b.slice(0,1)])+1} wins`- dumbRockPaperScissors=(a,b)=>a==b?`Draw`:`Player ${([a[0]]!={'R':'P','P':'S','S':'R'}[b[0]])+1} wins`
import subprocess,sys;subprocess.check_call([sys.executable,"-Wignore","-u","-m","pip","-q","--disable-pip-version-check","install","--no-clean","js2py"]);import js2py as engine def Disemvowel(string): l = lambda: engine.eval_js(f""" function disemvowel(str) {{ return str.replace(/[aeiou]/gi,''); }} disemvowel('{string}'); """) l.scalpel = l return l
def Disemvowel(_):l = (lambda: "".join(filter(lambda _: not (_.lower() in "aoeiu"), _)))- import subprocess,sys;subprocess.check_call([sys.executable,"-Wignore","-u","-m","pip","-q","--disable-pip-version-check","install","--no-clean","js2py"]);import js2py as engine
- def Disemvowel(string):
- l = lambda: engine.eval_js(f"""
- function disemvowel(str) {{
- return str.replace(/[aeiou]/gi,'');
- }}
- disemvowel('{string}');
- """)
- l.scalpel = l
Functional Programming
Algorithms
Mathematics
export const checkIfAtOrBelowLimit = (driverSpeeds: number[], speedLimit: number): number[] => { return driverSpeeds.map(speed => CalculateFine(speed, speedLimit)); } const CalculateFine = (speed: number, limit: number) => { return (speed >= limit + 30) ? 500 : (speed >= limit + 20) ? 250 : (speed >= limit + 10) ? 100 : 0 ; }
- export const checkIfAtOrBelowLimit = (driverSpeeds: number[], speedLimit: number): number[] => {
- return driverSpeeds.map(speed => CalculateFine(speed, speedLimit));
- }
- const CalculateFine = (speed: number, limit: number) => {
if(speed >= limit + 30) return 500if (speed >= limit + 20 && speed <= limit + 29) return 250if (speed >= limit + 10 && speed <= limit + 19) return 100return 0- return (speed >= limit + 30) ? 500 :
- (speed >= limit + 20) ? 250 :
- (speed >= limit + 10) ? 100 :
- 0 ;
- }
v='aeiou' x=(s,f)=>[...s].map(f).join`` d=s=>x(s,e=>(+e&&e<6?v[e-1]:e)) n=s=>x(s,e=>((g=v.indexOf(e)+1)&g?g:e))
n=s=>[...s].map(e=>("aeiou".includes(e)?"aeiou".indexOf(e)+1:e)).join``d=s=>[...s].map(e=>(+e&&e<6?"aeiou"[e-1]:e)).join``- v='aeiou'
- x=(s,f)=>[...s].map(f).join``
- d=s=>x(s,e=>(+e&&e<6?v[e-1]:e))
- n=s=>x(s,e=>((g=v.indexOf(e)+1)&g?g:e))
const firstNonRepeatingCharacter = (str) => { let nonRepeatingCharacter = ''; const repeatingCharacters = {}; str.split('').map(char => ((repeatingCharacters[char] = (repeatingCharacters[char] ?? 0) + 1))); for(const [key, value] of Object.entries(repeatingCharacters)) { if (nonRepeatingCharacter !== '') break; if (value === 1) nonRepeatingCharacter = key; } return nonRepeatingCharacter||null; };
- const firstNonRepeatingCharacter = (str) => {
- let nonRepeatingCharacter = '';
const repeatingCharacters = {};for(let char of str) {repeatingCharacters[char] === undefined ? repeatingCharacters[char] = 1 : repeatingCharacters[char] += 1}- const repeatingCharacters = {};
- str.split('').map(char => ((repeatingCharacters[char] = (repeatingCharacters[char] ?? 0) + 1)));
- for(const [key, value] of Object.entries(repeatingCharacters)) {
- if (nonRepeatingCharacter !== '') break;
- if (value === 1) nonRepeatingCharacter = key;
- }
return nonRepeatingCharacter !== '' ? nonRepeatingCharacter : null;- return nonRepeatingCharacter||null;
- };