Browse Source

Added multiple snippets (used by euler-098)

  - fixed_base_pow.b93
  - get_palindromic_hash.b93
  - read_single_word.b93
  - length_single_word.b93
Mike Schwörer 2 years ago
parent
commit
6c8ef216a6
Signed by: Mike Schwörer <mailport@mikescher.de> GPG Key ID: D3C7172E0A70F8CF
4 changed files with 92 additions and 0 deletions
  1. 32
    0
      Fixed_Base_Pow.b93
  2. 26
    0
      get_palindromic_hash.b93
  3. 17
    0
      length_single_word.b93
  4. 17
    0
      read_single_word.b93

+ 32
- 0
Fixed_Base_Pow.b93 View File

@@ -0,0 +1,32 @@
1
+v             v-1\5<  v*\<  
2
+              >:  >|  >\:|
3
+>  7          0\: ^>$:|  >$@
4
+                      >1\^
5
+                     
6
+
7
+
8
+[Stack] -> [Stack]
9
+
10
+
11
+Calculates `n^{Stack}` where `n` is a constant number (`5` in the code above)
12
+
13
+
14
+
15
+
16
+10^n version
17
+============
18
+
19
+v               v\+55<  v*\<  
20
+                >1->:|  >\:|
21
+>  4            0\ ^^>$:|  >$@
22
+                        >1\^
23
+
24
+
25
+
26
+
27
+Version 1.0 (doesn't accepts n^0)
28
+=================================
29
+
30
+v             v-1\5< v*\<  
31
+              >:  >| >\:|
32
+>  7          0\: ^>$^  >$@

+ 26
- 0
get_palindromic_hash.b93 View File

@@ -0,0 +1,26 @@
1
+v
2
+                                 v        !:\<
3
+>  0"YOUTH"                  0\:!vv-1\5< v*\<+ 
4
+                             v   <>:  >| >\:|$
5
+                            v_"A"-0\: ^$>|  >^
6
+                            >$@     >:#<^>1\^
7
+
8
+
9
+[Stack] -> [Stack]
10
+
11
+Input  := zero-terminated string
12
+Output := 64bit number
13
+
14
+Calculate a hash value for the palindromic identity of a string.
15
+We use a base-5 number where every digit denotes the count of a specific lette rin the input
16
+(eg digit-1 = `count of letter A`, digit_2 = `coutn of letter B` ...)
17
+
18
+Base-5 means we only support numbers that have maximally five times the same letter.
19
+Five is the biggest base we can use with 64bit signed numbers (otherwise the number can get too big and overflow):
20
+~~~
21
+x^(26-1) = 2^(64-1)    <=>
22
+x = 2^(63/25)          <=>
23
+x = 5.735
24
+~~~
25
+With 32bit numbers the maximum would be `2`.
26
+

+ 17
- 0
length_single_word.b93 View File

@@ -0,0 +1,17 @@
1
+vX
2
+              ELECTRICITY
3
+
4
+                  v         \+1\<
5
+> 72* 1      10p0\>:1+\10gg84*-#^_$ @
6
+
7
+
8
+
9
+[Stack<X> | Stack<Y>]  ->  [Stack]
10
+
11
+
12
+
13
+
14
+[10] temp
15
+
16
+read a word from the grid (until a space is encountered) and write its length to the stack
17
+X and Y is supplied via stack

+ 17
- 0
read_single_word.b93 View File

@@ -0,0 +1,17 @@
1
+vX
2
+              COMMISSION
3
+
4
+                  v             \<
5
+> 72* 1        10p>:1+\10gg:84*-#^_$$@
6
+
7
+
8
+
9
+[Stack<X> | Stack<Y>]  ->  [Stack]
10
+
11
+
12
+
13
+
14
+[10] temp
15
+
16
+read a word from the grid (until a space is encountered) to the stack
17
+X and Y is supplied via stack

Loading…
Cancel
Save