stackprobe7s_memo

何処にも披露する見込みの無いものを書き落とす場所

ナップサック問題(C#)

入力 public class Item // アイテム { public int Value; // このアイテムの価値 : 0 ~ 1,000,000 の範囲でランダムに生成 public int Weight; // このアイテムの重さ : 0 ~ 1,000 の範囲でランダムに生成 } public class Condition // 与えられた条件 { …

Brainfuck Interpreter

https://github.com/stackprobe/Annex/blob/master/Hatena/a20191018_Brainfuck/Brainfuck.c #include "C:\Factory\Common\all.h" static autoList_t *Memory; static uint Ptr; static uint Increment_Ptr(void) { errorCase(Ptr == UINTMAX); // ? Overflo…

ビット操作

一番下の立ち上がっているビットを得る uint LowestBit(uint value) { return value & ~value + 1; } // - - - 動作確認用 uint LowestBit_TEST(uint value) { int bit; for(bit = 0; bit < 32; bit++) if(value & 1u << bit) return 1u << bit; return 0u; …

再帰的探索の再起呼び出(し|さない)

再起呼び出し // protected bool IsInvalid(int index); : 0 ~ (index - 1) の element の並びが間違っていれば ture そうでなければ false // protected bool IsEnd(int index); : 0 ~ (index - 1) の element の並びで完成していれば true そうでなけれ…

swap (int a, int b)

int a = rand(); // any value int b = rand(); // any value // ... { int tmp = a; a = b; b = tmp; } { a ^= b; b ^= a; a ^= b; } { a -= b; b += a; a = b - a; } { a += b; b = a - b; a -= b; } { a = b - a; b -= a; a += b; } /* requires: 1 <= a …

FizzBuzzいろいろ

t0001.c #include <stdio.h> int main() { int n; for(n = 1; n <= 100; n++) { if(n % 15 == 0) printf("FizzBuzz\n"); else if(n % 3 == 0) printf("Fizz\n"); else if(n % 5 == 0) printf("Buzz\n"); else printf("%d\n", n); } } t0002.c #include <stdio.h> int main() { </stdio.h></stdio.h>…

よくある素数列挙サンプルコード集

t0001.c 愚直に素数を列挙する。 範囲 [2, INT_MAX) #include <stdio.h> #include <limits.h> int main() { int c; int d; for(c = 2; c < INT_MAX; c++) { for(d = 2; d < c; d++) if(c % d == 0) goto next; printf("%d\n", c); next:; } } t0002.c 愚直に素数を列挙する。そ</limits.h></stdio.h>…

Test()

Test() { Test(); }