Skip to content

Instantly share code, notes, and snippets.

View alpinistbg's full-sized avatar

alpine alpinistbg

View GitHub Profile
@alpinistbg
alpinistbg / binary.pas
Created May 9, 2023 08:38
Two variants of binary search function with a noticeable difference
program Project1;
const
MAX = 20;
var
A: array[0..MAX-1] of Integer;
function FindLM(I: Integer): Integer;
var
@alpinistbg
alpinistbg / duff_copy.c
Created January 5, 2023 09:03
Duff's device
void duff_copy(char *to, char *from, int count) {
int n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
case 2: *to++ = *from++;
@alpinistbg
alpinistbg / array_of_const.pas
Created July 21, 2022 07:59
Convinient `array of const`
unit
array_of_const;
{$mode ObjFPC}{$H+}
{$modeswitch advancedrecords}
interface
uses
Classes, SysUtils;
@alpinistbg
alpinistbg / sort.dart
Created June 25, 2022 10:55
Bubble and select sort
List l = [12, 4, 2, 4, 55, 66, 3.14, 3, 12];
void main() {
print('$l -> ${bubbleSort(List.from(l))}');
print('$l -> ${selSort(List.from(l))}');
}
List bubbleSort(List l) {
bool swap = true;
while (swap) {
@alpinistbg
alpinistbg / sortk.dart
Last active June 25, 2022 10:52
Sort with iterables
typedef ListInt = List<int>;
ListInt l = [12, 14, 2, 5, 1298, 88, 2, 12, 14, 2, 5, 1298, 88, 2];
void main() {
fun1(l);
print('kesten= ${kestenSort(l)}');
print('kesten2= ${kestenSort2(l)}');
print('kesten3= ${kestenSort3(l)}');
}