- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
function *foo()
{
yield 1;
yield 2;
yield 3;
}
function main()
{
for (const o of foo())
{
console.log (o);
}
}
main();
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
function *foo()
{
yield 1;
yield 2;
yield 3;
}
function main()
{
for (const o of foo())
{
console.log (o);
}
}
main();
давайте посмотрим, как TS/JS имплементирует "елды". изначально код выглядит красиво. но заглянем под капот что генерит tsc для выполнение такого кода. мне придется разбить этот ужос
+1
struct file_id
{
uint64_t persistent;
uint64_t volatile_;
static const size_t RAW_LENGTH = 16;
operator std::string() const
{ return std::string(reinterpret_cast<const char*>(&persistent), RAW_LENGTH); }
// Операторы для использования file_id в качестве ключа map и
// unordered_map
struct hash
{
std::size_t operator()(const ntdec_smb2_file_id& file_id) const
{
std::string s_file_id = file_id;
std::hash<std::string> hasher;
return hasher(s_file_id);
}
};
bool operator == (const ntdec_smb2_file_id& other)
{
return std::string(*this) == std::string(other);
}
bool operator < (const ntdec_smb2_file_id& other)
{
return std::string(*this) < std::string(other);
}
bool operator > (const ntdec_smb2_file_id& other)
{
return std::string(*this) > std::string(other);
}
};
operator std::string тоже UB?
+2
class IntIter {
constructor(private i = 0) {}
next() {
type retType = [value: typeof this.i, done: boolean];
if (this.i < 10) {
return <retType>[this.i++, false];
}
return <retType>[this.i, true];
}
}
function main() {
let it = new IntIter();
for (const o of it)
{
print(o);
}
for (const o of "Hello")
{
print(o);
}
}
добавил поддержку ForOf для ES2015 и ES3; причем компилятор сам определяет какой вариант лучше юзать
+1
type a = 1;
type i = a & a;
type j = a | a;
function main() {
let v1: i;
let v2: j;
assert(sizeof(i) != sizeof(j));
print("done.");
}
ну все я понял вам скучно... как насчет такого примера?
+6
Раскрытие покровов. Настя, облачные технологии и Настенька.
−1
type int = 1;
type int64 = 4294967296;
declare function GC_get_heap_size(): int64;
function main() {
let i = 0;
for (i = 0; i < 10000000; ++i) {
const p = new int[1];
if (i % 100000 == 0) print("Heap size = ", GC_get_heap_size());
}
}
вот такая лабуда подкатили.. называется GC.. для тех кто не любит GC я добавил опцию -nogc :)
вот так можно JIT запускать без компиляции
tsc.exe --emit=jit --shared-libs=TypeScriptGCWrapper.dll 1.ts
tsc.exe --emit=jit -nogc 1.ts
+1
fn main() {
println!("Hello World!");
}
rustc --version --verbose:
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: powerpc-unknown-linux-gnu
release: 1.52.1
LLVM version: 12.0.0
Error output
rustc ./hello.rs
Illegal instruction (core dumped)
https://github.com/rust-lang/rust/issues/85238
Open: clienthax opened this issue on May 12 · 6 comments
0
//Let me introduce you, to the most stupidly long and complicated solution!.
using System.Linq;
public class TwoToOne
{
static string final;
public static string Longest (string s1, string s2)
{
final = "";
if (s1.ToLower().Contains("a")){final += "a";}
else if (s2.ToLower().Contains("a")){final += "a";}
if (s1.ToLower().Contains("b")){final += "b";}
else if (s2.ToLower().Contains("b")){final += "b";}
if (s1.ToLower().Contains("c")){final += "c";}
else if (s2.ToLower().Contains("c")){final += "c";}
if (s1.ToLower().Contains("d")){final += "d";}
else if (s2.ToLower().Contains("d")){final += "d";}
if (s1.ToLower().Contains("e")){final += "e";}
else if (s2.ToLower().Contains("e")){final += "e";}
if (s1.ToLower().Contains("f")){final += "f";}
else if (s2.ToLower().Contains("f")){final += "f";}
if (s1.ToLower().Contains("g")){final += "g";}
else if (s2.ToLower().Contains("g")){final += "g";}
if (s1.ToLower().Contains("h")){final += "h";}
else if (s2.ToLower().Contains("h")){final += "h";}
if (s1.ToLower().Contains("i")){final += "i";}
else if (s2.ToLower().Contains("i")){final += "i";}
if (s1.ToLower().Contains("j")){final += "j";}
else if (s2.ToLower().Contains("j")){final += "j";}
if (s1.ToLower().Contains("k")){final += "k";}
else if (s2.ToLower().Contains("k")){final += "k";}
if (s1.ToLower().Contains("l")){final += "l";}
else if (s2.ToLower().Contains("l")){final += "l";}
if (s1.ToLower().Contains("m")){final += "m";}
else if (s2.ToLower().Contains("m")){final += "m";}
if (s1.ToLower().Contains("n")){final += "n";}
else if (s2.ToLower().Contains("n")){final += "n";}
if (s1.ToLower().Contains("o")){final += "o";}
else if (s2.ToLower().Contains("o")){final += "o";}
if (s1.ToLower().Contains("p")){final += "p";}
else if (s2.ToLower().Contains("p")){final += "p";}
if (s1.ToLower().Contains("q")){final += "q";}
else if (s2.ToLower().Contains("q")){final += "q";}
if (s1.ToLower().Contains("r")){final += "r";}
else if (s2.ToLower().Contains("r")){final += "r";}
if (s1.ToLower().Contains("s")){final += "s";}
else if (s2.ToLower().Contains("s")){final += "s";}
if (s1.ToLower().Contains("t")){final += "t";}
else if (s2.ToLower().Contains("t")){final += "t";}
if (s1.ToLower().Contains("u")){final += "u";}
else if (s2.ToLower().Contains("u")){final += "u";}
if (s1.ToLower().Contains("v")){final += "v";}
else if (s2.ToLower().Contains("v")){final += "v";}
if (s1.ToLower().Contains("w")){final += "w";}
else if (s2.ToLower().Contains("w")){final += "w";}
if (s1.ToLower().Contains("x")){final += "x";}
else if (s2.ToLower().Contains("x")){final += "x";}
if (s1.ToLower().Contains("y")){final += "y";}
else if (s2.ToLower().Contains("y")){final += "y";}
if (s1.ToLower().Contains("z")){final += "z";}
else if (s2.ToLower().Contains("z")){final += "z";}
return final;
}
}
https://www.codewars.com/kata/reviews/5656b9ee8e40eb0a4a000005/groups/5895b9cc4839ff4573001512
Если бы платили за количество, а не качество..
+2
if($account['lvl']=="1"){ $exp=round($account['exp']*100/52);}
if($account['lvl']=="2"){ $exp=round((($account['exp']-52)/(110))*100,2);}
if($account['lvl']=="3"){ $exp=round((($account['exp']-135)/(832-135))*100,2);}
if($account['lvl']=="4"){ $exp=round((($account['exp']-832)/(3547-832))*100,2);}
if($account['lvl']=="5"){ $exp=round((($account['exp']-3547)/(9658-3547))*100,2);}
if($account['lvl']=="6"){ $exp=round((($account['exp']-9658)/(15478-9658))*100,2);}
if($account['lvl']=="7"){ $exp=round((($account['exp']-15478)/(18478-15478))*100,2);}
if($account['lvl']=="8"){ $exp=round((($account['exp']-18478)/(30789-18478))*100,2);}
if($account['lvl']=="9"){ $exp=round((($account['exp']-30789)/(72394-30789))*100,2);}
if($account['lvl']=="10"){ $exp=round((($account['exp']-72394)/(138789-72394))*100,2);}
if($account['lvl']=="11"){ $exp=round((($account['exp']-138789)/(214787-138789))*100,2);}
if($account['lvl']=="12"){ $exp=round((($account['exp']-214787)/(398747-214787))*100,2);}
if($account['lvl']=="13"){ $exp=round((($account['exp']-398747)/(587058-398747))*100,2);}
if($account['lvl']=="14"){ $exp=round((($account['exp']-587058)/(824585-587058))*100,2);}
if($account['lvl']=="15"){ $exp=round((($account['exp']-824585)/(1247858-824585))*100,2);}
if($account['lvl']=="16"){ $exp=round((($account['exp']-1247858)/(1558789-1247858))*100,2);}
if($account['lvl']=="17"){ $exp=round((($account['exp']-1558789)/(1985478-1558789))*100,2);}
if($account['lvl']=="18"){ $exp=round((($account['exp']-1985478)/(2245857-1985478))*100,2);}
if($account['lvl']=="19"){ $exp=round((($account['exp']-2245857)/(2785896-2245857))*100,2);}
if($account['lvl']=="20"){ $exp=round((($account['exp']-2785896)/(3685478-2785896))*100,2);}
if($account['lvl']=="21"){ $exp=round((($account['exp']-3685478)/(4169875-3685478))*100,2);}
if($account['lvl']=="22"){ $exp=round((($account['exp']-4169875)/(5125478-4169875))*100,2);}
if($account['lvl']=="23"){ $exp=round((($account['exp']-5125478)/(5999999-5125478))*100,2);}
if($account['lvl']=="24"){ $exp=round((($account['exp']-5999999)/(7145877-5999999))*100,2);}
if($account['lvl']=="25"){ $exp=round((($account['exp']-7145877)/(8791755-7145877))*100,2);}
if($account['lvl']=="26"){ $exp=round((($account['exp']-8791755)/(10691755-8791755))*100,2);}
if($account['lvl']=="27"){ $exp=round((($account['exp']-10691755)/(12791755-10691755))*100,2);}
if($account['lvl']=="28"){ $exp=round((($account['exp']-12791755)/(15191755-12791755))*100,2);}
if($account['lvl']=="29"){ $exp=round((($account['exp']-15191755)/(18091755-15191755))*100,2);}
if($account['lvl']=="30"){ $exp=round((($account['exp']-18091755)/(21191755-18091755))*100,2);}
if($account['lvl']=="31"){ $exp=round((($account['exp']-21191755)/(24491755-21191755))*100,2);}
if($account['lvl']=="32"){ $exp=round((($account['exp']-24491755)/(27991755-24491755))*100,2);}
if($account['lvl']=="33"){ $exp=round((($account['exp']-27991755)/(31691755-27991755))*100,2);}
if($account['lvl']=="34"){ $exp=round((($account['exp']-31691755)/(35791755-31691755))*100,2);}
if($account['lvl']=="35"){ $exp=round((($account['exp']-35791755)/(40391755-35791755))*100,2);}
if($account['lvl']=="36"){ $exp=round((($account['exp']-40391755)/(45591755-40391755))*100,2);}
if($account['lvl']=="37"){ $exp=round((($account['exp']-45591755)/(51491755-45591755))*100,2);}
if($account['lvl']=="38"){ $exp=round((($account['exp']-51491755)/(58191755-51491755))*100,2);}
if($account['lvl']=="39"){ $exp=round((($account['exp']-58191755)/(65791755-58191755))*100,2);}
if($account['lvl']=="40"){ $exp=round((($account['exp']-65791755)/(74391755-65791755))*100,2);}
if($account['lvl']=="41"){ $exp=round((($account['exp']-74391755)/(83991755-74391755))*100,2);}
if($account['lvl']=="42"){ $exp=round((($account['exp']-83991755)/(94591755-83991755))*100,2);}
if($account['lvl']=="43"){ $exp=round((($account['exp']-94591755)/(106191755-94591755))*100,2);}
if($account['lvl']=="44"){ $exp=round((($account['exp']-106191755)/(118791755-106191755))*100,2);}
if($account['lvl']=="45"){ $exp=round((($account['exp']-118791755)/(132391755-118791755))*100,2);}
if($account['lvl']=="46"){ $exp=round((($account['exp']-132391755)/(146991755-132391755))*100,2);}
if($account['lvl']=="47"){ $exp=round((($account['exp']-146991755)/(162591755-146991755))*100,2);}
if($account['lvl']=="48"){ $exp=round((($account['exp']-162591755)/(179191755-162591755))*100,2);}
if($account['lvl']=="49"){ $exp=round((($account['exp']-179191755)/(196791755-179191755))*100,2);}
if($account['lvl']=="50"){ $exp=round((($account['exp']-196791755)/(215391755-196791755))*100,2);}
Расчет % заполнения шкалы уровня в зависимости от опыта
0
function main() {
const o = {
v: "Hi",
toString() {
return this.v;
},
};
print(o);
}
Хочу напомнить о себе, а то люди начали забывать :)...