This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static long gcf(long m, long n) | |
{ | |
if (m < n) goto l2; | |
l1: if ((m %= n) == 0) return n; | |
l2: if ((n %= m) == 0) return m; | |
goto l1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void ForwardCopy(byte[] s, uint si, byte[] d, uint di, uint cx) { | |
unchecked { | |
// pre copy to qword align to destination | |
uint cxpre = (8 - (di & 7)) & 7; | |
if (cx < cxpre) { | |
// early out if we cannot even align to the first qword | |
for (int i = 0; i < cx; i++) | |
d[di++] = s[si++]; | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DisposableList<T> : List<T>, IDisposable where T : IDisposable { | |
public void Dispose() { | |
foreach (var i in this) i.Dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2022 Hafthor Stefansson | |
// Distributed under the MIT/X11 software license | |
// Ref: http://www.opensource.org/licenses/mit-license.php. | |
static unsafe void UnsafeSet(byte[] a, uint d, uint c, byte v) { | |
unchecked { | |
ushort v2 = (ushort)(v << 8 | v); | |
uint v4 = (uint)v2 << 16 | v2; | |
ulong v8 = (ulong)v4 << 32 | v4; | |
fixed (byte* p = a) { | |
byte* di = p + d; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2022 Hafthor Stefansson | |
// Distributed under the MIT/X11 software license | |
// Ref: http://www.opensource.org/licenses/mit-license.php. | |
static unsafe void UnsafeCopy(byte[] sa, uint s, byte[] da, uint d, uint c) { | |
unchecked { | |
fixed (byte* sp = sa, dp = da) { | |
byte* si = sp + s, di = dp + d; | |
if (c >= 1 && (d & 1) != 0) { // word align | |
*((byte*)di) = *((byte*)si); | |
si++; di++; c--; d++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Jab : Attribute { | |
public T Resolve<T>() where T : class { | |
return (T)Resolve(typeof(T)); | |
} | |
public object Resolve(Type typ) { | |
var typeToInstantiate = (from t in Assembly.GetExecutingAssembly().GetTypes() | |
where t.IsDefined(typeof(Jab), false) && t.IsClass && t.IsPublic && t.GetInterfaces().Contains(typ) | |
select t).Single(); | |
var defaultConstructor = (from c in typeToInstantiate.GetConstructors().ToList() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hafthor; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(final String[] args) { | |
final RubiksCube rc = new RubiksCube(); | |
rc.print(); | |
Scanner scanner = new Scanner(System.in); | |
for (; ; ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hafthor; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.LinkedList; | |
import java.util.List; | |
public class Main { | |
public static void main(final String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hafthor; | |
public class Main { | |
public static void main(final String[] args) { | |
Nonogram n = new Nonogram("1 3 9 122 42 42 122 9 3 1", "33 22 8 121 121 6 22 11 6 4"); // 9 | |
while(n.solve()) n.print(); | |
n.print(); | |
} | |
public static class Nonogram { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hafthor; | |
public class Main { | |
public static void main(final String[] args) { | |
final String input = "" + | |
"89. .5. ..." + | |
"2.. 7.9 ..." + | |
"..4 ..3 ..." + | |
"..9 6.2 ..3" + | |
"... ..1 897" + |
NewerOlder