| Bytes | Lang | Time | Link |
|---|---|---|---|
| 1788 | Python + NumPy and SymPy | 250621T071804Z | Value In |
| 1488 | Ruby | 151113T234317Z | daniero |
| 669 | Japt | 151113T155215Z | ETHprodu |
| 8331 | Java | 151112T221541Z | SuperJed |
| 489 | Pyth | 151113T145436Z | Jakube |
| 621 | Python 3 currently invalid | 151112T190844Z | jan |
| 817 | Pyth | 151113T004557Z | Phyxie |
Python + NumPy and SymPy, 1788
Mostly just wanted to have a valid Python submission up. While many tasks are similar to jan's purely because they're just so basic, the only one I explicitly took was the numpy base 36 answer; the more complicated ones have different approaches, like a recursive function for the square root test to account for the lambda one-liner restriction or regex substitutions for ಠ and Caesar cipher. (And of course an actual answer to the prime factors task.)
# Task 3: 1738 Divisibility -- 17 bytes
lambda i:i%1738<1
# Task 4: q Check -- 16 bytes + 8^1.5 (22)
lambda i:'q'in i
# Task 7: PPCG -- 13 bytes + 8^1.5 (22)
lambda:'PPCG'
# Task 2: ASCII code concatenation -- 39 bytes + 31^1.5 (172)
lambda i:''.join(str(ord(c))for c in i)
# Task 5: Sum of prime factors -- 48 bytes + 30^1.5 (148)
lambda i:sum(primefactors(i));from sympy import*
# Task 1: Base 36 -- 43 bytes + 19^1.5 (76)
lambda i:base_repr(i,36);from numpy import*
# Task 9: ಠ -- 45 bytes + 23^1.5 (96)
lambda i:sub('[oO]',u'ಠ',i);from re import*
# Task 5: Caesar cipher -- 84 bytes + 45^1.5 (301)
lambda i:sub('[a-zA-Z]',lambda c:chr(ord(c[0])+1-26*(c[0]in'Zz')),i);from re import*
# Task 8: Square root divisibility -- 73 bytes + 69^1.5 (573)
h=lambda i,n=1:[]if i<1else([n]+h(i-1,n+1))if n%(n**.5//1)<1else h(i,n+1)
Ruby, 1488
Probably a lot of room for improvement here. Spent most of the time calculating the score...
Sum of prime factors: 64
require'prime';p gets.to_i.prime_division.reduce(0){|s,a|s+a[0]}
Base 36: 30 + 471.5 = 352
puts gets.to_i.to_s(36).upcase
Divisible by 1738: 22 + 151.5 = 80
puts gets.to_i%1738==0
Print PPCG: 9 + 181.5 = 85
puts:PPCG
Does string contain q?: 10 + 81.5 = 32
p gets[?q]
Replace o: 23 + 161.5 = 87
puts gets.gsub(/o/i,?ಠ)
Caesar cipher: 32 + 211.5 = 128
puts gets.tr 'A-Za-z','B-ZAb-za'
ASCII codes: 37 + 261.5 = 169
puts gets.chomp.chars.map(&:ord).join
Integers divisible by square root: 72 + 561.5 = 491
puts *(1..1/0.0).lazy.select{|i|i%Math.sqrt(i).floor==0}.take(gets.to_i)
Japt, 886 866 766 725 688 669
Tasks 5 and 6 are killers. Perhaps there are shorter ways to get them done. I think the Levenshtein distances could still be reduced as well.
- Task 3 (divisiblity):
!(U%#ۊ
7 bytes (arabic char messes up alignment) - Task 4 ('q' check):
U!=Uk'q7 bytes, dist 11 - Task 1 (base conversion):
Us36 u6 bytes, dist 14 - Task 2 (ASCII codes):
UmX=>Xc7 bytes, dist 14 - Task 7 (see for yourself):
"PPCG"6 bytes, dist 18 - Task 9 (ಠ replacement):
Ur"[Oo]",'ಠ13 bytes, dist 27 - Task 8 (floor(sqrt(n))):
X=Uq f;XoU*X+1,X16 bytes, dist 52 - Task 6 (prime factor sum):
2oU fX=>2oX eY=>X%Y &&!(U%X)r(X,Y =>X+Y39 bytes, dist 172 - Task 5 (Caesar cipher):
UmX=>128o mY=>Yd)a k'A i#Z,'A k'a i#z,'a gXc44 bytes, dist 216
Here's a snippet that will tell you (one of) the most efficient ways to arrange your programs:
function L(s,t) {
if(s == t) return 0;
if(s.length === 0) return t.length;
if(t.length === 0) return s.length;
var v0 = Array(t.length+1),
v1 = Array(t.length+1);
for(var i=0; i<v0.length; i++) v0[i]=i;
for(i=0; i<s.length; i++) {
v1[0]=i+1;
for(var j=0; j<t.length; j++)
v1[j+1] = Math.min(v1[j]+1, v0[j+1]+1, v0[j]+(s[i]==t[j]?0:1));
for(j=0; j<v0.length; j++) v0[j]=v1[j];
}
return v1[t.length];
}
function run(x) {
R.innerHTML='';
var b={}, k=0, min=1/0, item='';
for(var i in x) {
for(var j in x.slice(+i+1)) {
k=b[i+(+i+(+j)+1)]=b[(+i+(+j)+1)+i]=L(x[+i],x[+i+(+j)+1]);
if(k<min) min=k, item=i+(+i+(+j)+1);
}
}
var order=item, q=10;
while(order.length < x.length && q--) {
min=1/0, item='';
for(i in b) {
if(b[i]<min) {
if(i[0]==order.slice(-1) && order.indexOf(i[1])==-1)
min = b[i], item = i[1];
}
}
order+=item;
}
var score=0,y=0;
function getByteCount(s){return(new Blob([s],{encoding:"UTF-8",type:"text/plain;charset=UTF-8"})).size}
console.log("Task",(+order[0]+1)+":",y=getByteCount(x[order[0]])),score+=y
for(i in order.slice(1))
console.log(" ",y=Math.pow(b[order[i]+order[+i+1]],1.5)|0),score+=y,
console.log("Task",(+order[+i+1]+1)+":",y=getByteCount(x[order[+i+1]])),score+=y;
console.log("Total:",score)
}
console.log = function(){R.innerHTML+=Array.prototype.slice.call(arguments).join(' ');R.innerHTML+='<br>'};
<p>Input programs here, one per line:</p>
<textarea id=O rows="9" style="width:90%"></textarea><br>
<button onclick="run(O.value.split('\n'))">Run</button>
<p id=R></p>
With the latest version of Japt (non-competing in this challenge), most tasks get shorter:
- Task 1:
s36 u5 bytes - Task 2:
mc2 bytes - Task 3:
v#ۊ
4 bytes - Task 4:
oq2 bytes - Task 5:
;B±B+C²UrF,@Bg1+BbX19 bytes - Task 6:
k â x5 bytes - Task 7:
"PPCG5 bytes - Task 8:
B=U¬f)oU*B+1B13 bytes - Task 9:
ro'ಠ'i6 bytes
The optimal order is now 2,4,3,1,6,7,9,8,5, coming in at a whopping score of 217, less than one-third of the original!
Suggestions welcome!
Java, score 8331
Them levenshtein distances are killing my score here.
(These programs take input as command line arguments)
Program 1 (119):
class L{public static void main(String[]a){System.out.print(Integer.toString(Integer.parseInt(a[0]),36).toUpperCase());}}
Program 2 (120+561.5=539):
class L{public static void main(String[]a){/*System.out.print*/for(char b:a[0].toCharArray())System.out.print((int)b);}}
Program 3 (101+491.5=444):
class L{public static void main(String[]a){System.out.print/*for*/(Integer.parseInt(a[0])%1738==0);}}
Program 4 (108+201.5=197):
class L{public static void main(String[]a){System.out.print(/*forInteger.parseInt(*/a[0].indexOf('q')>=0);}}
Program 5 (186+1071.5=1293):
class L{public static void main(String[]a){for(char b:a[0].toCharArray())System.out.print(Character.isLetter(b)?Character.isUpperCase(b)?b>'Y'?'A':(char)(b+1):b>'y'?'a':(char)(b+1):b);}}
Program 6 (327+2281.5=3747):
class L{public static void main(String[]a){int i,k=0,j=i=Integer.parseInt(a[0]);for(;i>0;i--)if(p(i)&&j%i==0)k+=i;System.out.print(k);}static boolean p(int n){if(n<2)return 0>0;if(n==2||n==3)return 1>0;if(n%2==0||n%3==0)return 0>0;int i,k=(int)Math.sqrt(n)+1;for(i=6;i<=k;i+=6)if(n%(i-1)==0||n%(i+1)==0)return 0>0;return 1>0;}}
Program 7 (336+101.5=368)
class L{public static void main(String[]a){/*int i,k=0,j=i=Integer.parseInt(a[0]);for(;i>0;i--)if(p(i)&&j%i==0)k+=i;*/System.out.print("PPCG");}static boolean p(int n){if(n<2)return 0>0;if(n==2||n==3)return 1>0;if(n%2==0||n%3==0)return 0>0;int i,k=(int)Math.sqrt(n)+1;for(i=6;i<=k;i+=6)if(n%(i-1)==0||n%(i+1)==0)return 0>0;return 1>0;}}
Program 8 (351+341.5=549):
class L{public static void main(String[]a){int i,k=1,j=(int)Math.sqrt(i=Integer.parseInt(a[0]));for(;k<i;k++)/*if(p(i)&&j%i==0)k+=i;*/System.out.println(j*k);}static boolean p(int n){if(n<2)return 0>0;if(n==2||n==3)return 1>0;if(n%2==0||n%3==0)return 0>0;int i,k=(int)Math.sqrt(n)+1;for(i=6;i<=k;i+=6)if(n%(i-1)==0||n%(i+1)==0)return 0>0;return 1>0;}}
Program 9 (305+841.5=1075):
class L{public static void main(String[]a){int i,k=1,j=0;System.out.print(a[0].replaceAll("o|O",""+(char)3232));}static boolean p(int n){if(n<2)return 0>0;if(n==2||n==3)return 1>0;if(n%2==0||n%3==0)return 0>0;int i,k=(int)Math.sqrt(n)+1;for(i=6;i<=k;i+=6)if(n%(i-1)==0||n%(i+1)==0)return 0>0;return 1>0;}}
Pyth, score 489
Base conversion: 15
s@L+s`MTrG1jQ36
Caesar Cipher: 13 + 11^1.5
u.rGHrBG1z 36
Divisible by 1738: 7 + 11^1.5
!%Q1738
First N positive integers: 8 + 8^1.5
*Rs@Q2SQ
Sum of prime factors: 4 + 6^1.5
s{PQ
Appearance of q in string: 4 + 4^1.5
}\qz
Join all ASCII codes: 5 + 4^1.5
jkCMz
Print "PPCG": 5 + 5^1.5
"PPCG
Replace with ಠ: 9 + 7^1.5
Xz"oO"\ಠ
Python 3 (currently invalid), 621 bytes
from numpy import base_repr
import math
print(base_repr(int(input()),36))
print("".join([str(ord(c)) for c in input()]))
if int(input())%1738 == 0:print(True)
else:print(False)
if "q" in input().lower():print(True)
else:print(False)
t=bytes.maketrans(b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",b"bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA")
print(input().encode("utf-8").translate(t).decode("utf-8"))
print("PPCG")
n=int(input())
for i in range(1,n):
if i%math.floor(i**0.5)==0:print(i,end=" ")
print("")
y=input()
z=""
for i in y:
if i.lower()=="o":z+="0"
else:z+=i
print(z)
Not really that good code but somewhat works :D.
The sum of prime factors is not working. I always get a different result from your example so I removed it.
Also Python does not support the char ಠ so instead it replaces the os with 0s
IO INFO:
1st input: int in base 10 | Output: that number in base 36
2nd input: a string | Output: Ascii numbers of the string
3rd input: integer | Output: True or False depending if number is dividible by 1738
4th input: string | Output: T or F depending if the string has "q" in it
5th input: string | Output: Caser Cipher +1 of the string
6th: just prints "PPCG" literally
7th input: int n | Output: first n ints divisible by floor(sqrt(n))
8th input: string | Output: Replaced all os with 0 (not with ಠ because python does not support that character, don't get too mad :) )
Pyth, score 817
number 1: 24
Jjk+UTrG1VjKvz36=+k@JN;k
number 2: (9 + 161.5 = 73)
Vz=+kCN;k
number 3: (5 + 81.5 = 27)
/QC"ۊ
number 4: (5 + 141.5 = 57)
hxz\q
number 5: (39 + 371.5 = 264)
J+GrG1VzIhxJNKChCNIhxJKpK)EpC-CK26))EpN
number 6: (4 + 391.5 = 247)
s{PQ
number 7: (5 + 41.5 = 13)
"PPCG
number 8: (12 + 121.5 = 53)
VK/@Q2 1*KhN
number 9 (13 + 131.5 = 59)
j\ಠcj\ಠcz\o\O
Not the best, I just started learning pyth today and thought I'd give it a try, number 5 really killed my score, I think I can get a few of them shorter but That will just hurt me more on the distances. Any tips from more experienced pyth users are appreciated.