- 1
Чепига снова начинает остопяздывать.
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
Чепига снова начинает остопяздывать.
0
// А какие-нибудь IDE с интегрированными отладчиками (или
// отладчики сами по себе) умеют нахрен выкидывать всякую
// там компилтайм-метушню из кода, оставляя лишь то, что
// реально исполняется в рантайме?
// Ну например, чтобы хуйня вида
if constexpr(хуйня1)
{
bagor1();
if constexpr(хуйня2)
{
bagor11();
}
else
{
bagor12();
}
}
else
{
bagor2();
if constexpr (хуйня3)
{
bagor21();
}
bagor();
}
// и если хуйня1 == true и хуйня2 == false то чтоб в отладчике
// в какой-то там говноIDE я увидел бы не эту пидоросню с if consexpr
// а только лишь
bagor1();
bagor12();
Есть ли такое?
+4
int main()
{
using Human = NamedTuple<
Field<"name", std::string>,
Field<"age", int>
>;
using User = NamedTuple<
Field<"login", std::string>,
Field<"password", std::string>
>;
Human vasya{ "Vasya", 16 };
vasya.get<"age">() = 17;
User user{ "xXxBaCRHxXx", "p4ssword" };
auto vasyaMerged = mergeNamedTuples(vasya, user);
std::cout << vasyaMerged.get<"name">() << " is " << vasyaMerged.get<"age">() << " years old!" << std::endl;
std::cout << "Login is " << vasyaMerged.get<"login">() << " and password is " << vasyaMerged.get<"password">() << std::endl;
}
Как похорошел C++ при C++20!
https://wandbox.org/permlink/llpXuy7IOSugtxHo
0
Три девицы вечерком
Чатились за коньячком…
Мысль у всех была ловка:
Схантить бы холостяка.
Чтобы в теле мускулистом
Был крутым специалистом,
Чтобы с опытом в айти
Лет так более пяти.
В корпорации, стартапе
Чтоб прошёл он все этапы,
Да на англицком на слоге
Пел на Хабре в своём блоге.
И в сообществе средь профи
Был желан, как кружка кофе.
Ну, короче, чтоб матёр
Был как истинный Senior.
...
https://m.habr.com/ru/post/552828/
Какое поэтство )))
+1
import cowsay
cowsay.cow('Hello World')
___________
< Hello World >
===========
\
\
^__^
(oo)\_______
(__)\ )\/\
||----w |
|| ||
+2
package org.trishinfotech.builder;
public class Car {
private String chassis;
private String body;
private String paint;
private String interior;
public Car() {
super();
}
public Car(String chassis, String body, String paint, String interior) {
this();
this.chassis = chassis;
this.body = body;
this.paint = paint;
this.interior = interior;
}
public String getChassis() {
return chassis;
}
public void setChassis(String chassis) {
this.chassis = chassis;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getPaint() {
return paint;
}
public void setPaint(String paint) {
this.paint = paint;
}
public String getInterior() {
return interior;
}
public void setInterior(String interior) {
this.interior = interior;
}
public boolean doQualityCheck() {
return (chassis != null && !chassis.trim().isEmpty()) && (body != null && !body.trim().isEmpty())
&& (paint != null && !paint.trim().isEmpty()) && (interior != null && !interior.trim().isEmpty());
}
@Override
public String toString() {
// StringBuilder class also uses Builder Design Pattern with implementation of java.lang.Appendable interface
StringBuilder builder = new StringBuilder();
builder.append("Car [chassis=").append(chassis).append(", body=").append(body).append(", paint=").append(paint)
return builder.toString();
}
}
https://habr.com/ru/company/otus/blog/552412/
Паттерн проектирования Builder (Строитель) в Java
−1
https://thestreetjournal.org/2021/04/chinese-authorities-seize-7221-human-penises-on-cargo-ship-from-nigeria/
7221 камерунских шоколадных зайцев пострадало.
+3
std::cout << "Creating ptr1!" << std::endl;
auto ptr1 = make_nft<Cow>();
std::cout << "ptr1(" << &ptr1 << "): " << ptr1.get() << std::endl;
ptr1->MakeSound();
std::cout << "Creating ptr2!" << std::endl;
nft_ptr<Animal> ptr2;
std::cout << "ptr2(" << &ptr2 << "): " << ptr2.get() << std::endl;
std::cout << "Moving: ptr2 = std::move(ptr1)" << std::endl;
ptr2 = std::move(ptr1);
std::cout << "Moved: ptr1 = " << ptr1.get() << " ptr2 = " << ptr2.get()
<< std::endl;
https://github.com/zhuowei/nft_ptr
"C++ std::unique_ptr that represents each object as an NFT on the Ethereum blockchain."
0
void main()
{
unsigned char c=0;
for (int c = 0;c < 256; c++) {
cout << "the value of '" << c << "' is: " << int(c) << '\n';
}
}
Ой, а чойта оно повесилося и пикает?
0
"""
This module provides a function merge_sort, which is one of the simplest and the
most robust sorting algorithms, being relatively fast, having (n*log(n))
complexity. Also, this module counts the number of inversions in a given array.
Usage: import this module and use the function merge_sort. The first element in
a returned tuple shall be a sorted array, while the second one will be a number
of inversions in the array.
Copyright (C) 2021 Sergay Gayorgyevich.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import argparse
def merge_sort(array : list) -> (list, int):
"""
MergeSort algorithm with additional inversion counting.
input: array.
output: sorted array and number of inversions in it.
"""
if len(array) <= 1:
return (array, 0)
elif len(array) == 2:
if array[0] > array[1]:
array[0], array[1] = array[1], array[0]
return (array, 1)
return (array, 0)
mid = len(array) // 2
left, left_inversions = merge_sort(array[:mid])
right, right_inversions = merge_sort(array[mid:])
merged, split_inversions = _merge(left, right)
return (merged, right_inversions + left_inversions + split_inversions)
def _merge(left_array : list, right_array : list) -> (list, int):
"""
This function isn't supposed to be called, it's an inner function of the
module, and not a part of its API!
The purpose of this function is to merge two arrays. Due to the nature of
the MergeSort algorithm, it operates two arrays, both of which are sorted.
input: two sotrted arrays.
output: sorted array, consisting of elements of both operated arrays.
"""
resulting_array = list()
inversion_count = 0
c_len = len(left_array) + len(right_array)
for i in range(c_len):
if (len(left_array) != 0) and (len(right_array) != 0):
if left_array[0] > right_array[0]:
inversion_count += len(left_array)
resulting_array.append(right_array.pop(0))
else:
resulting_array.append(left_array.pop(0))
elif len(left_array) == 0:
resulting_array.append(right_array.pop(0))
elif len(right_array) == 0:
resulting_array.append(left_array.pop(0))
return (resulting_array[:], inversion_count)
# For testing purposes only! Do not use in production!
if __name__ == '__main__':
DESC = "Sort an array and print an amount of inversions it has." # Description for argparse.
argparser = argparse.ArgumentParser(description = DESC)
argparser.add_argument("elements", type = int, nargs = '+', help = "A list to be sorted.")
args = argparser.parse_args()
print(merge_sort(args.elements))
Изучаю алгоритм "Сортировка Слиянием".