- 1
IT Оффтоп #160
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
IT Оффтоп #160
#130: https://govnokod.ru/27755 https://govnokod.xyz/_27755
#131: https://govnokod.ru/27766 https://govnokod.xyz/_27766
#132: https://govnokod.ru/27790 https://govnokod.xyz/_27790
#133: https://govnokod.ru/27828 https://govnokod.xyz/_27828
#134: https://govnokod.ru/27834 https://govnokod.xyz/_27834
#135: https://govnokod.ru/27839 https://govnokod.xyz/_27839
#136: https://govnokod.ru/27845 https://govnokod.xyz/_27845
#137: https://govnokod.ru/27857 https://govnokod.xyz/_27857
#138: https://govnokod.ru/27867 https://govnokod.xyz/_27867
#139: https://govnokod.ru/27887 https://govnokod.xyz/_27887
#140: https://govnokod.ru/27900 https://govnokod.xyz/_27900
#141: https://govnokod.ru/27914 https://govnokod.xyz/_27914
#142: https://govnokod.ru/27942 https://govnokod.xyz/_27942
#143: https://govnokod.ru/27960 https://govnokod.xyz/_27960
#144: https://govnokod.ru/27972 https://govnokod.xyz/_27972
#145: https://govnokod.ru/27996 https://govnokod.xyz/_27996
#146: https://govnokod.ru/28008 https://govnokod.xyz/_28008
#147: https://govnokod.ru/28049 https://govnokod.xyz/_28049
#148: https://govnokod.ru/28087 https://govnokod.xyz/_28087
#149: https://govnokod.ru/28136 https://govnokod.xyz/_28136
#150: https://govnokod.ru/28157 https://govnokod.xyz/_28157
#151: https://govnokod.ru/28209 https://govnokod.xyz/_28209
#152: https://govnokod.ru/28217 https://govnokod.xyz/_28217
#153: https://govnokod.ru/28232 https://govnokod.xyz/_28232
#154: https://govnokod.ru/28275 https://govnokod.xyz/_28275
#155: https://govnokod.ru/28281 https://govnokod.xyz/_28281
#156: https://govnokod.ru/28322 https://govnokod.xyz/_28322
#157: https://govnokod.ru/28344 https://govnokod.xyz/_28344
#158: https://govnokod.ru/28366 https://govnokod.xyz/_28366
#159: https://govnokod.ru/28391 https://govnokod.xyz/_28391
−7
if (neuronsV.size() >= 8)
{
auto count = neuronsV.size() - neuronsV.size() % 8;
__m256* vs = static_cast<__m256*>(alloca(count * sizeof(float) * 3));
__m256* ws = vs + count / 8;
__m256* ins = ws + count / 8;
for (int i = 0; i < count / 8; ++i)
{
vs[i] = _mm256_load_ps(&neuronsV[i * 8]);
ws[i] = _mm256_load_ps(&neuronsW[i * 8]);
ins[i] = _mm256_load_ps(&neuronsIn[i * 8]);
}
static const __m256 div3 = [](void) -> __m256
{
float temp[]{ 3.f, 3.f, 3.f, 3.f, 3.f, 3.f, 3.f, 3.f };
return _mm256_load_ps(temp);
}();
__m256 iextv = [&iext](void) -> __m256
{
float temp[]{ iext, iext, iext, iext, iext, iext, iext, iext };
return _mm256_load_ps(temp);
}();
__m256 exprdtv = [&dt](void) -> __m256
{
float temp[]{ expr * dt, expr * dt, expr * dt, expr * dt, expr * dt, expr * dt, expr * dt, expr * dt };
return _mm256_load_ps(temp);
}();
static const __m256 av = [](void) -> __m256
{
float temp[]{ a, a, a, a, a, a, a, a };
return _mm256_load_ps(temp);
}();
static const __m256 bv = [](void) -> __m256
{
float temp[]{ b, b, b, b, b, b, b, b };
return _mm256_load_ps(temp);
}();
__m256 thetadt = [&dt](void) -> __m256
{
float temp[]{ dt / theta, dt / theta, dt / theta, dt / theta, dt / theta, dt / theta, dt / theta, dt / theta };
return _mm256_load_ps(temp);
}();
for (int i = 0; i < count / 8; ++i)
{
// vs += (vs - (vs * vs * vs) / 3.f - ws - iext - ins) * exprdtv
__m256 nv = _mm256_mul_ps(vs[i], _mm256_mul_ps(vs[i], vs[i]));
nv = _mm256_sub_ps(vs[i], _mm256_div_ps(nv, div3));
nv = _mm256_sub_ps(nv, ws[i]);
nv = _mm256_add_ps(nv, iextv);
nv = _mm256_add_ps(nv, ins[i]);
nv = _mm256_mul_ps(nv, exprdtv);
vs[i] = _mm256_add_ps(vs[i], nv);
// ws += (vs - av - ws * bv) * thetadt
nv = _mm256_sub_ps(vs[i], av);
nv = _mm256_sub_ps(nv, _mm256_mul_ps(ws[i], bv));
ws[i] = _mm256_add_ps(ws[i], _mm256_mul_ps(nv, thetadt));
}
for (int i = 0; i < count / 8; ++i)
{
_mm256_storeu_ps(&neuronsV[i * 8], vs[i]);
_mm256_storeu_ps(&neuronsW[i * 8], ws[i]);
}
}
// scalar edition
for (int i = 0; i < neuronsV.size() % 8; ++i)
{
auto off = neuronsV.size() - 1 - i;
auto& v = neuronsV[off];
auto& w = neuronsW[off];
auto& in = neuronsIn[off];
v += (v - (v * v * v) / 3.f - w - iext - in) * expr * dt;
w += (v - a - w * b) * dt / theta;
}
std::ranges::fill(neuronsIn, 0.f);
Царский анрол
0
main: () -> int = {
std::cout << "hello world!";
}
Война не всех убила..
https://github.com/hsutter/cppfront
0
includelib C:\Irvine\User32.Lib
includelib C:\Irvine\Kernel32.Lib
includelib D:\masm32\lib\Irvine32.lib
include \masm32\include\Irvine32.inc
; D:/masm32/bin/ml.exe /c /coff "D:\asm\simple.asm"
; D:/masm32\bin\link.exe /subsystem:console "D:\asm\simple.obj"
.data
X Dword ?
A dword ?
B dword ?
M dword ?
.code
main PROC
mov eax, 1
xor ecx , ecx
xor ebx, ebx
strt:
add eax , 1
mov X, eax
push eax
call simple
cmp ebx, 1
pop eax
je ext
call WriteInt
call CrLF
ext:
cmp eax, 50000000
jb strt
exit
main ENDP
Simple PROC uses ecx
Mov A, 1
call Sqrt
Mov A , eax
MOV edx , 2
rn:
;push edx
mov ecx, edx
mov eax , X
mov ebx, edx
xor edx ,edx
div ebx
cmp edx, 0
jne stp
mov ebx ,1
jmp var
stp:
;pop edx
mov edx,ecx
cmp edx, A
inc edx
jb rn
var:
ret
Simple ENDP
Sqrt PROC USES ebx
mov A, 1 ;A = 1
mov eax ,X
push eax
shr EAX, 5
add EAX , 8
Mov B , EAX
pop eax
cmp B,0FFFFh
jbe crt
mov B, 0FFFFh
crt:;do {
mov ebx, B
push A
add A,ebx
shr A, 1
mov ebx, A
pop A
mov M ,ebx
mov eax, ebx
mul ebx
cmp eax , X
jbe opt
Mov eax, M
dec eax
mov B , eax
jmp dz
opt:
mov eax, M
inc eax
mov A , eax
dz:
mov eax, B
cmp eax,A
Jae crt
mov eax , A
dec eax
ret
Sqrt ENDP
END main
Лялька для простых чисел )))))))))
0
#Ввод пользователем шахматной клетки
chess_cell = input("Введите шахматную клетку ")
horizontal_chess = chess_cell[0] #присовение в переменную буквы клетки
vertical_chess = int (chess_cell[1]) #присовение в переменную цифры клетки
#Вычисление условий для определения цвета ячейки
if vertical_chess > 8:
print ("Число клетки не может быть больше 8! ") #Условие ограничивающее количество клеток по вертикали
elif horizontal_chess != "a" and horizontal_chess != "A" and horizontal_chess != "b" and horizontal_chess != "B"\
and horizontal_chess != "c" and horizontal_chess != "C" and horizontal_chess != "d" and horizontal_chess != "D"\
and horizontal_chess != "e" and horizontal_chess != "E" and horizontal_chess != "f" and horizontal_chess != "F"\
and horizontal_chess != "g" and horizontal_chess != "G" and horizontal_chess != "h" and horizontal_chess != "H":
print ("такой буквы ячейки не существует!") #Условие ограничивающее количество букв по горизонтали
elif horizontal_chess == "a" or horizontal_chess == "A" or horizontal_chess == "c" or horizontal_chess == "C"\
or horizontal_chess == "e" or horizontal_chess == "E" or horizontal_chess == "g" or horizontal_chess == "G":
if vertical_chess%2 == 1:
print ("ячейка черная ")
else:
print ("ячейка белая") #определение цвета клеток в вертикали А, C, E, G
elif horizontal_chess == "b" or horizontal_chess == "B"or horizontal_chess == "d" or horizontal_chess == "D"\
or horizontal_chess == "f" or horizontal_chess == "F" or horizontal_chess == "h" or horizontal_chess == "H":
if vertical_chess%2 == 0:
print ("ячейка черная ")
else:
print ("ячейка белая") #определение цвета клеток в вертикали B, D, F, H
Определение цвета ячейки шахматной доски. Перевести букву в число с помощью ord()? Не, это мы не проходили.
−2
for (int x0 = 0; x0 < layout[static_cast<std::vector<unsigned int, std::allocator<unsigned int>>::size_type>(i) - 1]; ++x0)
for (int x1 = 0; x1 < layout[static_cast<std::vector<unsigned int, std::allocator<unsigned int>>::size_type>(i)]; ++x1)
...
implicitбляди соснули.
0
public class Solution
{
public string RemoveStars(string s)
{
char[] str = new char[s.Length];
int l = 0;
for(int i = 0; i < s.Length; ++i)
if(s[i] == '*')
--l;
else
str[l++] = s[i];
return new string(str, 0, l);
}
}
решил выйти из выгорания изучением новой технологии. литкод оказался прикольной штукой..
+1
#!/usr/bin/env python3
# -*- coding: UTF8 -*-
from datetime import date
from os import environ, mkdir, system
from os.path import dirname, exists, join as path_join
from time import time
def check_verbose():
return environ.get("DEBUG") in ("true", "True", "TRUE", True, "yes", "Yes", "YES")
class Timer:
def __init__(self):
"""
Объект добавляет в начале текста временные метки
"""
self.start_epoch = self.last_call = time()
@staticmethod
def __fully_scope(timer: int or str) -> str:
"""
Преобразует однозначные значения в двузначные.
:param timer: Время
:return: Двузначное значение
"""
if len(str(timer)) == 2:
return str(timer)
elif len(str(timer)) == 1:
return "0" + str(timer)
elif len(str(timer)) <= 0:
return "00"
elif len(str(timer)) >= 2:
return str(timer)[:2]
def __formatter(self, timestep: float) -> str:
"""
Форматирует время
:return: время hh:mm:ss
"""
_hours = int(timestep // 3600), int(timestep % 3600)
_minute = int(_hours[1] // 60), int(_hours[1] % 60)
_current_epoch = f"{self.__fully_scope(_minute[0])}:{self.__fully_scope(_minute[1])}"
if _hours[0] > 0:
_current_epoch = f"{_hours[0]}:" + _current_epoch
return _current_epoch
def __call__(self, fix_call: bool = True) -> str:
"""
Считает время с начала сценария + с последнего шага
:return: время hh:mm:ss(+hh:mm:ss)
"""
current_epoch = self.__formatter(time() - self.start_epoch)
timedelta_epoch = self.__formatter(time() - self.last_call)
if fix_call:
self.last_call = time()
return f"{current_epoch}(+{timedelta_epoch})"
def __bool__(self):
return True
class Logger:
def __init__(self, name: str):
self.start_time = time()
self.name = name.upper()
self.timer = Timer()
self.log_file = path_join(environ["RESULT_DIR"], name, f"{name}_{date.today().isoformat()}.log")
def check_file(self):
if not exists(self.log_file):
if not exists(dirname(self.log_file)):
mkdir(dirname(self.log_file))
system(f"echo {date.today().isoformat()}> {self.log_file}")
def save_log(self, msg: str):
self.check_file()
with open(self.log_file, "a+") as _log_file:
_log_file.write(msg + "\n")
def massage(self, msg: str):
print(f"{self.timer()}::{self.name}::{msg}")
self.check_file()
self.save_log(f"{self.timer()}::{self.name}::{msg}")
def multi_msg(self, level: str, msg: any):
if isinstance(msg, (str, int, float, bool)):
self.massage(f"{level.upper()}::{msg}")
elif isinstance(msg, (tuple, list, set)):
for _msg in msg:
self.multi_msg(level, _msg)
elif isinstance(msg, dict):
for _msg_key in msg:
Ну собственно самописный логгер, потому что "библиатечный логгер переусложнен НИНАДА!"
−1
words = ['Broom', 'Being', 'Boring', 'Breeding', 'Dreaming', 'Doing', 'Dancing', 'Drinking',
'Freezing', 'Falling', 'Flooding', 'Fearing', 'Saying', 'Sleeping', 'Standing',
'Screaming', 'Running', 'Reading', 'Rolling', 'Rushing', 'Twerking', 'Telling']
def make_rows(row_size: int) -> list:
row_size = abs(int(row_size)); index = 0; amount = len(words)
# Найти кол-во групп / Calculate the amount of sublists
if row_size>amount: row_size=amount
if row_size > 0:
subs = (amount // row_size) + 1 if amount % row_size > 0 else amount // row_size
print(f'Слов: {len(words)} | | Ячеек: {subs}\n')
# Создать найденное кол-во групп / Create the found amount of sublists
rows = [[] for i in range(subs)]
for x in range(amount):
rows[index].append(words[x])
if len(rows[index]) == row_size: index += 1
return rows
else: return words
print(make_rows(2))
−2
int make_program_look_bigger[1000000];